@@ -9,18 +9,17 @@ import {
9
9
} from '@blueprintjs/core'
10
10
11
11
import { useAtom } from 'jotai'
12
- import { isEqual , isEqualWith , omit } from 'lodash-es'
13
12
import { FC , useMemo , useState } from 'react'
14
13
15
14
import { AppToaster } from 'components/Toaster'
16
15
import { OPERATORS , PROFESSIONS } from 'models/operator'
17
- import { favGroupAtom , ignoreKeyDic } from 'store/useFavGroups'
16
+ import { favGroupAtom } from 'store/useFavGroups'
18
17
19
- import { Group , Operator } from '../EditorSheet'
18
+ import { Group } from '../EditorSheet'
20
19
import { SheetContainerSkeleton } from './SheetContainerSkeleton'
21
20
import { GroupNoData } from './SheetNoneData'
22
21
import { useSheet } from './SheetProvider'
23
- import { GroupItem , SheetGroupItem } from './sheetGroup/SheetGroupItem'
22
+ import { SheetGroupItem } from './sheetGroup/SheetGroupItem'
24
23
25
24
export interface SheetGroupProps { }
26
25
@@ -31,13 +30,11 @@ export interface GroupListModifyProp {
31
30
groupUpdateHandle ?: ( value : Group ) => void
32
31
}
33
32
34
- const EditorGroupName = ( {
35
- groupAddHandle,
36
- } : {
37
- groupAddHandle : GroupListModifyProp [ 'groupAddHandle' ]
38
- } ) => {
33
+ const EditorGroupName : FC = ( ) => {
39
34
const [ groupName , setGroupName ] = useState ( '' )
40
35
36
+ const { submitGroup } = useSheet ( )
37
+
41
38
const addGroupHandle = ( ) => {
42
39
const name = groupName . trim ( )
43
40
if ( ! name ) {
@@ -46,7 +43,7 @@ const EditorGroupName = ({
46
43
intent : Intent . DANGER ,
47
44
} )
48
45
} else {
49
- groupAddHandle ?. ( { name } )
46
+ submitGroup ( { name } , undefined , true )
50
47
setGroupName ( '' )
51
48
}
52
49
}
@@ -74,8 +71,7 @@ const EditorGroupName = ({
74
71
}
75
72
76
73
const SheetGroup : FC < SheetGroupProps > = ( ) => {
77
- const { submitGroup, existedGroups, existedOperators, removeGroup } =
78
- useSheet ( )
74
+ const { existedGroups, existedOperators } = useSheet ( )
79
75
80
76
const [ coverGroup , setCoverGroup ] = useState < Group > ( )
81
77
@@ -110,75 +106,12 @@ const SheetGroup: FC<SheetGroupProps> = () => {
110
106
return result
111
107
} , [ existedOperators , existedGroups ] )
112
108
113
- const checkGroupExisted = ( target : string ) =>
114
- ! ! existedGroups . find ( ( item ) => item . name === target )
115
- const checkGroupPinned = ( target : Group , ignoreKey ?: string [ ] ) => {
116
- const checkTarget = favGroups . find ( ( item ) => item . name === target . name )
117
- if ( checkTarget ) {
118
- return isEqualWith (
119
- checkTarget ,
120
- omit ( target , [ ...( ignoreKey || ignoreKeyDic ) ] ) ,
121
- ( { opers : aOpers } , { opers : bOpers } ) =>
122
- isEqual (
123
- aOpers . map ( ( item ) => omit ( item , [ ...( ignoreKey || ignoreKeyDic ) ] ) ) ,
124
- bOpers . map ( ( item ) => omit ( item , [ ...( ignoreKey || ignoreKeyDic ) ] ) ) ,
125
- ) ,
126
- )
127
- } else {
128
- return false
129
- }
130
- }
131
- const checkSamePinned = ( target : string ) =>
132
- ! ! favGroups . find ( ( { name } ) => name === target )
133
- const changeOperatorOfOtherGroups = ( target : Operator [ ] | undefined ) => {
134
- target ?. forEach ( ( item ) => {
135
- existedGroups . forEach ( ( groupItem ) => {
136
- const oldLength = groupItem . opers ?. length || 0
137
- if ( oldLength ) {
138
- const opers = groupItem . opers ?. filter (
139
- ( operItem ) => operItem . name !== item . name ,
140
- )
141
- if ( opers ?. length !== oldLength )
142
- submitGroup ( { ...groupItem , ...{ opers } } , undefined , true )
143
- }
144
- } )
145
- } )
146
- }
147
109
const updateFavGroup = ( value : Group ) =>
148
110
setFavGroups ( [
149
111
...[ ...favGroups ] . filter ( ( { name } ) => name !== value . name ) ,
150
112
{ ...value } ,
151
113
] )
152
114
153
- const groupAddHandle : GroupListModifyProp [ 'groupAddHandle' ] = ( value ) => {
154
- if ( checkGroupExisted ( value . name ) ) {
155
- AppToaster . show ( {
156
- message : '干员组已存在!' ,
157
- intent : Intent . DANGER ,
158
- } )
159
- } else {
160
- if ( checkGroupPinned ( value ) ) changeOperatorOfOtherGroups ( value . opers )
161
- submitGroup ( value , undefined , true )
162
- }
163
- }
164
- const groupRemoveHandle : GroupListModifyProp [ 'groupRemoveHandle' ] = ( _id ) => {
165
- removeGroup ( existedGroups . findIndex ( ( item ) => item . _id === _id ) )
166
- }
167
- const groupPinHandle : GroupListModifyProp [ 'groupPinHandle' ] = ( value ) => {
168
- if ( checkGroupPinned ( value ) )
169
- setFavGroups ( [ ...favGroups ] . filter ( ( { name } ) => name !== value . name ) )
170
- else {
171
- if ( checkSamePinned ( value . name ) ) setCoverGroup ( value )
172
- else updateFavGroup ( value )
173
- }
174
- }
175
- const groupUpdateHandle : GroupListModifyProp [ 'groupUpdateHandle' ] = (
176
- value ,
177
- ) => {
178
- changeOperatorOfOtherGroups ( value . opers )
179
- submitGroup ( value , undefined , true )
180
- }
181
-
182
115
const [ favGroups , setFavGroups ] = useAtom ( favGroupAtom )
183
116
184
117
return (
@@ -192,24 +125,13 @@ const SheetGroup: FC<SheetGroupProps> = () => {
192
125
mini
193
126
className = "sticky top-0 z-10 backdrop-blur-lg py-1"
194
127
>
195
- < EditorGroupName { ... { groupAddHandle } } />
128
+ < EditorGroupName />
196
129
</ SheetContainerSkeleton >
197
130
< SheetContainerSkeleton title = "已设置的干员组" icon = "cog" mini >
198
131
< div >
199
132
{ existedGroups . length ? (
200
133
< >
201
134
{ existedGroups . map ( ( item ) => (
202
- // <GroupItem
203
- // key={item.name}
204
- // existedGroup={existedGroups}
205
- // existedOperator={existedOperators}
206
- // groupInfo={item}
207
- // exist={checkGroupExisted(item.name)}
208
- // pinned={checkGroupPinned(item)}
209
- // groupRemoveHandle={groupRemoveHandle}
210
- // groupPinHandle={groupPinHandle}
211
- // groupUpdateHandle={groupUpdateHandle}
212
- // />
213
135
< SheetGroupItem groupInfo = { item } itemType = "selected" />
214
136
) ) }
215
137
< H6 className = "my-2 text-center" >
@@ -229,13 +151,7 @@ const SheetGroup: FC<SheetGroupProps> = () => {
229
151
< div >
230
152
{ defaultGroup . length
231
153
? defaultGroup . map ( ( item ) => (
232
- < GroupItem
233
- key = { item . name }
234
- groupInfo = { item }
235
- exist = { checkGroupExisted ( item . name ) }
236
- groupAddHandle = { groupAddHandle }
237
- pinned = { false }
238
- />
154
+ < SheetGroupItem groupInfo = { item } itemType = "recommend" />
239
155
) )
240
156
: GroupNoData }
241
157
</ div >
@@ -244,14 +160,7 @@ const SheetGroup: FC<SheetGroupProps> = () => {
244
160
< div >
245
161
{ favGroups . length
246
162
? favGroups . map ( ( item ) => (
247
- < GroupItem
248
- key = { item . name }
249
- groupInfo = { item }
250
- exist = { checkGroupExisted ( item . name ) }
251
- groupAddHandle = { groupAddHandle }
252
- groupPinHandle = { groupPinHandle }
253
- pinned
254
- />
163
+ < SheetGroupItem groupInfo = { item } itemType = "fav" />
255
164
) )
256
165
: GroupNoData }
257
166
</ div >
0 commit comments