mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-09 06:55:03 +00:00
refactor: redux migration - idb readiness
This commit is contained in:
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;
|
||||
Reference in New Issue
Block a user