diff --git a/src/model/post-cat.ts b/src/model/post-cat.ts index 853667a6..dd4ae1b4 100644 --- a/src/model/post-cat.ts +++ b/src/model/post-cat.ts @@ -10,6 +10,7 @@ export class PostCat { childCount = 0 visibleChildCount = 0 parent?: PostCat | null + children?: PostCat | null flattenParents(includeSelf: boolean): PostCat[] { // eslint-disable-next-line @typescript-eslint/no-this-alias diff --git a/src/service/post/post-cat.ts b/src/service/post/post-cat.ts index 6c1b1918..0fb32245 100644 --- a/src/service/post/post-cat.ts +++ b/src/service/post/post-cat.ts @@ -28,6 +28,21 @@ export namespace PostCatService { } } + export async function getFlatAll() { + const categories = await getAll() + + const flat = [] + const queue = categories + while (queue.length > 0) { + const current = queue.pop() + flat.push(current) + + if (current?.children != null) for (const child of current.children) queue.unshift(child) + } + + return flat + } + export async function getOne(categoryId: number) { const req = await getAuthedPostCatReq() try { diff --git a/src/service/post/post-cfg-panel.ts b/src/service/post/post-cfg-panel.ts index a2b0f38e..20329463 100644 --- a/src/service/post/post-cfg-panel.ts +++ b/src/service/post/post-cfg-panel.ts @@ -76,7 +76,7 @@ export namespace PostCfgPanel { command: Webview.Cmd.Ui.editPostCfg, post: cloneDeep(post), activeTheme: vscode.window.activeColorTheme.kind, - userCats: cloneDeep(await PostCatService.getAll()), + userCats: cloneDeep(await PostCatService.getFlatAll()), siteCats: cloneDeep(await PostCatService.getSitePresetList()), tags, breadcrumbs,