@@ -18,12 +18,7 @@ import { OPERATORS, PROFESSIONS } from 'models/operator'
18
18
import { favGroupAtom , ignoreKeyDic } from 'store/useFavGroups'
19
19
20
20
import { EditorPerformerGroupProps } from '../EditorPerformerGroup'
21
- import {
22
- Group ,
23
- GroupEventType ,
24
- Operator ,
25
- SheetSubmitEventHandleType ,
26
- } from '../EditorSheet'
21
+ import { Group , Operator } from '../EditorSheet'
27
22
import { SheetContainerSkeleton } from './SheetContainerSkeleton'
28
23
import { GroupNoData } from './SheetNoneData'
29
24
import { GroupItem } from './sheetGroup/SheetGroupItem'
@@ -35,7 +30,54 @@ export interface SheetGroupProps {
35
30
removeGroup : UseFieldArrayRemove
36
31
}
37
32
38
- export type GroupEventHandleType = SheetSubmitEventHandleType < GroupEventType >
33
+ export interface GroupListModifyProp {
34
+ groupAddHandle ?: ( value : Group ) => void
35
+ groupRemoveHandle ?: ( _id : string ) => void
36
+ groupPinHandle ?: ( value : Group ) => void
37
+ groupUpdateHandle ?: ( value : Group ) => void
38
+ }
39
+
40
+ const EditorGroupName = ( {
41
+ groupAddHandle,
42
+ } : {
43
+ groupAddHandle : GroupListModifyProp [ 'groupAddHandle' ]
44
+ } ) => {
45
+ const [ groupName , setGroupName ] = useState ( '' )
46
+
47
+ const addGroupHandle = ( ) => {
48
+ const name = groupName . trim ( )
49
+ if ( ! name ) {
50
+ AppToaster . show ( {
51
+ message : '干员组名不能为空' ,
52
+ intent : Intent . DANGER ,
53
+ } )
54
+ } else {
55
+ groupAddHandle ?.( { name } )
56
+ setGroupName ( '' )
57
+ }
58
+ }
59
+
60
+ return (
61
+ < div className = "flex px-3 items-center" >
62
+ < InputGroup
63
+ type = "text"
64
+ value = { groupName }
65
+ placeholder = "输入干员组名"
66
+ onChange = { ( e ) => setGroupName ( e . target . value ) }
67
+ fill
68
+ />
69
+ < div className = "flex items-center" >
70
+ < Button minimal icon = "tick" title = "添加" onClick = { addGroupHandle } />
71
+ < Button
72
+ minimal
73
+ icon = "reset"
74
+ title = "重置"
75
+ onClick = { ( ) => setGroupName ( '' ) }
76
+ />
77
+ </ div >
78
+ </ div >
79
+ )
80
+ }
39
81
40
82
const SheetGroup = ( {
41
83
submitGroup,
@@ -116,48 +158,32 @@ const SheetGroup = ({
116
158
{ ...value } ,
117
159
] )
118
160
119
- const eventHandleProxy : GroupEventHandleType = ( type , value ) => {
120
- switch ( type ) {
121
- case GroupEventType . ADD : {
122
- if ( checkGroupExisted ( value . name ) ) {
123
- AppToaster . show ( {
124
- message : '干员组已存在!' ,
125
- intent : Intent . DANGER ,
126
- } )
127
- } else {
128
- if ( checkGroupPinned ( value ) ) changeOperatorOfOtherGroups ( value . opers )
129
- submitGroup ( value , undefined , true )
130
- }
131
- break
132
- }
133
- case GroupEventType . REMOVE : {
134
- removeGroup ( existedGroups . findIndex ( ( item ) => item . _id === value . _id ) )
135
- break
136
- }
137
- case GroupEventType . PIN : {
138
- if ( checkGroupPinned ( value ) )
139
- setFavGroups ( [ ...favGroups ] . filter ( ( { name } ) => name !== value . name ) )
140
- else {
141
- if ( checkSamePinned ( value . name ) ) setCoverGroup ( value )
142
- else updateFavGroup ( value )
143
- }
144
- break
145
- }
146
- case GroupEventType . RENAME : {
147
- submitGroup ( value , undefined , true )
148
- break
149
- }
150
- case GroupEventType . OPERS : {
151
- changeOperatorOfOtherGroups ( value . opers )
152
- submitGroup ( value , undefined , true )
153
- break
154
- }
155
- case GroupEventType . UPDATE : {
156
- submitGroup ( value , undefined , true )
157
- break
158
- }
161
+ const groupAddHandle = ( value : Group ) => {
162
+ if ( checkGroupExisted ( value . name ) ) {
163
+ AppToaster . show ( {
164
+ message : '干员组已存在!' ,
165
+ intent : Intent . DANGER ,
166
+ } )
167
+ } else {
168
+ if ( checkGroupPinned ( value ) ) changeOperatorOfOtherGroups ( value . opers )
169
+ submitGroup ( value , undefined , true )
170
+ }
171
+ }
172
+ const groupRemoveHandle = ( _id : string ) => {
173
+ removeGroup ( existedGroups . findIndex ( ( item ) => item . _id === _id ) )
174
+ }
175
+ const groupPinHandle = ( value : Group ) => {
176
+ if ( checkGroupPinned ( value ) )
177
+ setFavGroups ( [ ...favGroups ] . filter ( ( { name } ) => name !== value . name ) )
178
+ else {
179
+ if ( checkSamePinned ( value . name ) ) setCoverGroup ( value )
180
+ else updateFavGroup ( value )
159
181
}
160
182
}
183
+ const groupUpdateHandle = ( value : Group ) => {
184
+ changeOperatorOfOtherGroups ( value . opers )
185
+ submitGroup ( value , undefined , true )
186
+ }
161
187
162
188
const [ favGroups , setFavGroups ] = useAtom ( favGroupAtom )
163
189
@@ -172,7 +198,7 @@ const SheetGroup = ({
172
198
mini
173
199
className = "sticky top-0 z-10 backdrop-blur-lg py-1"
174
200
>
175
- < EditorGroupName { ...{ eventHandleProxy } } />
201
+ < EditorGroupName { ...{ groupAddHandle } } />
176
202
</ SheetContainerSkeleton >
177
203
< SheetContainerSkeleton title = "已设置的干员组" icon = "cog" mini >
178
204
< div >
@@ -184,10 +210,11 @@ const SheetGroup = ({
184
210
existedGroup = { existedGroups }
185
211
existedOperator = { existedOperators }
186
212
groupInfo = { item }
187
- editable
188
213
exist = { checkGroupExisted ( item . name ) }
189
214
pinned = { checkGroupPinned ( item ) }
190
- eventHandleProxy = { eventHandleProxy }
215
+ groupRemoveHandle = { groupRemoveHandle }
216
+ groupPinHandle = { groupPinHandle }
217
+ groupUpdateHandle = { groupUpdateHandle }
191
218
/>
192
219
) ) }
193
220
< H6 className = "my-2 text-center" >
@@ -210,9 +237,8 @@ const SheetGroup = ({
210
237
< GroupItem
211
238
key = { item . name }
212
239
groupInfo = { item }
213
- editable = { false }
214
240
exist = { checkGroupExisted ( item . name ) }
215
- eventHandleProxy = { eventHandleProxy }
241
+ groupAddHandle = { groupAddHandle }
216
242
pinned = { false }
217
243
/>
218
244
) )
@@ -226,9 +252,9 @@ const SheetGroup = ({
226
252
< GroupItem
227
253
key = { item . name }
228
254
groupInfo = { item }
229
- editable = { false }
230
255
exist = { checkGroupExisted ( item . name ) }
231
- eventHandleProxy = { eventHandleProxy }
256
+ groupAddHandle = { groupAddHandle }
257
+ groupPinHandle = { groupPinHandle }
232
258
pinned
233
259
/>
234
260
) )
@@ -255,48 +281,6 @@ const SheetGroup = ({
255
281
)
256
282
}
257
283
258
- const EditorGroupName = ( {
259
- eventHandleProxy,
260
- } : {
261
- eventHandleProxy : GroupEventHandleType
262
- } ) => {
263
- const [ groupName , setGroupName ] = useState ( '' )
264
-
265
- const addGroupHandle = ( ) => {
266
- const name = groupName . trim ( )
267
- if ( ! name ) {
268
- AppToaster . show ( {
269
- message : '干员组名不能为空' ,
270
- intent : Intent . DANGER ,
271
- } )
272
- } else {
273
- eventHandleProxy ( GroupEventType . ADD , { name } )
274
- setGroupName ( '' )
275
- }
276
- }
277
-
278
- return (
279
- < div className = "flex px-3 items-center" >
280
- < InputGroup
281
- type = "text"
282
- value = { groupName }
283
- placeholder = "输入干员组名"
284
- onChange = { ( e ) => setGroupName ( e . target . value ) }
285
- fill
286
- />
287
- < div className = "flex items-center" >
288
- < Button minimal icon = "tick" title = "添加" onClick = { addGroupHandle } />
289
- < Button
290
- minimal
291
- icon = "reset"
292
- title = "重置"
293
- onClick = { ( ) => setGroupName ( '' ) }
294
- />
295
- </ div >
296
- </ div >
297
- )
298
- }
299
-
300
284
export const SheetGroupContainer : FC < SheetGroupProps > = ( sheetGroupProps ) => (
301
285
< SheetContainerSkeleton title = "设置干员组" icon = "people" >
302
286
< SheetGroup { ...sheetGroupProps } />
0 commit comments