storing api key and recent source docs locally

This commit is contained in:
TaylorS15
2023-02-22 09:12:55 -05:00
parent 13841c7162
commit 907c4f8c4b
6 changed files with 124 additions and 41 deletions

View File

@@ -1,7 +1,8 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { useDispatch } from 'react-redux';
import { ActiveState } from '../models/misc';
import { setApiKey } from './preferenceSlice';
import { getLocalApiKey, setLocalApiKey } from './preferenceApi';
export default function APIKeyModal({
modalState,
@@ -20,19 +21,39 @@ export default function APIKeyModal({
if (key.length <= 1) {
setIsError(true);
} else {
setLocalApiKey(key);
dispatch(setApiKey(key));
setModalState('INACTIVE');
setKey('');
setIsError(false);
}
}
function handleCancel() {
setKey('');
async function getApiKey() {
const localKey = await getLocalApiKey();
if (localKey) {
setKey(localKey);
}
}
getApiKey();
setIsError(false);
setModalState('INACTIVE');
}
useEffect(() => {
async function getApiKey() {
const localKey = await getLocalApiKey();
if (localKey) {
dispatch(setApiKey(localKey));
setKey(localKey);
setModalState('INACTIVE');
}
}
getApiKey();
}, []);
return (
<div
className={`${