2021-06-18 12:57:08 -04:00
|
|
|
import { store } from ".";
|
|
|
|
import localForage from "localforage";
|
2021-06-18 14:25:33 -04:00
|
|
|
import { Provider } from "react-redux";
|
2021-06-18 12:57:08 -04:00
|
|
|
import { Children } from "../types/Preact";
|
|
|
|
import { useEffect, useState } from "preact/hooks";
|
|
|
|
|
|
|
|
async function loadState() {
|
|
|
|
const state = await localForage.getItem("state");
|
|
|
|
if (state) {
|
|
|
|
store.dispatch({ type: "__INIT", state });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Props {
|
2021-06-18 14:25:33 -04:00
|
|
|
children: Children;
|
2021-06-18 12:57:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function State(props: Props) {
|
|
|
|
const [loaded, setLoaded] = useState(false);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
loadState().then(() => setLoaded(true));
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (!loaded) return null;
|
2021-06-18 14:25:33 -04:00
|
|
|
|
|
|
|
return <Provider store={store}>{props.children}</Provider>;
|
2021-06-18 12:57:08 -04:00
|
|
|
}
|