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

View File

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

View File

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