Browse Source

fix: clear tab if switching project, navigate to existing tab if found

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/2716/head
Pranav C 2 years ago
parent
commit
cf778cc216
  1. 13
      packages/nc-gui-v2/composables/useTabs.ts
  2. 8
      packages/nc-gui-v2/pages/nc/[projectId].vue

13
packages/nc-gui-v2/composables/useTabs.ts

@ -11,8 +11,17 @@ export default () => {
const activeTab = useState<number>('activeTab', () => 0)
const addTab = (tabMeta: TabItem) => {
tabs.value = [...(tabs.value || []), tabMeta]
activeTab.value = tabs.value.length - 1
const tabIndex = tabs.value.findIndex(tab => tab.id === tabMeta.id)
// if tab already found make it active
if(tabIndex>-1){
activeTab.value = tabIndex
}
// if tab not found add it
else {
tabs.value = [...(tabs.value || []), tabMeta]
activeTab.value = tabs.value.length - 1
}
}
const clearTabs = () => {
tabs.value = []

8
packages/nc-gui-v2/pages/nc/[projectId].vue

@ -15,10 +15,12 @@ onMounted(async () => {
watch(
() => route.params.projectId,
async (newVal, oldVal) => {
if (newVal && newVal !== oldVal) {
if (newVal !== oldVal) {
clearTabs()
await loadProject(newVal as string)
await loadTables()
if(newVal) {
await loadProject(newVal as string)
await loadTables()
}
}
},
)

Loading…
Cancel
Save