forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
β¨ feat: experimentally support to pin assistant to sidebar (lobehub#4514
) * β¨ feat: support pin assistant at side * β¨ feat: add a feature flag * β test: fix tests * π style: fix avtar meta * π style: fix pin mode style * π style: add hotkeys
- Loading branch information
Showing
7 changed files
with
123 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { Avatar, Tooltip } from '@lobehub/ui'; | ||
import { Divider } from 'antd'; | ||
import { createStyles } from 'antd-style'; | ||
import isEqual from 'fast-deep-equal'; | ||
import { parseAsBoolean, useQueryState } from 'nuqs'; | ||
import { useHotkeys } from 'react-hotkeys-hook'; | ||
import { Flexbox } from 'react-layout-kit'; | ||
|
||
import HotKeys from '@/components/HotKeys'; | ||
import { useSessionStore } from '@/store/session'; | ||
import { sessionHelpers } from '@/store/session/helpers'; | ||
import { sessionSelectors } from '@/store/session/selectors'; | ||
|
||
const useStyles = createStyles(({ css, token }) => ({ | ||
avatar: css` | ||
position: relative; | ||
transition: all 200ms ease-out 0s; | ||
&:hover { | ||
box-shadow: 0 0 0 2px ${token.colorPrimary}; | ||
} | ||
`, | ||
avatarActive: css` | ||
background: ${token.colorFillQuaternary}; | ||
box-shadow: 0 0 0 2px ${token.colorPrimaryBorder}; | ||
`, | ||
})); | ||
|
||
const PinList = () => { | ||
const { styles, cx } = useStyles(); | ||
const list = useSessionStore(sessionSelectors.pinnedSessions, isEqual); | ||
const [activeId, switchSession] = useSessionStore((s) => [s.activeId, s.switchSession]); | ||
|
||
const hasList = list.length > 0; | ||
const [isPinned, setPinned] = useQueryState('pinned', parseAsBoolean); | ||
|
||
const switchAgent = (id: string) => { | ||
switchSession(id); | ||
setPinned(true); | ||
}; | ||
|
||
useHotkeys( | ||
list.slice(0, 9).map((e, i) => `ctrl+${i + 1}`), | ||
(keyboardEvent, hotkeysEvent) => { | ||
if (!hotkeysEvent.keys?.[0]) return; | ||
|
||
const index = parseInt(hotkeysEvent.keys?.[0]) - 1; | ||
const item = list[index]; | ||
if (!item) return; | ||
|
||
switchAgent(item.id); | ||
}, | ||
{ enableOnFormTags: true, preventDefault: true }, | ||
); | ||
|
||
return ( | ||
hasList && ( | ||
<> | ||
<Divider style={{ margin: '8px 12px' }} /> | ||
<Flexbox flex={1} gap={12} height={'100%'}> | ||
{list.slice(0, 9).map((item, index) => ( | ||
<Tooltip | ||
key={item.id} | ||
placement={'right'} | ||
title={ | ||
<Flexbox gap={8} horizontal> | ||
{sessionHelpers.getTitle(item.meta)} | ||
<HotKeys inverseTheme keys={`ctrl+${index + 1}`} /> | ||
</Flexbox> | ||
} | ||
> | ||
<Avatar | ||
avatar={sessionHelpers.getAvatar(item.meta)} | ||
background={item.meta.backgroundColor} | ||
className={cx( | ||
styles.avatar, | ||
isPinned && activeId === item.id ? styles.avatarActive : undefined, | ||
)} | ||
onClick={() => { | ||
switchAgent(item.id); | ||
}} | ||
/> | ||
</Tooltip> | ||
))} | ||
</Flexbox> | ||
</> | ||
) | ||
); | ||
}; | ||
|
||
export default PinList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters