File size: 715 Bytes
25c63d0 5acf3a4 25c63d0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
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();
|