mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-25 09:23:17 +01:00
refactor: redux migration - idb readiness
This commit is contained in:
parent
b46d3c5a9e
commit
907f44d351
@ -1,6 +1,7 @@
|
|||||||
import { StoreProvider } from 'providers/Store';
|
import { StoreProvider } from 'providers/Store';
|
||||||
import { HotkeysProvider } from 'providers/Hotkeys';
|
import { HotkeysProvider } from 'providers/Hotkeys';
|
||||||
import { AuthProvider } from 'providers/Auth';
|
import { AuthProvider } from 'providers/Auth';
|
||||||
|
import { AppProvider } from 'providers/App';
|
||||||
import ReduxStore from 'providers/ReduxStore';
|
import ReduxStore from 'providers/ReduxStore';
|
||||||
import { Provider } from 'react-redux';
|
import { Provider } from 'react-redux';
|
||||||
|
|
||||||
@ -25,11 +26,13 @@ function MyApp({ Component, pageProps }) {
|
|||||||
<SafeHydrate>
|
<SafeHydrate>
|
||||||
<AuthProvider>
|
<AuthProvider>
|
||||||
<Provider store={ReduxStore}>
|
<Provider store={ReduxStore}>
|
||||||
|
<AppProvider>
|
||||||
<StoreProvider>
|
<StoreProvider>
|
||||||
<HotkeysProvider>
|
<HotkeysProvider>
|
||||||
<Component {...pageProps} />
|
<Component {...pageProps} />
|
||||||
</HotkeysProvider>
|
</HotkeysProvider>
|
||||||
</StoreProvider>
|
</StoreProvider>
|
||||||
|
</AppProvider>
|
||||||
</Provider>
|
</Provider>
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
</SafeHydrate>
|
</SafeHydrate>
|
||||||
|
17
renderer/providers/App/index.js
Normal file
17
renderer/providers/App/index.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import useIdb from './useIdb';
|
||||||
|
|
||||||
|
export const AppContext = React.createContext();
|
||||||
|
|
||||||
|
export const AppProvider = props => {
|
||||||
|
// boot idb
|
||||||
|
useIdb();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AppContext.Provider {...props} value='appProvider'>
|
||||||
|
{props.children}
|
||||||
|
</AppContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AppProvider;
|
30
renderer/providers/App/useIdb.js
Normal file
30
renderer/providers/App/useIdb.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import { openDB } from 'idb';
|
||||||
|
import { idbConnectionReady } from 'providers/ReduxStore/slices/app'
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
|
|
||||||
|
const useIdb = () => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let dbName = `grafnode`;
|
||||||
|
let connection = openDB(dbName, 1, {
|
||||||
|
upgrade(db, oldVersion, newVersion, transaction) {
|
||||||
|
switch(oldVersion) {
|
||||||
|
case 0:
|
||||||
|
const collectionStore = db.createObjectStore('collection', { keyPath: 'uid' });
|
||||||
|
collectionStore.createIndex('transactionIdIndex', 'transaction_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
connection
|
||||||
|
.then(() => {
|
||||||
|
window.__idb = connection;
|
||||||
|
dispatch(idbConnectionReady());
|
||||||
|
})
|
||||||
|
.catch((err) => console.log(err));
|
||||||
|
}, []);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useIdb;
|
@ -1,6 +1,7 @@
|
|||||||
import { createSlice } from '@reduxjs/toolkit'
|
import { createSlice } from '@reduxjs/toolkit'
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
|
idbConnectionReady: false,
|
||||||
leftMenuBarOpen: true,
|
leftMenuBarOpen: true,
|
||||||
leftSidebarWidth: 270
|
leftSidebarWidth: 270
|
||||||
};
|
};
|
||||||
@ -12,10 +13,13 @@ export const appSlice = createSlice({
|
|||||||
toggleLeftMenuBar: (state) => {
|
toggleLeftMenuBar: (state) => {
|
||||||
state.leftMenuBarOpen = !state.leftMenuBarOpen;
|
state.leftMenuBarOpen = !state.leftMenuBarOpen;
|
||||||
state.leftSidebarWidth = state.leftMenuBarOpen ? 270 : 222;
|
state.leftSidebarWidth = state.leftMenuBarOpen ? 270 : 222;
|
||||||
|
},
|
||||||
|
idbConnectionReady: (state) => {
|
||||||
|
state.idbConnectionReady = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const { toggleLeftMenuBar } = appSlice.actions;
|
export const { toggleLeftMenuBar, idbConnectionReady } = appSlice.actions;
|
||||||
|
|
||||||
export default appSlice.reducer;
|
export default appSlice.reducer;
|
||||||
|
Loading…
Reference in New Issue
Block a user