mirror of
https://github.com/usebruno/bruno.git
synced 2025-01-27 08:08:46 +01:00
27 lines
645 B
JavaScript
27 lines
645 B
JavaScript
|
import { createSlice } from '@reduxjs/toolkit'
|
||
|
import { getCollectionsFromIdb } from 'utils/idb';
|
||
|
|
||
|
const initialState = {
|
||
|
collections: []
|
||
|
};
|
||
|
|
||
|
export const collectionsSlice = createSlice({
|
||
|
name: 'app',
|
||
|
initialState,
|
||
|
reducers: {
|
||
|
loadCollections: (state, action) => {
|
||
|
state.collections = action.payload;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
export const { loadCollections } = collectionsSlice.actions;
|
||
|
|
||
|
export const loadCollectionsFromIdb = () => (dispatch) => {
|
||
|
getCollectionsFromIdb(window.__idb)
|
||
|
.then((collections) => dispatch(loadCollections(collections)))
|
||
|
.catch((err) => console.log(err));
|
||
|
};
|
||
|
|
||
|
export default collectionsSlice.reducer;
|