Skip to content

Commit ea0b251

Browse files
author
GeorgeZhang2035
committed
temp storage
1 parent ad21b50 commit ea0b251

File tree

2 files changed

+175
-125
lines changed

2 files changed

+175
-125
lines changed

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

Lines changed: 11 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ import {
99
} from '@blueprintjs/core'
1010

1111
import { useAtom } from 'jotai'
12-
import { isEqual, isEqualWith, omit } from 'lodash-es'
1312
import { FC, useMemo, useState } from 'react'
1413

1514
import { AppToaster } from 'components/Toaster'
1615
import { OPERATORS, PROFESSIONS } from 'models/operator'
17-
import { favGroupAtom, ignoreKeyDic } from 'store/useFavGroups'
16+
import { favGroupAtom } from 'store/useFavGroups'
1817

19-
import { Group, Operator } from '../EditorSheet'
18+
import { Group } from '../EditorSheet'
2019
import { SheetContainerSkeleton } from './SheetContainerSkeleton'
2120
import { GroupNoData } from './SheetNoneData'
2221
import { useSheet } from './SheetProvider'
23-
import { GroupItem, SheetGroupItem } from './sheetGroup/SheetGroupItem'
22+
import { SheetGroupItem } from './sheetGroup/SheetGroupItem'
2423

2524
export interface SheetGroupProps {}
2625

@@ -31,13 +30,11 @@ export interface GroupListModifyProp {
3130
groupUpdateHandle?: (value: Group) => void
3231
}
3332

34-
const EditorGroupName = ({
35-
groupAddHandle,
36-
}: {
37-
groupAddHandle: GroupListModifyProp['groupAddHandle']
38-
}) => {
33+
const EditorGroupName: FC = () => {
3934
const [groupName, setGroupName] = useState('')
4035

36+
const { submitGroup } = useSheet()
37+
4138
const addGroupHandle = () => {
4239
const name = groupName.trim()
4340
if (!name) {
@@ -46,7 +43,7 @@ const EditorGroupName = ({
4643
intent: Intent.DANGER,
4744
})
4845
} else {
49-
groupAddHandle?.({ name })
46+
submitGroup({ name }, undefined, true)
5047
setGroupName('')
5148
}
5249
}
@@ -74,8 +71,7 @@ const EditorGroupName = ({
7471
}
7572

7673
const SheetGroup: FC<SheetGroupProps> = () => {
77-
const { submitGroup, existedGroups, existedOperators, removeGroup } =
78-
useSheet()
74+
const { existedGroups, existedOperators } = useSheet()
7975

8076
const [coverGroup, setCoverGroup] = useState<Group>()
8177

@@ -110,75 +106,12 @@ const SheetGroup: FC<SheetGroupProps> = () => {
110106
return result
111107
}, [existedOperators, existedGroups])
112108

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-
}
147109
const updateFavGroup = (value: Group) =>
148110
setFavGroups([
149111
...[...favGroups].filter(({ name }) => name !== value.name),
150112
{ ...value },
151113
])
152114

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-
182115
const [favGroups, setFavGroups] = useAtom(favGroupAtom)
183116

184117
return (
@@ -192,24 +125,13 @@ const SheetGroup: FC<SheetGroupProps> = () => {
192125
mini
193126
className="sticky top-0 z-10 backdrop-blur-lg py-1"
194127
>
195-
<EditorGroupName {...{ groupAddHandle }} />
128+
<EditorGroupName />
196129
</SheetContainerSkeleton>
197130
<SheetContainerSkeleton title="已设置的干员组" icon="cog" mini>
198131
<div>
199132
{existedGroups.length ? (
200133
<>
201134
{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-
// />
213135
<SheetGroupItem groupInfo={item} itemType="selected" />
214136
))}
215137
<H6 className="my-2 text-center">
@@ -229,13 +151,7 @@ const SheetGroup: FC<SheetGroupProps> = () => {
229151
<div>
230152
{defaultGroup.length
231153
? 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" />
239155
))
240156
: GroupNoData}
241157
</div>
@@ -244,14 +160,7 @@ const SheetGroup: FC<SheetGroupProps> = () => {
244160
<div>
245161
{favGroups.length
246162
? 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" />
255164
))
256165
: GroupNoData}
257166
</div>

0 commit comments

Comments
 (0)