@@ -48,7 +48,6 @@ import { atomWithWebStorage } from '@/utils/atomWithWebStorage'
4848import { IndexPageContainer , IndexPageContent } from '../IndexPages/components'
4949import { Pagination } from '../Issues/Pagenation'
5050import { clIdAtom } from '../Issues/utils/store'
51- import { useDraftClList } from './hook/useDraftClList'
5251
5352type ItemsType = NonNullable < PostApiClListData [ 'data' ] > [ 'items' ]
5453
@@ -66,7 +65,6 @@ export default function CLView() {
6665 const [ _clid , setClid ] = useAtom ( clIdAtom )
6766
6867 const { mutate : fetchClList } = usePostClList ( )
69- const { mutate : fetchDraftClList } = useDraftClList ( )
7068 const { members } = useSyncedMembers ( )
7169
7270 const filterState = useFilterState ( { scope : scope as string , type : 'cl' } )
@@ -104,121 +102,37 @@ export default function CLView() {
104102
105103 const params = filterStateRef . current . toApiParams ( )
106104 const currentOrder = orderRef . current
107- const baseAdditional : any = {
105+ const additional : any = {
108106 sort_by : handleSort ( currentOrder . sort ) ,
107+ asc : currentOrder . time === 'Oldest' ,
108+ status : status , // 始终传递 status,open 时后端会返回 open + draft
109109 ...params
110110 }
111111
112- if ( status === 'draft' ) {
113- fetchDraftClList (
114- {
115- data : {
116- pagination : { page, per_page : pageSize } ,
117- additional : baseAdditional
118- }
119- } ,
120- {
121- onSuccess : ( response ) => {
122- const data = response . data
123-
124- setClList ( ( data ?. items ?? [ ] ) as ItemsType )
125- setNumTotal ( data ?. total ?? 0 )
126- } ,
127- onError : apiErrorToast ,
128- onSettled : ( ) => setIsLoading ( false )
112+ fetchClList (
113+ {
114+ data : {
115+ pagination : { page, per_page : pageSize } ,
116+ additional
129117 }
130- )
131- } else if ( status === 'open' ) {
132- const additional : any = {
133- ...baseAdditional ,
134- status : 'open' ,
135- asc : currentOrder . time === 'Oldest'
136- }
137-
138- let openData : PostApiClListData [ 'data' ] | undefined
139- let draftData : PostApiClListData [ 'data' ] | undefined
140- let openFinished = false
141- let draftFinished = false
142-
143- const finalize = ( ) => {
144- if ( ! openFinished || ! draftFinished ) return
118+ } ,
119+ {
120+ onSuccess : ( response ) => {
121+ const data = response . data
145122
146- const openItems = ( openData ?. items ?? [ ] ) as ItemsType
147- const draftItems = ( draftData ?. items ?? [ ] ) as ItemsType
148-
149- setClList ( [ ...openItems , ...draftItems ] )
150- setNumTotal ( ( openData ?. total ?? 0 ) + ( draftData ?. total ?? 0 ) )
151- setIsLoading ( false )
152- }
153-
154- fetchClList (
155- {
156- data : {
157- pagination : { page, per_page : pageSize } ,
158- additional
159- }
123+ setClList ( ( data ?. items ?? [ ] ) as ItemsType )
124+ setNumTotal ( data ?. total ?? 0 )
160125 } ,
161- {
162- onSuccess : ( response ) => {
163- openData = response . data
164- } ,
165- onError : apiErrorToast ,
166- onSettled : ( ) => {
167- openFinished = true
168- finalize ( )
169- }
170- }
171- )
172-
173- fetchDraftClList (
174- {
175- data : {
176- pagination : { page, per_page : pageSize } ,
177- additional : baseAdditional
178- }
179- } ,
180- {
181- onSuccess : ( response ) => {
182- draftData = response . data
183- } ,
184- onError : apiErrorToast ,
185- onSettled : ( ) => {
186- draftFinished = true
187- finalize ( )
188- }
189- }
190- )
191- } else {
192- const additional : any = {
193- ...baseAdditional ,
194- status,
195- asc : currentOrder . time === 'Oldest'
126+ onError : apiErrorToast ,
127+ onSettled : ( ) => setIsLoading ( false )
196128 }
197-
198- fetchClList (
199- {
200- data : {
201- pagination : { page, per_page : pageSize } ,
202- additional
203- }
204- } ,
205- {
206- onSuccess : ( response ) => {
207- const data = response . data
208-
209- setClList ( ( data ?. items ?? [ ] ) as ItemsType )
210- setNumTotal ( data ?. total ?? 0 )
211- } ,
212- onError : apiErrorToast ,
213- onSettled : ( ) => setIsLoading ( false )
214- }
215- )
216- }
217- } , [ page , pageSize , status , fetchClList , fetchDraftClList ] )
129+ )
130+ } , [ page , pageSize , status , fetchClList ] )
218131
219132 useEffect ( ( ) => {
220133 fetchClListData ( )
221- } , [ page , pageSize , status , fetchClListData ] )
134+ // eslint-disable-next-line react-hooks/exhaustive-deps
135+ } , [ page , pageSize , status ] )
222136
223137 const handleSort = ( str : string ) : string => {
224138 switch ( str ) {
0 commit comments