mirror of
https://github.com/usebruno/bruno.git
synced 2024-12-25 08:09:17 +01:00
feat: persist active workspace in local storage
This commit is contained in:
parent
2efc11ff6b
commit
ecc2252e84
@ -1,7 +1,9 @@
|
||||
import { createSlice } from '@reduxjs/toolkit';
|
||||
import find from 'lodash/find';
|
||||
import map from 'lodash/map';
|
||||
import filter from 'lodash/filter';
|
||||
import { findCollectionInWorkspace } from 'utils/workspaces';
|
||||
import cache from 'utils/common/cache';
|
||||
|
||||
const initialState = {
|
||||
workspaces: [],
|
||||
@ -16,11 +18,19 @@ export const workspacesSlice = createSlice({
|
||||
state.workspaces = action.payload.workspaces;
|
||||
|
||||
if(state.workspaces && state.workspaces.length) {
|
||||
state.activeWorkspaceUid = state.workspaces[0].uid;
|
||||
const workspaceUids = map(state.workspaces, (w) => w.uid);
|
||||
const activeWorkspaceUid = cache.getActiveWorkspaceUid();
|
||||
if(activeWorkspaceUid && workspaceUids.includes(activeWorkspaceUid)) {
|
||||
state.activeWorkspaceUid = activeWorkspaceUid;
|
||||
} else {
|
||||
state.activeWorkspaceUid = state.workspaces[0].uid;
|
||||
cache.setActiveWorkspaceUid(state.activeWorkspaceUid);
|
||||
}
|
||||
}
|
||||
},
|
||||
selectWorkspace: (state, action) => {
|
||||
state.activeWorkspaceUid = action.payload.workspaceUid;
|
||||
cache.setActiveWorkspaceUid(state.activeWorkspaceUid);
|
||||
},
|
||||
renameWorkspace: (state, action) => {
|
||||
const { name, uid } = action.payload;
|
||||
|
18
packages/bruno-app/src/utils/common/cache.js
Normal file
18
packages/bruno-app/src/utils/common/cache.js
Normal file
@ -0,0 +1,18 @@
|
||||
class Cache {
|
||||
get(key) {
|
||||
return window.localStorage.getItem(key);
|
||||
}
|
||||
set(key, val) {
|
||||
window.localStorage.setItem(key, val);
|
||||
}
|
||||
|
||||
getActiveWorkspaceUid() {
|
||||
return this.get('bruno.activeWorkspaceUid');
|
||||
}
|
||||
|
||||
setActiveWorkspaceUid(workspaceUid) {
|
||||
this.set('bruno.activeWorkspaceUid', workspaceUid);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = new Cache();;
|
Loading…
Reference in New Issue
Block a user