Thomas G. Lopes
move to csr
5acf3a4
raw
history blame
715 Bytes
import { writable } from "svelte/store";
const key = "hf_token";
function createTokenStore() {
const store = writable({ value: "", writeToLocalStorage: true, showModal: false });
function setValue(token: string) {
store.update(s => {
if (s.writeToLocalStorage) localStorage.setItem(key, JSON.stringify(token));
return { ...s, value: token, showModal: !token.length };
});
}
const storedHfToken = localStorage.getItem(key);
if (storedHfToken !== null) {
setValue(JSON.parse(storedHfToken));
}
return {
...store,
setValue,
reset() {
setValue("");
localStorage.removeItem(key);
store.update(s => ({ ...s, showModal: true }));
},
};
}
export const token = createTokenStore();