Skip to content

Commit 8bd95e3

Browse files
author
GeorgeZhang2035
committed
fix: some bugs in group fixed
1 parent ea0b251 commit 8bd95e3

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

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

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

1414
import clsx from 'clsx'
1515
import { useAtom } from 'jotai'
16-
import { isEqual } from 'lodash-es'
16+
import { isEqual, omit } from 'lodash-es'
1717
import { FC, ReactNode, useRef, useState } from 'react'
1818
import { useForm } from 'react-hook-form'
1919

2020
import { CardDeleteOption } from 'components/editor/CardOptions'
21-
import { favGroupAtom } from 'store/useFavGroups'
21+
import { favGroupAtom, ignoreKeyDic } from 'store/useFavGroups'
2222

2323
import { Group, Operator } from '../../EditorSheet'
2424
import { GroupListModifyProp } from '../SheetGroup'
@@ -327,7 +327,6 @@ const useSheetGroupItemController = ({
327327
({ name: nameInFav }) => nameInFav === name,
328328
)
329329
const pinned = isEqual({ name, opers }, findFavByName)
330-
console.log(pinned)
331330

332331
const onPinChange: GroupPinOptionProp['onPinChange'] = () => {
333332
setFavGroup(
@@ -390,9 +389,12 @@ const useSheetGroupItemController = ({
390389
}
391390
}
392391
case 'fav': {
393-
const selected = !!existedGroups.find(
392+
const selected = existedGroups.find(
394393
({ name: nameInExist }) => nameInExist === name,
395394
)
395+
const equal = selected
396+
? isEqual(omit(selected, ...ignoreKeyDic), { name, opers })
397+
: false
396398
const onPinChange: GroupPinOptionProp['onPinChange'] = () => {
397399
setFavGroup(
398400
favGroup.filter(({ name: nameInFav }) => nameInFav !== name),
@@ -428,8 +430,15 @@ const useSheetGroupItemController = ({
428430
<>
429431
<Button
430432
minimal
431-
icon={selected ? 'tick' : 'arrow-left'}
432-
title={selected ? '检测到同名干员组' : '使用该推荐分组'}
433+
disabled={!!selected}
434+
icon={selected && equal ? 'tick' : 'arrow-left'}
435+
title={
436+
selected
437+
? equal
438+
? '已添加'
439+
: '检测到同名干员组'
440+
: '使用该推荐分组'
441+
}
433442
onClick={() => submitGroup({ name, opers }, undefined, true)}
434443
/>
435444
<GroupPinOption pinned onPinChange={onPinChange} />
@@ -464,20 +473,23 @@ const GroupPinOption: FC<GroupPinOptionProp> = ({
464473
: isDuplicate
465474
? '此操作会替换同名干员组'
466475
: `添加至收藏分组`
467-
const pinIcon = pinned ? 'star' : isDuplicate ? 'warning-sign' : 'star-empty'
468476

469477
return (
470478
<Popover2
471479
disabled={!pinned && !isDuplicate}
472480
content={
473481
<Menu className="p-0">
474-
<MenuItem text={pinText} icon={pinIcon} onClick={onPinChange} />
482+
<MenuItem
483+
text={pinText}
484+
icon={pinned ? 'star' : isDuplicate ? 'warning-sign' : 'star-empty'}
485+
onClick={onPinChange}
486+
/>
475487
</Menu>
476488
}
477489
>
478490
<Button
479491
minimal
480-
icon={pinIcon}
492+
icon={pinned ? 'star' : 'star-empty'}
481493
title={pinText}
482494
onClick={pinned || isDuplicate ? undefined : onPinChange}
483495
/>

0 commit comments

Comments
 (0)