Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/model/post-cat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/service/post/post-cat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@
}
}

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)

Check warning on line 40 in src/service/post/post-cat.ts

View workflow job for this annotation

GitHub Actions / node-lint

Unsafe argument of type `any` assigned to a parameter of type `PostCat`

Check warning on line 40 in src/service/post/post-cat.ts

View workflow job for this annotation

GitHub Actions / node-lint

Unsafe argument of type `any` assigned to a parameter of type `PostCat`

Check warning on line 40 in src/service/post/post-cat.ts

View workflow job for this annotation

GitHub Actions / node-lint

Unsafe argument of type `any` assigned to a parameter of type `PostCat`
}

return flat
}

export async function getOne(categoryId: number) {
const req = await getAuthedPostCatReq()
try {
Expand Down
2 changes: 1 addition & 1 deletion src/service/post/post-cfg-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading