Local storage sync

This commit is contained in:
Alex
2023-09-12 16:39:09 +01:00
parent ee0cbff245
commit 7f7856f0e4
7 changed files with 163 additions and 152 deletions

View File

@@ -109,7 +109,9 @@ function fetchAnswerStreaming({
export const DocsGPTWidget = ({ apiHost = 'https://gptcloud.arc53.com', selectDocs = 'default', apiKey = 'docsgpt-public'}) => {
// processing states
const [chatState, setChatState] = useState<ChatStates>(ChatStates.Init);
const [chatState, setChatState] = useState<ChatStates>(
() => localStorage.getItem('docsGPTChatState') as ChatStates || ChatStates.Init
);
const [answer, setAnswer] = useState<string>('');
//const selectDocs = 'local/1706.03762.pdf/'
@@ -122,6 +124,12 @@ export const DocsGPTWidget = ({ apiHost = 'https://gptcloud.arc53.com', selectDo
}
}, [answer]);
useEffect(() => {
if (chatState === ChatStates.Init || chatState === ChatStates.Minimized) {
localStorage.setItem('docsGPTChatState', chatState);
}
}, [chatState]);
// submit handler