feat: improved tab behaviour while closing a tab

This commit is contained in:
Anoop M D 2022-10-14 02:12:59 +05:30
parent d49eb4df33
commit 6bb3967379

View File

@ -49,14 +49,24 @@ export const tabsSlice = createSlice({
}
},
closeTabs: (state, action) => {
const activeTab = find(state.tabs, (t) => t.uid === state.activeTabUid);
const tabUids = action.payload.tabUids || [];
state.tabs = filter(state.tabs, (t) => !tabUids.includes(t.uid));
if(state.tabs && state.tabs.length) {
// todo: closing tab needs to focus on the right adjacent tab
state.activeTabUid = last(state.tabs).uid;
} else {
state.activeTabUid = null;
if(activeTab && state.tabs.length) {
const { collectionUid } = activeTab;
const activeTabStillExists = find(state.tabs, (t) => t.uid === state.activeTabUid);
if(!activeTabStillExists) {
// attempt to load sibling tabs (based on collections) of the dead tab
const siblingTabs = filter(state.tabs, (t) => t.collectionUid === collectionUid);
if(siblingTabs && siblingTabs.length) {
state.activeTabUid = last(siblingTabs).uid;
} else {
state.activeTabUid = last(state.tabs).uid;
}
}
}
},
// todo: implement this