Skip to content

Commit 7708c74

Browse files
authored
Merge pull request #1 from GeorgeZhang2035/guan/temp1
fix(sheet): bug of fav group fixed!
2 parents 367e25a + dd67dfe commit 7708c74

File tree

5 files changed

+56
-47
lines changed

5 files changed

+56
-47
lines changed

src/components/editor/operator/EditorSheet.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ type EditorSheetProps = SheetOperatorProps & SheetGroupProps
1414
export type Group = CopilotDocV1.Group
1515
export type Operator = CopilotDocV1.Operator
1616

17-
const EditorOperatorSheet = (sheetProps: EditorSheetProps) => {
18-
return (
19-
<div className="overflow-y-auto">
20-
<SheetOperatorContainer {...sheetProps} />
21-
<SheetGroupContainer {...sheetProps} />
22-
</div>
23-
)
24-
}
17+
const EditorOperatorSheet = (sheetProps: EditorSheetProps) => (
18+
<article className="overflow-y-auto">
19+
<SheetOperatorContainer {...sheetProps} />
20+
<SheetGroupContainer {...sheetProps} />
21+
</article>
22+
)
2523

2624
export const EditorSheetTrigger = (sheetProps: EditorSheetProps) => {
2725
const [open, setOpen] = useState(false)

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ export const SheetContainerSkeleton = ({
3232
[mini],
3333
)
3434
return (
35-
<div className={className}>
36-
<div className={clsx('flex items-center pl-3', mini ? 'my-1' : 'my-5')}>
37-
<div className="flex items-center">
38-
{StaticTitle}
39-
{rightOptions}
40-
</div>
41-
</div>
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>
4242
{!mini && <Divider />}
4343
{children}
44-
</div>
44+
</section>
4545
)
4646
}

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

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useAtom } from 'jotai'
1111
import { isEqual, omit } from 'lodash-es'
1212
import { useMemo, useState } from 'react'
1313
import { UseFieldArrayRemove, UseFormSetError } from 'react-hook-form'
14+
import { useEvent } from 'react-use'
1415

1516
import { AppToaster } from 'components/Toaster'
1617
import { CopilotDocV1 } from 'models/copilot.schema'
@@ -127,6 +128,7 @@ const SheetGroup = ({
127128
...[...favGroups].filter(({ name }) => name !== value.name),
128129
{ ...value },
129130
])
131+
130132
const eventHandleProxy = (
131133
type: EventType,
132134
value: Group,
@@ -202,28 +204,30 @@ const SheetGroup = ({
202204
<>
203205
{FavCoverAlert}
204206
<div className="flex px-1">
205-
<div className="flex-1 sticky top-0 h-screen overflow-y-auto">
207+
<div className="flex-1 sticky top-0 max-h-screen flex flex-col">
208+
<div className="grow h-full overflow-y-auto py-1">
209+
<SheetContainerSkeleton title="已设置的分组" icon="cog" mini>
210+
<div>
211+
{existedGroups.length
212+
? existedGroups.map((item) => (
213+
<GroupItem
214+
key={item.name}
215+
existedGroup={existedGroups}
216+
existedOperator={existedOperators}
217+
groupInfo={item}
218+
editable
219+
exist={checkGroupExisted(item.name)}
220+
pinned={checkGroupPinned(item)}
221+
eventHandleProxy={eventHandleProxy}
222+
/>
223+
))
224+
: GroupNoData}
225+
</div>
226+
</SheetContainerSkeleton>
227+
</div>
206228
<SheetContainerSkeleton title="添加干员组" icon="add" mini>
207229
<EditorGroupName {...{ eventHandleProxy }} />
208230
</SheetContainerSkeleton>
209-
<SheetContainerSkeleton title="已设置的分组" icon="cog" mini>
210-
<div>
211-
{existedGroups.length
212-
? existedGroups.map((item) => (
213-
<GroupItem
214-
key={item.name}
215-
existedGroup={existedGroups}
216-
existedOperator={existedOperators}
217-
groupInfo={item}
218-
editable
219-
exist={checkGroupExisted(item.name)}
220-
pinned={checkGroupPinned(item)}
221-
eventHandleProxy={eventHandleProxy}
222-
/>
223-
))
224-
: GroupNoData}
225-
</div>
226-
</SheetContainerSkeleton>
227231
</div>
228232
<Divider />
229233
<div className="flex-1">
@@ -237,7 +241,7 @@ const SheetGroup = ({
237241
editable={false}
238242
exist={checkGroupExisted(item.name)}
239243
eventHandleProxy={eventHandleProxy}
240-
pinned={checkGroupPinned(item)}
244+
pinned={false}
241245
/>
242246
))
243247
: GroupNoData}
@@ -253,7 +257,7 @@ const SheetGroup = ({
253257
editable={false}
254258
exist={checkGroupExisted(item.name)}
255259
eventHandleProxy={eventHandleProxy}
256-
pinned={checkGroupPinned(item)}
260+
pinned
257261
/>
258262
))
259263
: GroupNoData}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ const SheetOperator = ({
257257
className="cursor-pointer mx-auto text-sm text-gray-500 hover:text-inherit hover:underline"
258258
onClick={() => setPageIndex(pageIndex + 1)}
259259
>
260-
显示更多干员
260+
显示更多干员({operatorsGroupedBySubProf.length - lastIndex})
261261
</H6>
262262
)}
263263
</div>
@@ -384,9 +384,7 @@ const SheetOperator = ({
384384
export const SheetOperatorContainer = (
385385
sheetOperatorProp: SheetOperatorProps,
386386
) => (
387-
<div>
388-
<SheetContainerSkeleton title="选择干员" icon="person">
389-
<SheetOperator {...sheetOperatorProp} />
390-
</SheetContainerSkeleton>
391-
</div>
387+
<SheetContainerSkeleton title="选择干员" icon="person">
388+
<SheetOperator {...sheetOperatorProp} />
389+
</SheetContainerSkeleton>
392390
)

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ export const GroupItem = ({
108108
),
109109
[groupInfo.name],
110110
)
111-
const GroupOperations = useMemo(() => {
111+
112+
const GroupActions = useMemo(() => {
112113
const pinText = pinned ? `从收藏移除` : `添加至收藏`
113114
const pinIcon = pinned ? 'star' : 'star-empty'
114115
return (
@@ -132,6 +133,7 @@ export const GroupItem = ({
132133
)}
133134
{(editable || pinned) && (
134135
<Popover2
136+
disabled={!pinned}
135137
content={
136138
<Menu className="p-0">
137139
<MenuItem
@@ -142,18 +144,25 @@ export const GroupItem = ({
142144
</Menu>
143145
}
144146
>
145-
<Button minimal icon={pinIcon} title={pinText} />
147+
<Button
148+
minimal
149+
icon={pinIcon}
150+
title={pinText}
151+
onClick={
152+
pinned ? undefined : () => eventHandleProxy('pin', groupInfo)
153+
}
154+
/>
146155
</Popover2>
147156
)}
148157
</div>
149158
)
150-
}, [showOperators, pinned, exist])
159+
}, [showOperators, pinned, exist, eventHandleProxy])
151160

152161
return (
153162
<Card interactive={!exist} className="mt-1 mx-0.5">
154163
<div className="flex items-center">
155164
{GroupName}
156-
{GroupOperations}
165+
{GroupActions}
157166
</div>
158167
{OperatorsPart}
159168
</Card>

0 commit comments

Comments
 (0)