Skip to content

Commit f8e7da6

Browse files
author
gemini2035
committed
refactor(sheet): part of sheet optimized (except eventHandleProxy)
1 parent cd32e11 commit f8e7da6

File tree

11 files changed

+869
-592
lines changed

11 files changed

+869
-592
lines changed

scripts/shared.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export async function getOperators() {
114114
id: id,
115115
subProf: op.subProfessionId,
116116
...transformOperatorName(op.name),
117+
alt_name: op.appellation,
117118
},
118119
]
119120
}),

src/components/editor/operator/EditorSheet.tsx

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

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

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

@@ -23,15 +23,15 @@ const EditorOperatorSheet = (sheetProps: EditorSheetProps) => (
2323

2424
export const EditorSheetTrigger: FC<EditorSheetProps> = (sheetProps) => {
2525
const [open, setOpen] = useState(false)
26-
const miniMedia = useMemo(() => window.innerWidth < 600, [])
2726
return (
2827
<>
2928
<Drawer
3029
isOpen={open}
3130
onClose={() => setOpen(false)}
32-
size={miniMedia ? DrawerSize.LARGE : '55%'}
31+
size={DrawerSize.LARGE}
32+
className="max-w-[900px]"
3333
>
34-
<EditorOperatorSheet {...sheetProps} miniMedia={miniMedia} />
34+
<EditorOperatorSheet {...sheetProps} />
3535
</Drawer>
3636
<Button onClick={() => setOpen(true)} text="快捷编辑" fill />
3737
</>
Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Divider, H3, Icon, IconName, MaybeElement } from '@blueprintjs/core'
22

33
import clsx from 'clsx'
4-
import { ReactNode, useMemo } from 'react'
4+
import { ReactNode } from 'react'
55

66
interface SheetContainerSkeletonProps {
77
title: string
@@ -19,28 +19,16 @@ export const SheetContainerSkeleton = ({
1919
mini,
2020
rightOptions,
2121
className,
22-
}: SheetContainerSkeletonProps) => {
23-
const StaticTitle = useMemo(
24-
() => (
25-
<>
26-
<Icon icon={icon} size={mini ? 16 : 20} />
27-
<H3 className={clsx('p-0 m-0 ml-3 truncate', mini && '!text-lg')}>
28-
{title}
29-
</H3>
30-
</>
31-
),
32-
[mini],
33-
)
34-
return (
35-
<section className={className}>
36-
<header
37-
className={clsx('flex items-center pl-3', mini ? 'my-1' : 'my-5')}
38-
>
39-
{StaticTitle}
40-
{rightOptions}
41-
</header>
42-
{!mini && <Divider />}
43-
{children}
44-
</section>
45-
)
46-
}
22+
}: SheetContainerSkeletonProps) => (
23+
<section className={className}>
24+
<header className={clsx('flex items-center pl-3', mini ? 'my-1' : 'my-5')}>
25+
<Icon icon={icon} size={mini ? 16 : 20} />
26+
<H3 className={clsx('p-0 m-0 ml-3 truncate', mini && '!text-lg')}>
27+
{title}
28+
</H3>
29+
{rightOptions}
30+
</header>
31+
{!mini && <Divider />}
32+
{children}
33+
</section>
34+
)

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

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '@blueprintjs/core'
1010

1111
import { useAtom } from 'jotai'
12-
import { isEqual, omit } from 'lodash-es'
12+
import { isEqual, isEqualWith, omit } from 'lodash-es'
1313
import { FC, useMemo, useState } from 'react'
1414
import { UseFieldArrayRemove } from 'react-hook-form'
1515

@@ -82,27 +82,18 @@ const SheetGroup = ({
8282
) => {
8383
const checkTarget = favGroups.find((item) => item.name === target.name)
8484
if (checkTarget) {
85-
if ((checkTarget.opers?.length || 0) === (target.opers?.length || 0)) {
86-
for (const aItem of checkTarget.opers!) {
87-
if (
88-
target.opers?.find((bItem) => {
89-
return isEqual(
90-
omit(aItem, ignoreKeyDic),
91-
omit(bItem, ignoreKeyDic),
92-
)
93-
})
94-
)
95-
continue
96-
else return false
97-
}
98-
return true
99-
} else return false
100-
} else return false
101-
// return isEqualWith(checkTarget, target, (value1, value2, key) => {
102-
// if (ignoreKeyDic.find((item) => item === key)) return true
103-
// else {
104-
// }
105-
// })
85+
return isEqualWith(
86+
omit(checkTarget, ignoreKeyDic),
87+
omit(target, ignoreKeyDic),
88+
({ opers: aOpers }, { opers: bOpers }) =>
89+
isEqual(
90+
aOpers.map((item) => omit(item, ignoreKeyDic)),
91+
bOpers.map((item) => omit(item, ignoreKeyDic)),
92+
),
93+
)
94+
} else {
95+
return false
96+
}
10697
}
10798
const checkSamePinned = (target: string) =>
10899
!!favGroups.find(({ name }) => name === target)
@@ -111,11 +102,11 @@ const SheetGroup = ({
111102
existedGroups.forEach((groupItem) => {
112103
const oldLength = groupItem.opers?.length || 0
113104
if (oldLength) {
114-
groupItem.opers = groupItem.opers?.filter(
105+
const opers = groupItem.opers?.filter(
115106
(operItem) => operItem.name !== item.name,
116107
)
117-
if (groupItem.opers?.length !== oldLength)
118-
submitGroup(groupItem, undefined, true)
108+
if (opers?.length !== oldLength)
109+
submitGroup({ ...groupItem, ...{ opers } }, undefined, true)
119110
}
120111
})
121112
})
@@ -273,13 +264,14 @@ const EditorGroupName = ({
273264
const [groupName, setGroupName] = useState('')
274265

275266
const addGroupHandle = () => {
276-
if (!groupName) {
267+
const name = groupName.trim()
268+
if (!name) {
277269
AppToaster.show({
278270
message: '干员组名不能为空',
279271
intent: Intent.DANGER,
280272
})
281273
} else {
282-
eventHandleProxy('add', { name: groupName.trim() })
274+
eventHandleProxy('add', { name })
283275
setGroupName('')
284276
}
285277
}

0 commit comments

Comments
 (0)