diff --git a/src/sdk.ts b/src/sdk.ts index e3fb197..679ec5d 100644 --- a/src/sdk.ts +++ b/src/sdk.ts @@ -156,7 +156,7 @@ export type EndpointFolder = EndpointFolderPreview & { value: EndpointPagePreview; } )[]; - parentPages: ParentPage[]; + parentPages: EndpointSource[]; }; export type EndpointHomeFolder = EndpointFolderPreview & { @@ -226,13 +226,7 @@ export type EndpointPage = EndpointPagePreview & { proofreaders: EndpointRecorder[]; toc: TableOfContentEntry[]; })[]; - parentPages: ParentPage[]; -}; - -export type ParentPage = { - slug: string; - collection: Collections; - translations: { language: string; name: string }[]; + parentPages: EndpointSource[]; }; export type EndpointCollectiblePreview = { @@ -307,7 +301,7 @@ export type EndpointCollectible = EndpointCollectiblePreview & { }[]; }; }[]; - parentPages: ParentPage[]; + parentPages: EndpointSource[]; }; export type TableOfContentEntry = { @@ -350,7 +344,8 @@ export type EndpointSource = | { type: "timestamp"; timestamp: string } | { type: "custom"; translations: { language: string; note: string }[] }; } - | { type: "page"; page: EndpointPagePreview }; + | { type: "page"; page: EndpointPagePreview } + | { type: "folder"; folder: EndpointFolderPreview }; export type PayloadImage = { url: string; diff --git a/src/utils/endpoints.ts b/src/utils/endpoints.ts index dd7243d..c785821 100644 --- a/src/utils/endpoints.ts +++ b/src/utils/endpoints.ts @@ -1,5 +1,6 @@ -import { Collections } from "../constants"; -import { EndpointRecorder, EndpointTag, EndpointTagsGroup, ParentPage } from "../sdk"; +import { convertCollectibleToPreview } from "../collections/Collectibles/endpoints/getBySlugEndpoint"; +import { convertFolderToPreview } from "../collections/Folders/endpoints/getBySlugEndpoint"; +import { EndpointRecorder, EndpointSource, EndpointTag, EndpointTagsGroup } from "../sdk"; import { Collectible, Folder, Recorder, Tag } from "../types/collections"; import { isPayloadArrayType, isPayloadType, isPublished, isValidPayloadImage } from "./asserts"; @@ -49,32 +50,23 @@ export const handleParentPages = ({ }: { collectibles?: (string | Collectible)[] | null | undefined; folders?: (string | Folder)[] | null | undefined; -}): ParentPage[] => { - const result: ParentPage[] = []; +}): EndpointSource[] => { + const result: EndpointSource[] = []; if (collectibles && isPayloadArrayType(collectibles)) { - collectibles.filter(isPublished).forEach(({ slug, translations }) => { + collectibles.filter(isPublished).forEach((collectible) => { result.push({ - collection: Collections.Collectibles, - slug, - translations: translations.map(({ language, title }) => ({ - language: isPayloadType(language) ? language.id : language, - name: title, // TODO: Use the entire pretitle + title + subtitle - })), + type: "collectible", + collectible: convertCollectibleToPreview(collectible), }); }); } if (folders && isPayloadArrayType(folders)) { - folders.forEach(({ slug, translations }) => { + folders.forEach((folder) => { result.push({ - collection: Collections.Folders, - slug, - translations: - translations?.map(({ language, name }) => ({ - language: isPayloadType(language) ? language.id : language, - name, - })) ?? [], + type: "folder", + folder: convertFolderToPreview(folder), }); }); }