Skip to content

Commit 80e9152

Browse files
author
GeorgeZhang2035
committed
perf(sheet): ui of group optimized!
1 parent ad87c12 commit 80e9152

File tree

7 files changed

+32
-53
lines changed

7 files changed

+32
-53
lines changed

src/components/editor/operator/EditorPerformer.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export const EditorPerformer: FC<EditorPerformerProps> = ({ control }) => {
229229
({ name, _id }) => name === operator.name && _id !== operator._id,
230230
)
231231
) {
232-
setError('name', { message: '干员已存在' })
232+
setError?.('name', { message: '干员已存在' })
233233
return false
234234
}
235235

@@ -297,7 +297,7 @@ export const EditorPerformer: FC<EditorPerformerProps> = ({ control }) => {
297297

298298
setEditingOperator(undefined)
299299
} else {
300-
setError('global' as any, { message: '未能找到要更新的干员' })
300+
setError?.('global' as any, { message: '未能找到要更新的干员' })
301301
return false
302302
}
303303
} else {
@@ -324,7 +324,7 @@ export const EditorPerformer: FC<EditorPerformerProps> = ({ control }) => {
324324
if (
325325
groups.find(({ name, _id }) => name === group.name && _id !== group._id)
326326
) {
327-
setError('name', { message: '干员组已存在' })
327+
setError?.('name', { message: '干员组已存在' })
328328
return false
329329
}
330330
if (editingGroup || fromSheet) {
@@ -340,7 +340,7 @@ export const EditorPerformer: FC<EditorPerformerProps> = ({ control }) => {
340340
)
341341
setEditingGroup(undefined)
342342
} else {
343-
setError('global' as any, { message: '未能找到要更新的干员组' })
343+
setError?.('global' as any, { message: '未能找到要更新的干员组' })
344344
return false
345345
}
346346
} else {

src/components/editor/operator/EditorPerformerGroup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface EditorPerformerGroupProps {
1616
group?: CopilotDocV1.Group
1717
submit: (
1818
group: CopilotDocV1.Group,
19-
setError: UseFormSetError<CopilotDocV1.Group>,
19+
setError?: UseFormSetError<CopilotDocV1.Group>,
2020
fromSheet?: boolean,
2121
) => boolean
2222
onCancel: () => void

src/components/editor/operator/EditorPerformerOperator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface EditorPerformerOperatorProps {
2525
groups: CopilotDocV1.Group[]
2626
submit: (
2727
values: EditorOperatorFormValues,
28-
setError: UseFormSetError<EditorOperatorFormValues>,
28+
setError?: UseFormSetError<EditorOperatorFormValues>,
2929
fromSheet?: boolean,
3030
) => boolean
3131
onCancel: () => void

src/components/editor/operator/EditorSheet.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Button, Drawer, DrawerSize } from '@blueprintjs/core'
22

3-
import { useMemo, useState } from 'react'
3+
import { FC, useMemo, useState } from 'react'
44

55
import { CopilotDocV1 } from 'models/copilot.schema'
66

@@ -21,7 +21,7 @@ const EditorOperatorSheet = (sheetProps: EditorSheetProps) => (
2121
</article>
2222
)
2323

24-
export const EditorSheetTrigger = (sheetProps: EditorSheetProps) => {
24+
export const EditorSheetTrigger: FC<EditorSheetProps> = (sheetProps) => {
2525
const [open, setOpen] = useState(false)
2626
const miniMedia = useMemo(() => window.innerWidth < 600, [])
2727
return (

src/components/editor/operator/sheet/SheetGroup.tsx

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010

1111
import { useAtom } from 'jotai'
1212
import { isEqual, omit } from 'lodash-es'
13-
import { useMemo, useState } from 'react'
14-
import { UseFieldArrayRemove, UseFormSetError } from 'react-hook-form'
13+
import { FC, useMemo, useState } from 'react'
14+
import { UseFieldArrayRemove } from 'react-hook-form'
1515

1616
import { AppToaster } from 'components/Toaster'
1717
import { CopilotDocV1 } from 'models/copilot.schema'
@@ -106,10 +106,7 @@ const SheetGroup = ({
106106
}
107107
const checkSamePinned = (target: string) =>
108108
!!favGroups.find(({ name }) => name === target)
109-
const changeOperatorOfOtherGroups = (
110-
target: Operator[] | undefined,
111-
errHandle: UseFormSetError<Group>,
112-
) => {
109+
const changeOperatorOfOtherGroups = (target: Operator[] | undefined) => {
113110
target?.forEach((item) => {
114111
existedGroups.forEach((groupItem) => {
115112
const oldLength = groupItem.opers?.length || 0
@@ -118,7 +115,7 @@ const SheetGroup = ({
118115
(operItem) => operItem.name !== item.name,
119116
)
120117
if (groupItem.opers?.length !== oldLength)
121-
submitGroup(groupItem, errHandle, true)
118+
submitGroup(groupItem, undefined, true)
122119
}
123120
})
124121
})
@@ -129,12 +126,7 @@ const SheetGroup = ({
129126
{ ...value },
130127
])
131128

132-
const eventHandleProxy = (
133-
type: EventType,
134-
value: Group,
135-
setError?: UseFormSetError<Group>,
136-
) => {
137-
const errHandle = setError || function () {}
129+
const eventHandleProxy = (type: EventType, value: Group) => {
138130
switch (type) {
139131
case 'add': {
140132
if (checkGroupExisted(value.name)) {
@@ -143,9 +135,8 @@ const SheetGroup = ({
143135
intent: Intent.DANGER,
144136
})
145137
} else {
146-
if (checkGroupPinned(value))
147-
changeOperatorOfOtherGroups(value.opers, errHandle)
148-
submitGroup(value, errHandle)
138+
if (checkGroupPinned(value)) changeOperatorOfOtherGroups(value.opers)
139+
submitGroup(value)
149140
}
150141
break
151142
}
@@ -163,16 +154,16 @@ const SheetGroup = ({
163154
break
164155
}
165156
case 'rename': {
166-
submitGroup(value, errHandle, true)
157+
submitGroup(value, undefined, true)
167158
break
168159
}
169160
case 'opers': {
170-
changeOperatorOfOtherGroups(value.opers, errHandle)
171-
submitGroup(value, errHandle, true)
161+
changeOperatorOfOtherGroups(value.opers)
162+
submitGroup(value, undefined, true)
172163
break
173164
}
174165
case 'update': {
175-
submitGroup(value, errHandle, true)
166+
submitGroup(value, undefined, true)
176167
break
177168
}
178169
}
@@ -291,11 +282,7 @@ const SheetGroup = ({
291282
const EditorGroupName = ({
292283
eventHandleProxy,
293284
}: {
294-
eventHandleProxy: (
295-
type: EventType,
296-
value: Group,
297-
setError?: UseFormSetError<Group> | undefined,
298-
) => void
285+
eventHandleProxy: (type: EventType, value: Group) => void
299286
}) => {
300287
const [groupName, setGroupName] = useState('')
301288

@@ -346,7 +333,7 @@ const EditorGroupName = ({
346333
)
347334
}
348335

349-
export const SheetGroupContainer = (sheetGroupProps: SheetGroupProps) => (
336+
export const SheetGroupContainer: FC<SheetGroupProps> = (sheetGroupProps) => (
350337
<SheetContainerSkeleton title="设置干员组" icon="people">
351338
<SheetGroup {...sheetGroupProps} />
352339
</SheetContainerSkeleton>

src/components/editor/operator/sheet/sheetGroup/SheetGroupItem.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Popover2 } from '@blueprintjs/popover2'
1212

1313
import clsx from 'clsx'
1414
import { useMemo, useRef, useState } from 'react'
15-
import { UseFormSetError, useForm } from 'react-hook-form'
15+
import { useForm } from 'react-hook-form'
1616

1717
import { CardDeleteOption } from 'components/editor/CardOptions'
1818
import { CopilotDocV1 } from 'models/copilot.schema'
@@ -61,11 +61,8 @@ export const GroupItem = ({
6161
eventHandleProxy('update', groupInfoCopy)
6262
}
6363
}
64-
const renameEventHandle = (
65-
name: string,
66-
errorHandle: UseFormSetError<Group>,
67-
) => {
68-
eventHandleProxy('rename', { ...groupInfo, name }, errorHandle)
64+
const renameEventHandle = (name: string) => {
65+
eventHandleProxy('rename', { ...groupInfo, name })
6966
}
7067

7168
const OperatorsPart = useMemo(
@@ -175,13 +172,13 @@ const GroupTitle = ({
175172
renameSubmit,
176173
}: {
177174
editable: boolean
178-
renameSubmit: (newName: string, errorHandle: UseFormSetError<Group>) => void
175+
renameSubmit: (newName: string) => void
179176
groupTitle: string
180177
}) => {
181178
const [editName, setEditName] = useState('')
182179
const [nameEditState, setNameEditState] = useState(false)
183180
const [alertState, setAlertState] = useState(false)
184-
const { register, handleSubmit, setError, reset } = useForm<Group>()
181+
const { register, handleSubmit, reset } = useForm<Group>()
185182
// handle differ priority of capture events
186183
const ignoreBlur = useRef(false)
187184
const blurHandle = () => {
@@ -270,7 +267,7 @@ const GroupTitle = ({
270267
className="flex items-center"
271268
onSubmit={handleSubmit(() => {
272269
ignoreBlur.current = true
273-
renameSubmit(editName || groupTitle, setError)
270+
renameSubmit(editName || groupTitle)
274271
setNameEditState(false)
275272
inputRef.current?.blur()
276273
})}

src/components/editor/operator/sheet/sheetGroup/SheetGroupOperatorSelect.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import {
1313
import { Popover2 } from '@blueprintjs/popover2'
1414

1515
import clsx from 'clsx'
16-
import { useMemo, useState } from 'react'
17-
import { UseFormSetError } from 'react-hook-form'
16+
import { FC, useMemo, useState } from 'react'
1817

1918
import { Group, Operator } from '../../EditorSheet'
2019
import { SheetContainerSkeleton } from '../SheetContainerSkeleton'
@@ -25,11 +24,7 @@ export interface SheetGroupOperatorSelectProp {
2524
existedOperator?: Operator[]
2625
existedGroup?: Group[]
2726
groupInfo: Group
28-
eventHandleProxy: (
29-
type: EventType,
30-
value: Group,
31-
setError?: UseFormSetError<Group>,
32-
) => void
27+
eventHandleProxy: (type: EventType, value: Group) => void
3328
}
3429

3530
const SheetGroupOperatorSelect = ({
@@ -234,9 +229,9 @@ const SheetGroupOperatorSelect = ({
234229
)
235230
}
236231

237-
export const SheetGroupOperatorSelectTrigger = (
238-
sheetGroupOperatorSelectProp: SheetGroupOperatorSelectProp,
239-
) => (
232+
export const SheetGroupOperatorSelectTrigger: FC<
233+
SheetGroupOperatorSelectProp
234+
> = (sheetGroupOperatorSelectProp) => (
240235
<Popover2
241236
className="w-full mt-1"
242237
content={<SheetGroupOperatorSelect {...sheetGroupOperatorSelectProp} />}

0 commit comments

Comments
 (0)