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() { 预设角色