File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { FC , memo } from 'react'
2+ import dropdownIcon from '~/assets/icons/dropdown.svg'
3+ import { BotId } from '~app/bots'
4+ import SwitchBotDropdown from '../SwitchBotDropdown'
5+ import Tooltip from '../Tooltip'
6+
7+ interface Props {
8+ botId : BotId
9+ name : string
10+ fullName ?: string
11+ onSwitchBot ?: ( botId : BotId ) => void
12+ }
13+
14+ const ChatbotName : FC < Props > = ( props ) => {
15+ const node = (
16+ < Tooltip content = { props . fullName || props . name } >
17+ < span className = "font-semibold text-primary-text text-sm cursor-pointer" > { props . name } </ span >
18+ </ Tooltip >
19+ )
20+ if ( ! props . onSwitchBot ) {
21+ return node
22+ }
23+ const triggerNode = (
24+ < div className = "flex flex-row items-center gap-[2px]" >
25+ { node }
26+ < img src = { dropdownIcon } className = "w-5 h-5" />
27+ </ div >
28+ )
29+ return < SwitchBotDropdown selectedBotId = { props . botId } onChange = { props . onSwitchBot } triggerNode = { triggerNode } />
30+ }
31+
32+ export default memo ( ChatbotName )
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import Tooltip from '../Tooltip'
1818import ChatMessageInput from './ChatMessageInput'
1919import ChatMessageList from './ChatMessageList'
2020import WebAccessCheckbox from './WebAccessCheckbox'
21+ import ChatbotName from './ChatbotName'
2122
2223interface Props {
2324 botId : BotId
@@ -93,15 +94,15 @@ const ConversationPanel: FC<Props> = (props) => {
9394 < div className = "flex flex-row items-center" >
9495 < motion . img
9596 src = { botInfo . avatar }
96- className = "w-[18px] h-[18px] object-contain rounded-full"
97+ className = "w-[18px] h-[18px] object-contain rounded-full mr-2 "
9798 whileHover = { { rotate : 180 } }
9899 />
99- < Tooltip content = { props . bot . name || botInfo . name } >
100- < span className = "font-semibold text-primary-text text-sm cursor-default ml-2 mr-1" > { botInfo . name } </ span >
101- </ Tooltip >
102- { mode === 'compact' && props . onSwitchBot && (
103- < SwitchBotDropdown selectedBotId = { props . botId } onChange = { props . onSwitchBot } />
104- ) }
100+ < ChatbotName
101+ botId = { props . botId }
102+ name = { botInfo . name }
103+ fullName = { props . bot . name }
104+ onSwitchBot = { mode === 'compact' ? props . onSwitchBot : undefined }
105+ />
105106 </ div >
106107 < WebAccessCheckbox botId = { props . botId } />
107108 < div className = "flex flex-row items-center gap-3" >
Original file line number Diff line number Diff line change 11import { Menu , Transition } from '@headlessui/react'
2- import { FC , Fragment , useCallback } from 'react'
3- import dropdownIcon from '~/assets/icons/dropdown.svg'
2+ import { FC , Fragment , ReactNode } from 'react'
43import { BotId } from '~app/bots'
54import { useEnabledBots } from '~app/hooks/use-enabled-bots'
65
76interface Props {
7+ triggerNode : ReactNode
88 selectedBotId : BotId
99 onChange : ( botId : BotId ) => void
1010}
1111
1212const SwitchBotDropdown : FC < Props > = ( props ) => {
1313 const enabledBots = useEnabledBots ( )
14-
15- const onSelect = useCallback (
16- ( botId : BotId ) => {
17- props . onChange ( botId )
18- } ,
19- [ props ] ,
20- )
21-
2214 return (
2315 < Menu as = "div" className = "relative inline-block text-left h-5" >
24- < Menu . Button >
25- < img src = { dropdownIcon } className = "w-5 h-5" />
26- </ Menu . Button >
16+ < Menu . Button className = "flex" > { props . triggerNode } </ Menu . Button >
2717 < Transition
2818 as = { Fragment }
2919 enter = "transition ease-out duration-100"
@@ -42,7 +32,7 @@ const SwitchBotDropdown: FC<Props> = (props) => {
4232 < Menu . Item key = { botId } >
4333 < div
4434 className = "px-4 py-2 ui-active:bg-primary-blue ui-active:text-white ui-not-active:text-secondary-text cursor-pointer flex flex-row items-center gap-3 pr-8"
45- onClick = { ( ) => onSelect ( botId ) }
35+ onClick = { ( ) => props . onChange ( botId ) }
4636 >
4737 < div className = "w-4 h-4" >
4838 < img src = { bot . avatar } className = "w-4 h-4" />
Original file line number Diff line number Diff line change 1- import { cx } from '~/utils'
21import { useAtom } from 'jotai'
32import { useCallback , useMemo } from 'react'
43import { useTranslation } from 'react-i18next'
54import clearIcon from '~/assets/icons/clear.svg'
5+ import { cx } from '~/utils'
66import Button from '~app/components/Button'
77import ChatMessageInput from '~app/components/Chat/ChatMessageInput'
88import ChatMessageList from '~app/components/Chat/ChatMessageList'
9- import SwitchBotDropdown from '~app/components/SwitchBotDropdown '
9+ import ChatbotName from '~app/components/Chat/ChatbotName '
1010import { CHATBOTS } from '~app/consts'
1111import { ConversationContext , ConversationContextValue } from '~app/context'
1212import { useChat } from '~app/hooks/use-chat'
@@ -43,8 +43,7 @@ function SidePanelPage() {
4343 < div className = "border-b border-solid border-primary-border flex flex-row items-center justify-between gap-2 py-3 mx-3" >
4444 < div className = "flex flex-row items-center gap-2" >
4545 < img src = { botInfo . avatar } className = "w-4 h-4 object-contain rounded-full" />
46- < span className = "font-semibold text-primary-text text-xs" > { botInfo . name } </ span >
47- < SwitchBotDropdown selectedBotId = { botId } onChange = { setBotId } />
46+ < ChatbotName botId = { botId } name = { botInfo . name } onSwitchBot = { setBotId } />
4847 </ div >
4948 < div className = "flex flex-row items-center gap-3" >
5049 < img
You can’t perform that action at this time.
0 commit comments