diff --git a/src/components/settings/advanced.tsx b/src/components/settings/advanced.tsx index 2da65065..6e423ebb 100644 --- a/src/components/settings/advanced.tsx +++ b/src/components/settings/advanced.tsx @@ -1,7 +1,8 @@ -import { useCallback, useState } from 'react' +import { useCallback, useEffect, useState } from 'react' import { useAtom } from 'jotai' import { Switch, RadioGroup } from '@headlessui/react' +import { Textarea } from '../ui/textarea' import { DialogDescription, DialogHeader, @@ -12,12 +13,21 @@ import { PrompsTemplates, systemPromptsAtom, unlimitAtom } from '@/state' export function AdvancedSetting() { const [enableUnlimit, setUnlimit] = useAtom(unlimitAtom) const [systemPrompt, setSystemPrompt] = useAtom(systemPromptsAtom) - const [selected, setSelected] = useState(PrompsTemplates.find((item) => item.content === (systemPrompt || ''))) + const [selected, setSelected] = useState(PrompsTemplates.find((item) => item.content === systemPrompt)) - const handleChangePrompt = useCallback((value: typeof PrompsTemplates[0]) => { + useEffect(() => { + if (!selected) { + setSelected(PrompsTemplates[PrompsTemplates.length - 1]) + } + }, [selected, systemPrompt, setSelected]) + const handleSwitchPrompt = useCallback((value: typeof PrompsTemplates[0]) => { setSelected(value) - setSystemPrompt(value.content) - }, [setSelected, setSystemPrompt]) + setSystemPrompt(value.content || systemPrompt) + }, [setSelected, systemPrompt, setSystemPrompt]) + + const handleChangePrompt = useCallback((value: string) => { + setSystemPrompt(value) + }, []) return ( <> @@ -44,41 +54,40 @@ export function AdvancedSetting() { 预设角色
- + Server size
{PrompsTemplates.map((prompt) => ( - `${active - ? 'ring-2 ring-white/60 ring-offset-2 ring-offset-sky-300' - : '' - } - ${checked ? 'bg-sky-900/75 text-white' : 'bg-white'} - relative flex cursor-pointer rounded-lg px-5 py-4 shadow-md focus:outline-none` + className={ + ({ active, checked }) => + `${active + ? 'ring-2 ring-white/60 ring-offset-2 ring-offset-sky-300' + : ''} + ${checked ? 'bg-sky-900/75 text-white' : 'bg-white'} + relative flex cursor-pointer rounded-lg px-5 py-4 shadow-md focus:outline-none` } > {({ checked }) => ( <> -
-
-
+
+
+
{prompt.label} - - {prompt.desc} - + {checked && prompt.label === '自定义' ? +