diff --git a/src/app/dashboard/[subdomain]/editor/page.tsx b/src/app/dashboard/[subdomain]/editor/page.tsx index d1501602..45a2b91a 100644 --- a/src/app/dashboard/[subdomain]/editor/page.tsx +++ b/src/app/dashboard/[subdomain]/editor/page.tsx @@ -58,8 +58,8 @@ import { Rendered, renderPageContent } from "~/markdown" import { checkPageSlug } from "~/models/page.model" import { useCreateOrUpdatePage, + useGetDistinctNoteTagsOfCharacter, useGetPage, - useGetPagesBySiteLite, } from "~/queries/page" import { useGetSite } from "~/queries/site" @@ -119,29 +119,7 @@ export default function SubdomainEditor() { handle: subdomain, }) - const { data: posts = { pages: [] } } = useGetPagesBySiteLite({ - characterId: site.data?.characterId, - limit: 100, - type: "post", - visibility: PageVisibilityEnum.Published, - }) - - const userTags = useMemo(() => { - const result = new Set() - - if (posts?.pages?.length) { - for (const page of posts.pages) { - for (const post of page.list) { - post.metadata?.content?.tags?.forEach((tag) => { - if (tag !== "post" && tag !== "page") { - result.add(tag) - } - }) - } - } - } - return Array.from(result) - }, [posts.pages]) + const userTags = useGetDistinctNoteTagsOfCharacter(site.data?.characterId) const [visibility, setVisibility] = useState() @@ -476,7 +454,7 @@ export default function SubdomainEditor() { updateValue={updateValue} isPost={isPost} subdomain={subdomain} - userTags={userTags} + userTags={userTags.data?.list || []} openAdvancedOptions={() => setIsAdvancedOptionsOpen(true)} /> ) @@ -655,7 +633,7 @@ export default function SubdomainEditor() { defaultSlug={defaultSlug} updateValue={updateValue} isPost={isPost} - userTags={userTags} + userTags={userTags.data?.list || []} subdomain={subdomain} openAdvancedOptions={() => setIsAdvancedOptionsOpen(true)} /> diff --git a/src/models/page.model.ts b/src/models/page.model.ts index 9ecfaa12..79a98421 100644 --- a/src/models/page.model.ts +++ b/src/models/page.model.ts @@ -812,3 +812,14 @@ export async function checkMirror(characterId: number) { return notes.count === 0 } + +export const getDistinctNoteTagsOfCharacter = async (characterId: number) => { + const result = await indexer.note.getDistinctTagsOfCharacter(characterId, { + sources: "xlog", + }) + result.list = result.list.filter( + (tag) => ["post", "comment", "page"].findIndex((t) => t === tag) === -1, + ) + + return result +} diff --git a/src/queries/page.ts b/src/queries/page.ts index 4da9487a..1bd42856 100644 --- a/src/queries/page.ts +++ b/src/queries/page.ts @@ -475,3 +475,14 @@ export const useReportStats = ( }, ) } + +export const useGetDistinctNoteTagsOfCharacter = (characterId?: number) => { + return useQuery(["getDistinctNoteTagsOfCharacter", characterId], async () => { + if (!characterId) { + return { + list: [], + } + } + return pageModel.getDistinctNoteTagsOfCharacter(characterId) + }) +}