small change

This commit is contained in:
TaylorS15 2023-02-22 18:34:20 -05:00
parent 91df648767
commit 355d6e3cf2
2 changed files with 22 additions and 21 deletions

View File

@ -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();
}, []);

View File

@ -33,23 +33,17 @@ export async function getDocs(): Promise<Doc[] | null> {
export async function getLocalApiKey(): Promise<string | null> {
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<Doc | null> {
export async function getLocalRecentDocs(): Promise<string | null> {
try {
const doc = localStorage.getItem('DocsGPTRecentDocs');
if (doc) {
return JSON.parse(doc);
}
return null;
return doc;
} catch (error) {
console.log(error);
return null;