Skip to content

Commit bed66d6

Browse files
committed
fix: flatten tree categories
1 parent c0a5e77 commit bed66d6

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/model/post-cat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export class PostCat {
1010
childCount = 0
1111
visibleChildCount = 0
1212
parent?: PostCat | null
13+
children?: PostCat | null
1314

1415
flattenParents(includeSelf: boolean): PostCat[] {
1516
// eslint-disable-next-line @typescript-eslint/no-this-alias

src/service/post/post-cat.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ export namespace PostCatService {
2828
}
2929
}
3030

31+
export async function getFlatAll() {
32+
const categories = await getAll()
33+
34+
const flat = []
35+
const queue = categories
36+
while (queue.length > 0) {
37+
const current = queue.pop()
38+
flat.push(current)
39+
40+
if (current?.children != null) for (const child of current.children) queue.unshift(child)
41+
}
42+
43+
return flat
44+
}
45+
3146
export async function getOne(categoryId: number) {
3247
const req = await getAuthedPostCatReq()
3348
try {

src/service/post/post-cfg-panel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export namespace PostCfgPanel {
7676
command: Webview.Cmd.Ui.editPostCfg,
7777
post: cloneDeep(post),
7878
activeTheme: vscode.window.activeColorTheme.kind,
79-
userCats: cloneDeep(await PostCatService.getAll()),
79+
userCats: cloneDeep(await PostCatService.getFlatAll()),
8080
siteCats: cloneDeep(await PostCatService.getSitePresetList()),
8181
tags,
8282
breadcrumbs,

0 commit comments

Comments
 (0)