From 355d6e3cf2416bc5b8dff56e69e67b20c2269405 Mon Sep 17 00:00:00 2001 From: TaylorS15 Date: Wed, 22 Feb 2023 18:34:20 -0500 Subject: [PATCH] small change --- frontend/src/preferences/SelectDocsModal.tsx | 31 ++++++++++++-------- frontend/src/preferences/preferenceApi.ts | 12 ++------ 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/frontend/src/preferences/SelectDocsModal.tsx b/frontend/src/preferences/SelectDocsModal.tsx index 7a36e5a5..45d8f6c6 100644 --- a/frontend/src/preferences/SelectDocsModal.tsx +++ b/frontend/src/preferences/SelectDocsModal.tsx @@ -41,32 +41,39 @@ export default function APIKeyModal({ function handleCancel() { async function getRecentDocs() { - const recentDocs = await getLocalRecentDocs(); - if (recentDocs) { - setLocalSelectedDocs(recentDocs); + const response = await getLocalRecentDocs(); + console.log('response'); + + if (response) { + const parsedResponse = JSON.parse(response) as Doc; + setLocalSelectedDocs(parsedResponse); } } getRecentDocs(); + console.log('cancel'); setIsError(false); setModalState('INACTIVE'); } useEffect(() => { + async function getRecentDocs() { + const response = await getLocalRecentDocs(); + + if (response) { + const parsedResponse = JSON.parse(response) as Doc; + + dispatch(setSelectedDocs(parsedResponse)); + setLocalSelectedDocs(parsedResponse); + setModalState('INACTIVE'); + } + } + async function requestDocs() { const data = await getDocs(); dispatch(setSourceDocs(data)); } - async function getRecentDocs() { - const recentDocs = await getLocalRecentDocs(); - if (recentDocs) { - dispatch(setSelectedDocs(recentDocs)); - setLocalSelectedDocs(recentDocs); - setModalState('INACTIVE'); - } - } - getRecentDocs(); requestDocs(); }, []); diff --git a/frontend/src/preferences/preferenceApi.ts b/frontend/src/preferences/preferenceApi.ts index 2aa24200..d7f99094 100644 --- a/frontend/src/preferences/preferenceApi.ts +++ b/frontend/src/preferences/preferenceApi.ts @@ -33,23 +33,17 @@ export async function getDocs(): Promise { export async function getLocalApiKey(): Promise { try { const key = localStorage.getItem('DocsGPTApiKey'); - if (key) { - return key; - } - return null; + return key; } catch (error) { console.log(error); return null; } } -export async function getLocalRecentDocs(): Promise { +export async function getLocalRecentDocs(): Promise { try { const doc = localStorage.getItem('DocsGPTRecentDocs'); - if (doc) { - return JSON.parse(doc); - } - return null; + return doc; } catch (error) { console.log(error); return null;