Skip to content

Commit f0103bc

Browse files
author
gemini2035
committed
fixed(sheet): problem solved!
1 parent 71a6ab5 commit f0103bc

File tree

3 files changed

+26
-49
lines changed

3 files changed

+26
-49
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,20 @@ const SheetGroup = ({
7474
opers: otherOperators,
7575
})
7676
return result
77-
}, [existedOperators])
77+
}, [existedOperators, existedGroups])
7878

7979
const checkGroupExisted = (target: string) =>
8080
!!existedGroups.find((item) => item.name === target)
81-
const checkGroupPinned = (
82-
target: Group,
83-
ignoreKey: string[] = ignoreKeyDic,
84-
) => {
81+
const checkGroupPinned = (target: Group, ignoreKey?: string[]) => {
8582
const checkTarget = favGroups.find((item) => item.name === target.name)
8683
if (checkTarget) {
8784
return isEqualWith(
8885
checkTarget,
89-
omit(target, ignoreKey),
86+
omit(target, [...(ignoreKey || ignoreKeyDic)]),
9087
({ opers: aOpers }, { opers: bOpers }) =>
9188
isEqual(
92-
aOpers.map((item) => omit(item, ignoreKeyDic)),
93-
bOpers.map((item) => omit(item, ignoreKeyDic)),
89+
aOpers.map((item) => omit(item, [...(ignoreKey || ignoreKeyDic)])),
90+
bOpers.map((item) => omit(item, [...(ignoreKey || ignoreKeyDic)])),
9491
),
9592
)
9693
} else {

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Button, Divider, H4, H5, H6, Intent } from '@blueprintjs/core'
22

33
import clsx from 'clsx'
4-
import { useEffect, useMemo, useRef, useState } from 'react'
4+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
55
import { UseFieldArrayRemove } from 'react-hook-form'
66

77
import { AppToaster } from 'components/Toaster'
@@ -89,14 +89,17 @@ const SheetOperator = ({
8989
[selectedProf, existedOperators],
9090
)
9191

92-
const checkOperatorSelected = (target: string) => {
93-
if (existedOperators.find((item) => item.name === target)) return true
94-
else
95-
return !!existedGroups
96-
.map((item) => item.opers)
97-
.flat()
98-
.find((item) => item?.name === target)
99-
}
92+
const checkOperatorSelected = useCallback(
93+
(target: string) => {
94+
if (existedOperators.find((item) => item.name === target)) return true
95+
else
96+
return !!existedGroups
97+
.map((item) => item.opers)
98+
.flat()
99+
.find((item) => item?.name === target)
100+
},
101+
[existedOperators, existedGroups],
102+
)
100103

101104
const operatorsGroupedBySubProf = useMemo(() => {
102105
if (selectedSubProf.id === 'all') return operatorsGroupedByProf
@@ -108,7 +111,7 @@ const SheetOperator = ({
108111
return operatorsGroupedByProf.filter(
109112
(item) => item.subProf === selectedSubProf.id,
110113
)
111-
}, [selectedSubProf, operatorsGroupedByProf])
114+
}, [selectedSubProf, operatorsGroupedByProf, checkOperatorSelected])
112115

113116
const eventHandleProxy: OperatorEventHandleType = (type, value) => {
114117
switch (type) {

src/store/useFavGroups.ts

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,22 @@ import { atomWithStorage } from 'jotai/utils'
33
import { omit } from 'lodash-es'
44

55
import { CopilotDocV1 } from '../models/copilot.schema'
6-
import { authAtom } from './auth'
76

8-
const DEFAULTGROUPUSER = 'none_login_user'
9-
export const ignoreKeyDic = ['_id', 'id']
7+
export const ignoreKeyDic = ['_id', 'id'] as const
108
type Group = CopilotDocV1.Group
11-
interface FavGroupState {
12-
userId: string
13-
favGroups: Group[]
14-
}
15-
const favGroupCoreAtom = atomWithStorage<FavGroupState[]>(
9+
type FavGroup = Omit<Group, typeof ignoreKeyDic[number]>
10+
11+
const favGroupCoreAtom = atomWithStorage<FavGroup[]>(
1612
'maa-copilot-fav-groups',
1713
[],
1814
)
1915

2016
export const favGroupAtom = atom(
21-
(get) =>
22-
get(favGroupCoreAtom).find(
23-
(item) => item.userId === (get(authAtom).userId || DEFAULTGROUPUSER),
24-
)?.favGroups || ([] as Group[]),
17+
(get) => get(favGroupCoreAtom),
2518
(_get, set, favGroups: Group[]) => {
26-
const omitFavGroup = favGroups.map((item) =>
27-
omit(item, ignoreKeyDic),
28-
) as Group[]
29-
const { userId = DEFAULTGROUPUSER } = _get(authAtom)
30-
const oldFavGroup = [..._get(favGroupCoreAtom)]
31-
const existedFavGroupIndex = oldFavGroup.findIndex(
32-
(item) => item.userId === userId,
19+
set(
20+
favGroupCoreAtom,
21+
favGroups.map((item) => omit(item, ...ignoreKeyDic)),
3322
)
34-
if (existedFavGroupIndex === -1)
35-
set(favGroupCoreAtom, [
36-
...oldFavGroup,
37-
{ userId, favGroups: omitFavGroup },
38-
])
39-
else {
40-
oldFavGroup.splice(existedFavGroupIndex, 1, {
41-
userId,
42-
favGroups: omitFavGroup,
43-
})
44-
set(favGroupCoreAtom, oldFavGroup)
45-
}
4623
},
4724
)

0 commit comments

Comments
 (0)