@@ -2,77 +2,84 @@ import { Button, NonIdealState } from '@blueprintjs/core'
2
2
3
3
import { UseOperationsParams , useOperations } from 'apis/operation'
4
4
import { useAtomValue } from 'jotai'
5
- import { ComponentType , ReactNode } from 'react'
5
+ import { ComponentType , ReactNode , useEffect } from 'react'
6
6
7
7
import { neoLayoutAtom } from 'store/pref'
8
8
9
9
import { NeoOperationCard , OperationCard } from './OperationCard'
10
10
import { withSuspensable } from './Suspensable'
11
11
12
- export const OperationList : ComponentType < UseOperationsParams > =
13
- withSuspensable (
14
- ( props ) => {
15
- const neoLayout = useAtomValue ( neoLayoutAtom )
12
+ interface OperationListProps extends UseOperationsParams {
13
+ onUpdate ?: ( params : { total : number } ) => void
14
+ }
16
15
17
- const { operations, setSize, isValidating, isReachingEnd } =
18
- useOperations ( {
19
- ...props ,
20
- suspense : true ,
21
- } )
16
+ export const OperationList : ComponentType < OperationListProps > = withSuspensable (
17
+ ( { onUpdate, ...params } ) => {
18
+ const neoLayout = useAtomValue ( neoLayoutAtom )
22
19
23
- // make TS happy: we got Suspense out there
24
- if ( ! operations ) throw new Error ( 'unreachable' )
20
+ const { operations, total, setSize, isValidating, isReachingEnd } =
21
+ useOperations ( {
22
+ ...params ,
23
+ suspense : true ,
24
+ } )
25
25
26
- const items : ReactNode = neoLayout ? (
27
- < div
28
- className = "grid gap-4"
29
- style = { {
30
- gridTemplateColumns : 'repeat(auto-fill, minmax(20rem, 1fr)' ,
31
- } }
32
- >
33
- { operations . map ( ( operation ) => (
34
- < NeoOperationCard operation = { operation } key = { operation . id } />
35
- ) ) }
36
- </ div >
37
- ) : (
38
- operations . map ( ( operation ) => (
39
- < OperationCard operation = { operation } key = { operation . id } />
40
- ) )
41
- )
26
+ // make TS happy: we got Suspense out there
27
+ if ( ! operations ) throw new Error ( 'unreachable' )
42
28
43
- return (
44
- < >
45
- { items }
29
+ useEffect ( ( ) => {
30
+ onUpdate ?. ( { total } )
31
+ } , [ total , onUpdate ] )
46
32
47
- { isReachingEnd && operations . length === 0 && (
48
- < NonIdealState
49
- icon = "slash"
50
- title = "没有找到任何作业"
51
- description = "(つД`)・゚・"
52
- />
53
- ) }
33
+ const items : ReactNode = neoLayout ? (
34
+ < div
35
+ className = "grid gap-4"
36
+ style = { {
37
+ gridTemplateColumns : 'repeat(auto-fill, minmax(20rem, 1fr)' ,
38
+ } }
39
+ >
40
+ { operations . map ( ( operation ) => (
41
+ < NeoOperationCard operation = { operation } key = { operation . id } />
42
+ ) ) }
43
+ </ div >
44
+ ) : (
45
+ operations . map ( ( operation ) => (
46
+ < OperationCard operation = { operation } key = { operation . id } />
47
+ ) )
48
+ )
54
49
55
- { isReachingEnd && operations . length !== 0 && (
56
- < div className = "mt-8 w-full tracking-wider text-center select-none text-slate-500" >
57
- 已经到底了哦 (゚▽゚)/
58
- </ div >
59
- ) }
50
+ return (
51
+ < >
52
+ { items }
60
53
61
- { ! isReachingEnd && (
62
- < Button
63
- loading = { isValidating }
64
- text = "加载更多"
65
- icon = "more"
66
- className = "mt-2"
67
- large
68
- fill
69
- onClick = { ( ) => setSize ( ( size ) => size + 1 ) }
70
- />
71
- ) }
72
- </ >
73
- )
74
- } ,
75
- {
76
- retryOnChange : [ 'orderBy' , 'keyword' , 'levelKeyword' , 'operator' ] ,
77
- } ,
78
- )
54
+ { isReachingEnd && operations . length === 0 && (
55
+ < NonIdealState
56
+ icon = "slash"
57
+ title = "没有找到任何作业"
58
+ description = "(つД`)・゚・"
59
+ />
60
+ ) }
61
+
62
+ { isReachingEnd && operations . length !== 0 && (
63
+ < div className = "mt-8 w-full tracking-wider text-center select-none text-slate-500" >
64
+ 已经到底了哦 (゚▽゚)/
65
+ </ div >
66
+ ) }
67
+
68
+ { ! isReachingEnd && (
69
+ < Button
70
+ loading = { isValidating }
71
+ text = "加载更多"
72
+ icon = "more"
73
+ className = "mt-2"
74
+ large
75
+ fill
76
+ onClick = { ( ) => setSize ( ( size ) => size + 1 ) }
77
+ />
78
+ ) }
79
+ </ >
80
+ )
81
+ } ,
82
+ {
83
+ retryOnChange : [ 'orderBy' , 'keyword' , 'levelKeyword' , 'operator' ] ,
84
+ } ,
85
+ )
0 commit comments