quivr/frontend/lib/context/BrainProvider/helpers/brainLocalStorage.ts

16 lines
460 B
TypeScript
Raw Normal View History

import { Brain } from "../types";
const BRAIN_LOCAL_STORAGE_KEY = "userBrains";
2023-06-28 20:39:27 +03:00
export const saveBrainInLocalStorage = (brain: Brain): void => {
localStorage.setItem(BRAIN_LOCAL_STORAGE_KEY, JSON.stringify(brain));
};
export const getBrainFromLocalStorage = (): Brain | undefined => {
const persistedBrain = localStorage.getItem(BRAIN_LOCAL_STORAGE_KEY);
if (persistedBrain === null) {
return;
}
return JSON.parse(persistedBrain) as Brain;
};