-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #447 from EasyBrizy/443-blocksAPI
443 blocks api
- Loading branch information
Showing
5 changed files
with
168 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
packages/demo-nextjs/src/components/Editor/contexts/converters.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { pipe } from "@brizy/readers"; | ||
import { APIPopup, BlockWithThumbs, Categories, Kit, KitType } from "@builder/core/build/es/types/templates"; | ||
import { flatten, uniq, upperFirst } from "lodash"; | ||
|
||
type CatTypes = Kit | APIPopup; | ||
const PRO = "PRO"; | ||
|
||
export const getUniqueKitCategories = (collections: CatTypes[]): Categories[] => | ||
pipe( | ||
(collections: CatTypes[]) => collections.map((collection: CatTypes) => collection.categories), | ||
(categories) => categories.map((category) => category.split(",")), | ||
flatten, | ||
(categories2) => categories2.map((category2) => category2.trim()), | ||
uniq, | ||
(allCats) => allCats.filter((cat) => cat && cat.length), | ||
(cats) => | ||
cats.map((cat) => ({ | ||
title: upperFirst(cat), | ||
slug: cat, | ||
id: cat, | ||
})), | ||
)(collections); | ||
|
||
export const getUniqueKitTypes = (collections: Kit[]): KitType[] => | ||
pipe( | ||
(collections: Kit[]) => collections.map((collection) => collection.theme), | ||
(types) => types.map((type) => type.split(",")), | ||
flatten, | ||
(types2) => types2.map((type2) => type2.toLowerCase()), | ||
uniq, | ||
(allTypes) => allTypes.filter((type) => type && type.length), | ||
(uni) => | ||
uni.map((u) => ({ | ||
title: upperFirst(u), | ||
id: u, | ||
name: u, | ||
icon: u === "light" ? "nc-light" : "nc-dark", | ||
})), | ||
)(collections); | ||
|
||
export const convertToCategories = (obj: { slug: string; title: string }[]): Categories[] => | ||
obj.map((item) => ({ | ||
...item, | ||
id: item.title.toLowerCase(), | ||
})); | ||
|
||
export const converterKit = ( | ||
kit: Kit[], | ||
url: string, | ||
kitId: string, | ||
): { | ||
blocks: BlockWithThumbs[]; | ||
categories: Categories[]; | ||
types: KitType[]; | ||
} => { | ||
const categories = getUniqueKitCategories(kit); | ||
const types = getUniqueKitTypes(kit); | ||
|
||
const blocks: BlockWithThumbs[] = kit.map( | ||
({ slug, categories, pro, thumbnail, keywords, thumbnailWidth, thumbnailHeight, blank, theme }) => ({ | ||
id: slug, | ||
cat: categories.split(",").map((item) => item.trim().toLowerCase()), | ||
title: slug, | ||
type: theme | ||
.split(",") | ||
.map((item) => item.trim()) | ||
.map((i1) => i1.toLowerCase()), | ||
keywords: keywords ?? "", | ||
thumbnailHeight, | ||
thumbnailWidth, | ||
thumbnailSrc: `${url}${thumbnail}`, | ||
pro: pro === PRO, | ||
kitId, | ||
blank, | ||
}), | ||
); | ||
|
||
return { | ||
blocks, | ||
categories, | ||
types, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters