feat: disable send button and show tooltip when user have changes value on setting panel
This commit is contained in:
parent
4c67e5021c
commit
bf9cd4443c
@ -11,10 +11,15 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
|
Tooltip,
|
||||||
|
TooltipArrow,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipPortal,
|
||||||
|
TooltipTrigger,
|
||||||
FormControl,
|
FormControl,
|
||||||
} from '@janhq/uikit'
|
} from '@janhq/uikit'
|
||||||
|
|
||||||
import { atom, useAtomValue, useSetAtom } from 'jotai'
|
import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai'
|
||||||
|
|
||||||
import { twMerge } from 'tailwind-merge'
|
import { twMerge } from 'tailwind-merge'
|
||||||
|
|
||||||
@ -25,6 +30,8 @@ import DropdownListSidebar, {
|
|||||||
selectedModelAtom,
|
selectedModelAtom,
|
||||||
} from '@/containers/DropdownListSidebar'
|
} from '@/containers/DropdownListSidebar'
|
||||||
|
|
||||||
|
import { currentPromptAtom } from '@/containers/Providers/Jotai'
|
||||||
|
|
||||||
import { useCreateNewThread } from '@/hooks/useCreateNewThread'
|
import { useCreateNewThread } from '@/hooks/useCreateNewThread'
|
||||||
|
|
||||||
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
|
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
|
||||||
@ -63,6 +70,7 @@ const Sidebar: React.FC = () => {
|
|||||||
|
|
||||||
const componentDataRuntimeSetting = getConfigurationsData(modelRuntimeParams)
|
const componentDataRuntimeSetting = getConfigurationsData(modelRuntimeParams)
|
||||||
const setThreadSettingFormUpdate = useSetAtom(threadSettingFormUpdateAtom)
|
const setThreadSettingFormUpdate = useSetAtom(threadSettingFormUpdateAtom)
|
||||||
|
const [currentPrompt] = useAtom(currentPromptAtom)
|
||||||
|
|
||||||
const componentData = [
|
const componentData = [
|
||||||
...[
|
...[
|
||||||
@ -390,9 +398,19 @@ const Sidebar: React.FC = () => {
|
|||||||
<Button themes="secondaryBlue" block onClick={onCancel}>
|
<Button themes="secondaryBlue" block onClick={onCancel}>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
|
<Tooltip open={currentPrompt.length !== 0}>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
<Button type="submit" block>
|
<Button type="submit" block>
|
||||||
Save
|
Save
|
||||||
</Button>
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipPortal>
|
||||||
|
<TooltipContent side="top" className="max-w-[240px]">
|
||||||
|
<span>{`It seems changes haven't been saved yet`}</span>
|
||||||
|
<TooltipArrow />
|
||||||
|
</TooltipContent>
|
||||||
|
</TooltipPortal>
|
||||||
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import ThreadList from '@/screens/Chat/ThreadList'
|
|||||||
import Sidebar, { showRightSideBarAtom } from './Sidebar'
|
import Sidebar, { showRightSideBarAtom } from './Sidebar'
|
||||||
|
|
||||||
import { getCurrentChatMessagesAtom } from '@/helpers/atoms/ChatMessage.atom'
|
import { getCurrentChatMessagesAtom } from '@/helpers/atoms/ChatMessage.atom'
|
||||||
|
import { threadSettingFormUpdateAtom } from '@/helpers/atoms/Thread.atom'
|
||||||
import {
|
import {
|
||||||
activeThreadAtom,
|
activeThreadAtom,
|
||||||
getActiveThreadIdAtom,
|
getActiveThreadIdAtom,
|
||||||
@ -60,6 +61,8 @@ const ChatScreen = () => {
|
|||||||
const textareaRef = useRef<HTMLTextAreaElement>(null)
|
const textareaRef = useRef<HTMLTextAreaElement>(null)
|
||||||
const modelRef = useRef(activeModel)
|
const modelRef = useRef(activeModel)
|
||||||
|
|
||||||
|
const threadSettingFormUpdate = useAtomValue(threadSettingFormUpdateAtom)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
modelRef.current = activeModel
|
modelRef.current = activeModel
|
||||||
}, [activeModel])
|
}, [activeModel])
|
||||||
@ -171,7 +174,12 @@ const ChatScreen = () => {
|
|||||||
{messages[messages.length - 1]?.status !== MessageStatus.Pending ? (
|
{messages[messages.length - 1]?.status !== MessageStatus.Pending ? (
|
||||||
<Button
|
<Button
|
||||||
size="lg"
|
size="lg"
|
||||||
disabled={disabled || stateModel.loading || !activeThread}
|
disabled={
|
||||||
|
disabled ||
|
||||||
|
stateModel.loading ||
|
||||||
|
!activeThread ||
|
||||||
|
threadSettingFormUpdate
|
||||||
|
}
|
||||||
themes="primary"
|
themes="primary"
|
||||||
className="min-w-[100px]"
|
className="min-w-[100px]"
|
||||||
onClick={sendChatMessage}
|
onClick={sendChatMessage}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user