fix: setting chatbox input (#3429)

* fix: setting chatbox input

* fix: linter issue
This commit is contained in:
Faisal Amir 2024-08-22 11:18:37 +07:00 committed by GitHub
parent 5c2f0d33fd
commit bb3bbd25d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 48 additions and 22 deletions

View File

@ -34,6 +34,7 @@ import {
reduceTransparentAtom, reduceTransparentAtom,
selectedSettingAtom, selectedSettingAtom,
} from '@/helpers/atoms/Setting.atom' } from '@/helpers/atoms/Setting.atom'
import { activeTabThreadRightPanelAtom } from '@/helpers/atoms/ThreadRightPanel.atom'
const TopPanel = () => { const TopPanel = () => {
const [showLeftPanel, setShowLeftPanel] = useAtom(showLeftPanelAtom) const [showLeftPanel, setShowLeftPanel] = useAtom(showLeftPanelAtom)
@ -43,6 +44,9 @@ const TopPanel = () => {
const reduceTransparent = useAtomValue(reduceTransparentAtom) const reduceTransparent = useAtomValue(reduceTransparentAtom)
const { requestCreateNewThread } = useCreateNewThread() const { requestCreateNewThread } = useCreateNewThread()
const assistants = useAtomValue(assistantsAtom) const assistants = useAtomValue(assistantsAtom)
const [activeTabThreadRightPanel, setActiveTabThreadRightPanel] = useAtom(
activeTabThreadRightPanelAtom
)
const onCreateNewThreadClick = () => { const onCreateNewThreadClick = () => {
if (!assistants.length) if (!assistants.length)
@ -107,11 +111,27 @@ const TopPanel = () => {
mainViewState !== MainViewState.Settings && ( mainViewState !== MainViewState.Settings && (
<Fragment> <Fragment>
{showRightPanel ? ( {showRightPanel ? (
<Button theme="icon" onClick={() => setShowRightPanel(false)}> <Button
theme="icon"
onClick={() => {
setShowRightPanel(false)
if (activeTabThreadRightPanel === 'model') {
setActiveTabThreadRightPanel(undefined)
}
}}
>
<PanelRightCloseIcon size={16} /> <PanelRightCloseIcon size={16} />
</Button> </Button>
) : ( ) : (
<Button theme="icon" onClick={() => setShowRightPanel(true)}> <Button
theme="icon"
onClick={() => {
setShowRightPanel(true)
if (activeTabThreadRightPanel === undefined) {
setActiveTabThreadRightPanel('model')
}
}}
>
<PanelRightOpenIcon size={16} /> <PanelRightOpenIcon size={16} />
</Button> </Button>
)} )}

View File

@ -1,4 +1,6 @@
import { atom } from 'jotai' import { atom } from 'jotai'
// Store tabs menu active state // Store tabs menu active state
export const activeTabThreadRightPanelAtom = atom<string>('assistant') export const activeTabThreadRightPanelAtom = atom<string | undefined>(
'assistant'
)

View File

@ -3,14 +3,7 @@ import { useEffect, useRef, useState } from 'react'
import { MessageStatus } from '@janhq/core' import { MessageStatus } from '@janhq/core'
import { import { TextArea, Button, Tooltip, useClickOutside, Badge } from '@janhq/joi'
TextArea,
Button,
Tooltip,
useClickOutside,
Badge,
useMediaQuery,
} from '@janhq/joi'
import { useAtom, useAtomValue } from 'jotai' import { useAtom, useAtomValue } from 'jotai'
import { import {
FileTextIcon, FileTextIcon,
@ -20,7 +13,6 @@ import {
SettingsIcon, SettingsIcon,
ChevronUpIcon, ChevronUpIcon,
Settings2Icon, Settings2Icon,
ShapesIcon,
} from 'lucide-react' } from 'lucide-react'
import { twMerge } from 'tailwind-merge' import { twMerge } from 'tailwind-merge'
@ -89,8 +81,6 @@ const ChatInput = () => {
const refAttachmentMenus = useClickOutside(() => setShowAttacmentMenus(false)) const refAttachmentMenus = useClickOutside(() => setShowAttacmentMenus(false))
const [showRightPanel, setShowRightPanel] = useAtom(showRightPanelAtom) const [showRightPanel, setShowRightPanel] = useAtom(showRightPanelAtom)
const matches = useMediaQuery('(max-width: 880px)')
useEffect(() => { useEffect(() => {
if (isWaitingToSend && activeThreadId) { if (isWaitingToSend && activeThreadId) {
setIsWaitingToSend(false) setIsWaitingToSend(false)
@ -403,11 +393,25 @@ const ChatInput = () => {
activeTabThreadRightPanel === 'model' ? 'solid' : 'outline' activeTabThreadRightPanel === 'model' ? 'solid' : 'outline'
} }
onClick={() => { onClick={() => {
setActiveTabThreadRightPanel('model') // TODO @faisal: should be refactor later and better experience beetwen tab and toggle button
if (matches) { if (showRightPanel && activeTabThreadRightPanel !== 'model') {
setShowRightPanel(!showRightPanel)
} else if (!showRightPanel) {
setShowRightPanel(true) setShowRightPanel(true)
setActiveTabThreadRightPanel('model')
}
if (showRightPanel && activeTabThreadRightPanel === 'model') {
setShowRightPanel(false)
setActiveTabThreadRightPanel(undefined)
}
if (activeTabThreadRightPanel === undefined) {
setShowRightPanel(true)
setActiveTabThreadRightPanel('model')
}
if (
!showRightPanel &&
activeTabThreadRightPanel !== 'model'
) {
setShowRightPanel(true)
setActiveTabThreadRightPanel('model')
} }
}} }}
> >
@ -415,9 +419,9 @@ const ChatInput = () => {
size={16} size={16}
className="flex-shrink-0 cursor-pointer text-[hsla(var(--text-secondary))]" className="flex-shrink-0 cursor-pointer text-[hsla(var(--text-secondary))]"
/> />
<span>Inference</span>
</Badge> </Badge>
{experimentalFeature && ( {/* Temporary disable it */}
{/* {experimentalFeature && (
<Badge <Badge
className="flex cursor-pointer items-center gap-x-1" className="flex cursor-pointer items-center gap-x-1"
theme="secondary" theme="secondary"
@ -439,7 +443,7 @@ const ChatInput = () => {
/> />
<span>Tools</span> <span>Tools</span>
</Badge> </Badge>
)} )} */}
</div> </div>
<Button <Button
theme="icon" theme="icon"

View File

@ -191,7 +191,7 @@ const ThreadRightPanel = () => {
{ name: 'Model', value: 'model' }, { name: 'Model', value: 'model' },
...(experimentalFeature ? [{ name: 'Tools', value: 'tools' }] : []), ...(experimentalFeature ? [{ name: 'Tools', value: 'tools' }] : []),
]} ]}
value={activeTabThreadRightPanel} value={activeTabThreadRightPanel as string}
onValueChange={(value) => setActiveTabThreadRightPanel(value)} onValueChange={(value) => setActiveTabThreadRightPanel(value)}
> >
<TabsContent value="assistant"> <TabsContent value="assistant">