File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ export class PostCat {
10
10
childCount = 0
11
11
visibleChildCount = 0
12
12
parent ?: PostCat | null
13
- children ?: PostCat | null
13
+ children ?: PostCat [ ] | null
14
14
15
15
flattenParents ( includeSelf : boolean ) : PostCat [ ] {
16
16
// eslint-disable-next-line @typescript-eslint/no-this-alias
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ import { UserService } from '../user.service'
8
8
// TODO: need better cache impl
9
9
let siteCategoryCache : SiteCat [ ] | null = null
10
10
11
+ const DEFAULT_ORDER = 999999
12
+
11
13
async function getAuthedPostCatReq ( ) {
12
14
const token = await AuthManager . acquireToken ( )
13
15
// TODO: need better solution
@@ -31,17 +33,24 @@ export namespace PostCatService {
31
33
32
34
export async function getFlatAll ( ) {
33
35
const categories = await getAll ( )
36
+ if ( categories == null || categories . length === 0 ) return [ ]
34
37
35
38
const flat = [ ]
36
39
const queue = categories
37
40
while ( queue . length > 0 ) {
38
41
const current = queue . pop ( )
42
+ if ( current == null ) continue
39
43
flat . push ( current )
40
-
41
- if ( current ?. children != null ) for ( const child of current . children ) queue . unshift ( child )
44
+ if ( current . children != null ) for ( const child of current . children ) queue . unshift ( child )
42
45
}
43
46
44
- return flat
47
+ return flat . sort ( ( x , y ) => {
48
+ const order1 = x . order ?? DEFAULT_ORDER
49
+ const order2 = y . order ?? DEFAULT_ORDER
50
+ if ( order1 > order2 ) return 1
51
+ else if ( order1 < order2 ) return - 1
52
+ else return x . title . localeCompare ( y . title )
53
+ } )
45
54
}
46
55
47
56
export async function getOne ( categoryId : number ) {
You can’t perform that action at this time.
0 commit comments