-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WP stories #1973
WP stories #1973
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
import { Arr, Obj, Str } from "@brizy/readers"; | ||
import { Config, getConfig } from "@/config"; | ||
import { | ||
DefaultBlock, | ||
DefaultBlockWithID, | ||
LayoutsAPI, | ||
LayoutsPageAPI, | ||
StoriesAPI, | ||
StoryPages, | ||
Style | ||
} from "@/types/DefaultTemplate"; | ||
import { ConfigDCItem } from "@/types/DynamicContent"; | ||
import { GlobalBlock } from "@/types/GlobalBlocks"; | ||
import { Page } from "@/types/Page"; | ||
import { Rule } from "@/types/PopupConditions"; | ||
import { Project } from "@/types/Project"; | ||
import { ResponseWithBody } from "@/types/Response"; | ||
import { ConfigDCItem } from "@/types/DynamicContent"; | ||
import { | ||
CreateSavedBlock, | ||
CreateSavedLayout, | ||
|
@@ -15,8 +23,9 @@ import { | |
SavedLayoutMeta | ||
} from "@/types/SavedBlocks"; | ||
import { ScreenshotData } from "@/types/Screenshots"; | ||
import { Dictionary } from "../types/utils"; | ||
import { t } from "@/utils/i18n"; | ||
import { Arr, Json, Obj, Str } from "@brizy/readers"; | ||
import { Dictionary } from "../types/utils"; | ||
import { Literal } from "../utils/types"; | ||
import { | ||
GetCollections, | ||
|
@@ -1262,3 +1271,100 @@ export const updateGlobalBlocks = async ( | |
}; | ||
|
||
//#endregion | ||
|
||
//#region Default Templates | ||
export const getDefaultLayouts = async ( | ||
url: string | ||
): Promise<{ | ||
templates: LayoutsAPI[]; | ||
categories: { slug: string; title: string }[]; | ||
}> => { | ||
const res = await fetch(`${url}/get-layouts-chunk`).then((r) => r.json()); | ||
|
||
return { templates: res.collections, categories: res.categories }; | ||
}; | ||
|
||
export const getDefaultLayoutsPages = async ( | ||
url: string, | ||
id: string | ||
): Promise<{ | ||
collections: LayoutsPageAPI[]; | ||
paginationInfo: { | ||
itemsPerPage: number; | ||
lastPage: number; | ||
totalCount: number; | ||
}; | ||
styles: Style; | ||
}> => { | ||
const data = await fetch( | ||
`${url}/get-layouts-pages?project_id=${id}&per_page=20` | ||
).then((r) => r.json()); | ||
|
||
return data; | ||
}; | ||
|
||
export const getDefaultLayoutData = async ( | ||
url: string, | ||
layoutId: Literal, | ||
id: string | ||
): Promise<{ | ||
items: DefaultBlockWithID[]; | ||
}> => { | ||
const data = await fetch( | ||
`${url}/get-layouts-page?project_id=${layoutId}&page_slug=${id}` | ||
).then((r) => r.json()); | ||
|
||
return Json.read(data[0].pageData) as { | ||
items: DefaultBlockWithID[]; | ||
}; | ||
}; | ||
|
||
export const getDefaultStories = async ( | ||
url: string | ||
): Promise<{ | ||
templates: StoriesAPI[]; | ||
categories: { slug: string; title: string }[]; | ||
}> => { | ||
const res = await fetch(`${url}/get-story-chunk`).then((r) => r.json()); | ||
|
||
return { | ||
templates: res.collections, | ||
categories: res.categories | ||
}; | ||
}; | ||
|
||
export const getDefaultStory = async ( | ||
url: string, | ||
layoutId: Literal, | ||
id: string | ||
): Promise<{ | ||
blocks: DefaultBlock[]; | ||
}> => { | ||
const data = await fetch( | ||
`${url}/get-story-page-data?project_id=${layoutId}&page_slug=${id}` | ||
).then((r) => r.json()); | ||
|
||
const pageData = JSON.parse(data.collection); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
|
||
return pageData as { | ||
blocks: DefaultBlock[]; | ||
}; | ||
Comment on lines
+1349
to
+1351
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove casting if without casting is not possible then validate it, as example if pageData will be undefined/null then return empty array |
||
}; | ||
|
||
export const getDefaultStoryPages = async ( | ||
url: string, | ||
id: string | ||
): Promise<{ | ||
collections: StoryPages[]; | ||
paginationInfo: { | ||
itemsPerPage: number; | ||
lastPage: number; | ||
totalCount: number; | ||
}; | ||
styles: Style; | ||
}> => { | ||
return await fetch(`${url}/get-story-page?project_id=${id}&per_page=20`).then( | ||
(r) => r.json() | ||
); | ||
}; | ||
//#endregion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove casting, because of casting we don't handle some errors
as example here
Json.read
can return undefinedbut you cast is as object with items inside