@@ -30,7 +30,7 @@ const questionsAdapter = createEntityAdapter<
3030} )
3131
3232export const fetchAllQuestions = createAsyncThunk <
33- ProblemsetQuestion [ ] | null ,
33+ Map < CategorySlugType , ProblemsetQuestion [ ] > | null ,
3434 undefined ,
3535 { state : RootState }
3636> ( 'questions/fetchAllQuestions' , async ( _ , { getState, dispatch } ) => {
@@ -53,7 +53,7 @@ export const fetchAllQuestions = createAsyncThunk<
5353 }
5454 }
5555
56- return api . getProblemsetQuestionListAll ( { } , total )
56+ return api . getAllQuestion ( )
5757} )
5858
5959export const fetchLastACQuestions = createAsyncThunk <
@@ -70,10 +70,15 @@ export const fetchAllQuestionIds = createAsyncThunk<
7070 { state : RootState }
7171> ( 'questions/fetchAllQuestionIds' , async ( ) => api . getAllQuestions ( ) )
7272
73- const initialState = questionsAdapter . getInitialState ( {
73+ const initData = {
7474 total : 0 ,
7575 update : 0 ,
76- } )
76+ } as {
77+ total : number
78+ update : number
79+ } & { [ key in CategorySlugType ] : string [ ] }
80+
81+ const initialState = questionsAdapter . getInitialState ( initData )
7782
7883const questionsSlice = createSlice ( {
7984 name : 'posts' ,
@@ -82,10 +87,16 @@ const questionsSlice = createSlice({
8287 extraReducers ( builder ) {
8388 builder
8489 . addCase ( fetchAllQuestions . fulfilled , ( state , action ) => {
85- if ( action . payload ) {
86- questionsAdapter . upsertMany ( state , action . payload )
87- state . total = action . payload . length
90+ const map = action . payload
91+ if ( map ) {
92+ const allQuestions = map . get ( 'all-code-essentials' ) !
93+ questionsAdapter . upsertMany ( state , allQuestions )
94+ state . total = allQuestions . length
8895 state . update = new Date ( ) . valueOf ( )
96+ for ( const [ category , questions ] of map ) {
97+ if ( category === 'all-code-essentials' ) continue
98+ state [ category ] = questions . map ( q => q . frontendQuestionId )
99+ }
89100 }
90101 } )
91102 . addCase ( fetchAllQuestionIds . fulfilled , ( state , action ) => {
@@ -154,26 +165,12 @@ export const selectQuestonsByOption = (
154165 . filter ( Boolean ) as EntityId [ ] ) ?? [ ]
155166 }
156167
157- if ( option . categorySlug ) {
158- const categorySlugs = new Set ( [ 'database' , 'shell' , 'concurrency' ] )
168+ if ( option . categorySlug && option . categorySlug !== 'all-code-essentials' ) {
169+ const set = new Set ( questions [ option . categorySlug ] )
159170 for ( const id of ids ) {
160171 const question = questions . entities [ id ]
161- if ( ! question ) continue
162- if ( option . categorySlug === 'algorithms' ) {
163- // 力扣没有将 「剑指」和「面试题」 的题目归为 algorithms 这个分类,
164- // 为了保持跟力扣的一致,如果分类是 algorithms 也过滤掉这些题目
165- if (
166- ! question . frontendQuestionId . startsWith ( '剑指' ) &&
167- ! question . frontendQuestionId . startsWith ( '面试题' ) &&
168- question . topicTags . every ( a => ! categorySlugs . has ( a . slug ) )
169- ) {
170- res . push ( question )
171- }
172- } else {
173- if ( question . topicTags . some ( a => a . slug === option . categorySlug ) ) {
174- res . push ( question )
175- }
176- }
172+ if ( ! question || ! set . has ( question . frontendQuestionId ) ) continue
173+ res . push ( question )
177174 }
178175 } else {
179176 res = ids . map ( id => questions . entities [ id ] ! )
0 commit comments