Storing imported tracks in local "forage".

This commit is contained in:
vdv committed 2022-09-23 22:34:59 +02:00
1 parent bb2130793d
commit d0bac1c509
9 files changed
+1276 -53

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
import react, { useEffect, useState } from 'react';
import * as CordovaSQLiteDriver from 'localforage-cordovasqlitedriver';
import localforage from 'localforage';
const initialDbContext = { ready: false, tracksStore: localforage };
export const DbContext = react.createContext(initialDbContext);
const DbContextProvider: react.FC<{
children?: JSX.Element;
}> = (props: { children?: JSX.Element }) => {
const [store, setStore] = useState(localforage);
const [ready, setReady] = useState(false);
useEffect(() => {
const config = {
name: 'dyomedea',
driver: [
CordovaSQLiteDriver._driver,
localforage.INDEXEDDB,
localforage.WEBSQL,
localforage.LOCALSTORAGE,
],
};
const newStore = localforage.createInstance({
storeName: 'tracks',
...config,
});
setStore(newStore);
setReady(true);
}, []);
return (
<DbContext.Provider value={{ ready, tracksStore: store }}>
{props.children}
</DbContext.Provider>
);
};
export default DbContextProvider;