Skip to content

Commit 82654be

Browse files
fix selected prompt being reset
1 parent f493ea5 commit 82654be

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/client/components/ChatV2/SettingsModal.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import apiClient from '../../util/apiClient'
1313
import { useSearchParams } from 'react-router-dom'
1414
import { BlueButton, OutlineButtonBlack } from './generics/Buttons'
1515
import { useAnalyticsDispatch } from '../../stores/analytics'
16+
import useLocalStorageState from '../../hooks/useLocalStorageState'
1617

1718
const useUrlPromptId = () => {
1819
const [searchParams] = useSearchParams()
@@ -75,7 +76,9 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({
7576
refetch()
7677
},
7778
})
78-
const [activePrompt, setActivePrompt] = useState<Prompt>()
79+
//local storage prompt prevents the annoying case where the user refreshes the page and the chosen prompt is reset to default, and the textbox displays incorrect prompt information
80+
const [localStoragePrompt, setLocalStoragePrompt] = useLocalStorageState< Prompt | undefined>('prompt', undefined)
81+
const [activePrompt, setActivePrompt] = useState<Prompt | undefined>(localStoragePrompt)
7982
const [myPromptModalOpen, setMyPromptModalOpen] = useState<boolean>(false)
8083
const mandatoryPrompt = course?.prompts.find((p) => p.mandatory)
8184
const urlPrompt = course?.prompts.find((p) => p.id === urlPromptId)
@@ -102,12 +105,14 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({
102105
if (!newPrompt) {
103106
console.log('Setting default prompt')
104107
setActivePrompt(undefined)
108+
setLocalStoragePrompt(undefined)
105109
setAssistantInstructions(DEFAULT_ASSISTANT_INSTRUCTIONS)
106110
return
107111
}
108112

109113
setAssistantInstructions(newPrompt.systemMessage)
110114
setActivePrompt(newPrompt)
115+
setLocalStoragePrompt(newPrompt)
111116
}
112117

113118
useEffect(() => {

0 commit comments

Comments
 (0)