diff --git a/brizy.php b/brizy.php index 5a81fe4455..4854a9b244 100755 --- a/brizy.php +++ b/brizy.php @@ -17,7 +17,7 @@ $_SERVER['HTTPS'] = 'on'; } -define('BRIZY_DEVELOPMENT', false ); +define('BRIZY_DEVELOPMENT', true ); define('BRIZY_LOG', false ); define('BRIZY_VERSION', '2.4.41'); define('BRIZY_MINIMUM_PRO_VERSION', '2.4.15'); diff --git a/public/editor-client/src/config.ts b/public/editor-client/src/config.ts index 3b6bc23f9d..0a8f8f12f1 100644 --- a/public/editor-client/src/config.ts +++ b/public/editor-client/src/config.ts @@ -12,6 +12,7 @@ interface DefaultTemplates { popupsUrl: string; storiesUrl: string; layoutsUrl: string; + pagesUrl: string; } interface Actions { @@ -99,6 +100,10 @@ const templatesReader = parseStrict, DefaultTemplates>({ mPipe(Obj.readKey("storiesUrl"), Str.read), throwOnNullish("Invalid API Config: stories") ) + // pagesUrl: pipe( + // mPipe(Obj.readKey("pagesUrl"), Str.read), + // throwOnNullish("Invalid API Config: stories") + // ) }); const collectionTypesReader = (arr: Array): Array => { diff --git a/public/editor-client/src/defaultTemplates/index.ts b/public/editor-client/src/defaultTemplates/index.ts index 5090642a89..a131786470 100644 --- a/public/editor-client/src/defaultTemplates/index.ts +++ b/public/editor-client/src/defaultTemplates/index.ts @@ -11,13 +11,22 @@ import { KitsWithThumbs, Layouts, LayoutsWithThumbs, + Pages, + PagesAPI, + PagesDefaultTemplate, Popups, PopupsWithThumbs, Stories, StoriesWithThumbs } from "../types/DefaultTemplate"; import { t } from "../utils/i18n"; +import { read } from "../utils/reader/json"; import { tempConverterKit } from "./tempComverters"; +import { + convertPages, + fetchAllLayouts, + getUniqueLayoutsCategories +} from "./utils"; const defaultKits = ( config: Config @@ -288,4 +297,52 @@ const defaultLayouts = ( }; }; -export { defaultKits, defaultStories, defaultLayouts, defaultPopups }; +const defaultPages = ( + config: Config +): PagesDefaultTemplate> => { + // @ts-expect-error: temporary solution, wait until new API will come via config + const { layoutsUrl } = config.api.templates; + const imageUrl = "https://cloud-1de12d.b-cdn.net/media/iW=1024&iH=1024/"; + const apiPagesUrl = "https://j6dfq8pl41.b-cdn.net/api"; + + return { + async getMeta(res, rej) { + try { + const meta = await fetchAllLayouts( + `${apiPagesUrl}/get-pages`, + 50 + ); + + res({ + blocks: convertPages(meta, imageUrl), + categories: getUniqueLayoutsCategories(meta) + }); + } catch (e) { + rej(t("Failed to load meta.json")); + } + }, + async getData(res, rej, { slug }) { + try { + const data = await fetch( + `${apiPagesUrl}/get-page-data?page_slug=${slug}` + ).then((r) => r.json()); + + const pageData = read(data[0].pageData) as { items: DefaultBlock[] }; + + res({ + blocks: [...pageData.items] + }); + } catch (e) { + rej(t("Failed to load resolves for selected DefaultTemplate")); + } + } + }; +}; + +export { + defaultKits, + defaultStories, + defaultLayouts, + defaultPopups, + defaultPages +}; diff --git a/public/editor-client/src/defaultTemplates/utils.ts b/public/editor-client/src/defaultTemplates/utils.ts index 2cfe123df0..77276f4f52 100644 --- a/public/editor-client/src/defaultTemplates/utils.ts +++ b/public/editor-client/src/defaultTemplates/utils.ts @@ -1,10 +1,13 @@ -import { flatten, uniq, upperFirst } from "lodash"; +import { flatten, trim, uniq, upperFirst } from "lodash"; import { APIPopup, BlockWithThumbs, Categories, Kit, KitType, + LayoutsAPI, + PagesAPI, + PagesTemplate, Style } from "../types/DefaultTemplate"; import { pipe } from "../utils/fp/pipe"; @@ -25,6 +28,26 @@ export const getUniqueKitCategories = (collections: CatTypes[]): Categories[] => })) )(collections); +export const getUniqueLayoutsCategories = ( + collections: LayoutsAPI[] | PagesAPI[] +): Categories[] => + pipe( + (collections: LayoutsAPI[] | PagesAPI[]) => + collections.map( + (collection: LayoutsAPI | PagesAPI) => collection.categories + ), + (cats: string[]) => cats.map((it) => it.split(",")), + flatten, + (cats: string[]) => cats.map(trim), + uniq, + (cats) => + cats.map((cat) => ({ + title: cat, + slug: cat, + id: cat + })) + )(collections); + export const getUniqueKitTypes = (collections: Kit[]): KitType[] => pipe( (collections: Kit[]) => collections.map((collection) => collection.theme), @@ -121,6 +144,30 @@ export const converterPopup = ( }; }; +export const convertPages = ( + collections: PagesAPI[], + thumbUrl: string +): PagesTemplate[] => + collections.map( + ({ + title, + categories, + thumbnailWidth, + thumbnailHeight, + thumbnail, + slug + }) => { + return { + title: title, + slug: slug, + cat: categories.split(",").map(trim), + thumbnailWidth, + thumbnailHeight, + thumbnailSrc: `${thumbUrl}${thumbnail}` + }; + } + ); + export const getStyles = (): Array