@@ -5,20 +5,19 @@ import * as _ from "lodash";
55import { Disposable } from "vscode" ;
66import * as list from "../commands/list" ;
77import { getSortingStrategy } from "../commands/plugin" ;
8- import { Category , defaultProblem , ProblemState , SortingStrategy } from "../shared" ;
9- import { shouldHideSolvedProblem } from "../utils/settingUtils" ;
8+ import { Category , defaultProblem , SortingStrategy } from "../shared" ;
9+ import { shouldHideProblem } from "../utils/settingUtils" ;
1010import { LeetCodeNode } from "./LeetCodeNode" ;
1111
1212class ExplorerNodeManager implements Disposable {
1313 private explorerNodeMap : Map < string , LeetCodeNode > = new Map < string , LeetCodeNode > ( ) ;
1414 private companySet : Set < string > = new Set < string > ( ) ;
1515 private tagSet : Set < string > = new Set < string > ( ) ;
16-
1716 public async refreshCache ( ) : Promise < void > {
1817 this . dispose ( ) ;
19- const shouldHideSolved : boolean = shouldHideSolvedProblem ( ) ;
18+ const shouldHide : Set < number > = shouldHideProblem ( ) ;
2019 for ( const problem of await list . listProblems ( ) ) {
21- if ( shouldHideSolved && problem . state === ProblemState . AC ) {
20+ if ( shouldHide . has ( problem . state ) ) {
2221 continue ;
2322 }
2423 this . explorerNodeMap . set ( problem . id , new LeetCodeNode ( problem ) ) ;
@@ -33,50 +32,72 @@ class ExplorerNodeManager implements Disposable {
3332
3433 public getRootNodes ( ) : LeetCodeNode [ ] {
3534 return [
36- new LeetCodeNode ( Object . assign ( { } , defaultProblem , {
37- id : Category . All ,
38- name : Category . All ,
39- } ) , false ) ,
40- new LeetCodeNode ( Object . assign ( { } , defaultProblem , {
41- id : Category . Difficulty ,
42- name : Category . Difficulty ,
43- } ) , false ) ,
44- new LeetCodeNode ( Object . assign ( { } , defaultProblem , {
45- id : Category . Tag ,
46- name : Category . Tag ,
47- } ) , false ) ,
48- new LeetCodeNode ( Object . assign ( { } , defaultProblem , {
49- id : Category . Company ,
50- name : Category . Company ,
51- } ) , false ) ,
52- new LeetCodeNode ( Object . assign ( { } , defaultProblem , {
53- id : Category . Favorite ,
54- name : Category . Favorite ,
55- } ) , false ) ,
35+ new LeetCodeNode (
36+ Object . assign ( { } , defaultProblem , {
37+ id : Category . All ,
38+ name : Category . All ,
39+ } ) ,
40+ false
41+ ) ,
42+ new LeetCodeNode (
43+ Object . assign ( { } , defaultProblem , {
44+ id : Category . Difficulty ,
45+ name : Category . Difficulty ,
46+ } ) ,
47+ false
48+ ) ,
49+ new LeetCodeNode (
50+ Object . assign ( { } , defaultProblem , {
51+ id : Category . Tag ,
52+ name : Category . Tag ,
53+ } ) ,
54+ false
55+ ) ,
56+ new LeetCodeNode (
57+ Object . assign ( { } , defaultProblem , {
58+ id : Category . Company ,
59+ name : Category . Company ,
60+ } ) ,
61+ false
62+ ) ,
63+ new LeetCodeNode (
64+ Object . assign ( { } , defaultProblem , {
65+ id : Category . Favorite ,
66+ name : Category . Favorite ,
67+ } ) ,
68+ false
69+ ) ,
5670 ] ;
5771 }
5872
5973 public getAllNodes ( ) : LeetCodeNode [ ] {
60- return this . applySortingStrategy (
61- Array . from ( this . explorerNodeMap . values ( ) ) ,
62- ) ;
74+ return this . applySortingStrategy ( Array . from ( this . explorerNodeMap . values ( ) ) ) ;
6375 }
6476
6577 public getAllDifficultyNodes ( ) : LeetCodeNode [ ] {
6678 const res : LeetCodeNode [ ] = [ ] ;
6779 res . push (
68- new LeetCodeNode ( Object . assign ( { } , defaultProblem , {
69- id : `${ Category . Difficulty } .Easy` ,
70- name : "Easy" ,
71- } ) , false ) ,
72- new LeetCodeNode ( Object . assign ( { } , defaultProblem , {
73- id : `${ Category . Difficulty } .Medium` ,
74- name : "Medium" ,
75- } ) , false ) ,
76- new LeetCodeNode ( Object . assign ( { } , defaultProblem , {
77- id : `${ Category . Difficulty } .Hard` ,
78- name : "Hard" ,
79- } ) , false ) ,
80+ new LeetCodeNode (
81+ Object . assign ( { } , defaultProblem , {
82+ id : `${ Category . Difficulty } .Easy` ,
83+ name : "Easy" ,
84+ } ) ,
85+ false
86+ ) ,
87+ new LeetCodeNode (
88+ Object . assign ( { } , defaultProblem , {
89+ id : `${ Category . Difficulty } .Medium` ,
90+ name : "Medium" ,
91+ } ) ,
92+ false
93+ ) ,
94+ new LeetCodeNode (
95+ Object . assign ( { } , defaultProblem , {
96+ id : `${ Category . Difficulty } .Hard` ,
97+ name : "Hard" ,
98+ } ) ,
99+ false
100+ )
80101 ) ;
81102 this . sortSubCategoryNodes ( res , Category . Difficulty ) ;
82103 return res ;
@@ -85,10 +106,15 @@ class ExplorerNodeManager implements Disposable {
85106 public getAllCompanyNodes ( ) : LeetCodeNode [ ] {
86107 const res : LeetCodeNode [ ] = [ ] ;
87108 for ( const company of this . companySet . values ( ) ) {
88- res . push ( new LeetCodeNode ( Object . assign ( { } , defaultProblem , {
89- id : `${ Category . Company } .${ company } ` ,
90- name : _ . startCase ( company ) ,
91- } ) , false ) ) ;
109+ res . push (
110+ new LeetCodeNode (
111+ Object . assign ( { } , defaultProblem , {
112+ id : `${ Category . Company } .${ company } ` ,
113+ name : _ . startCase ( company ) ,
114+ } ) ,
115+ false
116+ )
117+ ) ;
92118 }
93119 this . sortSubCategoryNodes ( res , Category . Company ) ;
94120 return res ;
@@ -97,10 +123,15 @@ class ExplorerNodeManager implements Disposable {
97123 public getAllTagNodes ( ) : LeetCodeNode [ ] {
98124 const res : LeetCodeNode [ ] = [ ] ;
99125 for ( const tag of this . tagSet . values ( ) ) {
100- res . push ( new LeetCodeNode ( Object . assign ( { } , defaultProblem , {
101- id : `${ Category . Tag } .${ tag } ` ,
102- name : _ . startCase ( tag ) ,
103- } ) , false ) ) ;
126+ res . push (
127+ new LeetCodeNode (
128+ Object . assign ( { } , defaultProblem , {
129+ id : `${ Category . Tag } .${ tag } ` ,
130+ name : _ . startCase ( tag ) ,
131+ } ) ,
132+ false
133+ )
134+ ) ;
104135 }
105136 this . sortSubCategoryNodes ( res , Category . Tag ) ;
106137 return res ;
@@ -193,9 +224,12 @@ class ExplorerNodeManager implements Disposable {
193224 private applySortingStrategy ( nodes : LeetCodeNode [ ] ) : LeetCodeNode [ ] {
194225 const strategy : SortingStrategy = getSortingStrategy ( ) ;
195226 switch ( strategy ) {
196- case SortingStrategy . AcceptanceRateAsc : return nodes . sort ( ( x : LeetCodeNode , y : LeetCodeNode ) => Number ( x . acceptanceRate ) - Number ( y . acceptanceRate ) ) ;
197- case SortingStrategy . AcceptanceRateDesc : return nodes . sort ( ( x : LeetCodeNode , y : LeetCodeNode ) => Number ( y . acceptanceRate ) - Number ( x . acceptanceRate ) ) ;
198- default : return nodes ;
227+ case SortingStrategy . AcceptanceRateAsc :
228+ return nodes . sort ( ( x : LeetCodeNode , y : LeetCodeNode ) => Number ( x . acceptanceRate ) - Number ( y . acceptanceRate ) ) ;
229+ case SortingStrategy . AcceptanceRateDesc :
230+ return nodes . sort ( ( x : LeetCodeNode , y : LeetCodeNode ) => Number ( y . acceptanceRate ) - Number ( x . acceptanceRate ) ) ;
231+ default :
232+ return nodes ;
199233 }
200234 }
201235}
0 commit comments