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 {
1010 childCount = 0
1111 visibleChildCount = 0
1212 parent ?: PostCat | null
13- children ?: PostCat | null
13+ children ?: PostCat [ ] | null
1414
1515 flattenParents ( includeSelf : boolean ) : PostCat [ ] {
1616 // 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'
88// TODO: need better cache impl
99let siteCategoryCache : SiteCat [ ] | null = null
1010
11+ const DEFAULT_ORDER = 999999
12+
1113async function getAuthedPostCatReq ( ) {
1214 const token = await AuthManager . acquireToken ( )
1315 // TODO: need better solution
@@ -31,17 +33,24 @@ export namespace PostCatService {
3133
3234 export async function getFlatAll ( ) {
3335 const categories = await getAll ( )
36+ if ( categories == null || categories . length === 0 ) return [ ]
3437
3538 const flat = [ ]
3639 const queue = categories
3740 while ( queue . length > 0 ) {
3841 const current = queue . pop ( )
42+ if ( current == null ) continue
3943 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 )
4245 }
4346
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+ } )
4554 }
4655
4756 export async function getOne ( categoryId : number ) {
You can’t perform that action at this time.
0 commit comments