Storing imported tracks in local "forage".
This commit is contained in:
1 parent
bb2130793d
commit
d0bac1c509
9 files changed
+1276
-53
No files matched your search
@@ -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;
|
||||
Reference in new issue
Block a user