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. 9
      packages/nc-gui-v2/composables/useTabs.ts
  2. 4
      packages/nc-gui-v2/pages/nc/[projectId].vue

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

@ -11,9 +11,18 @@ export default () => {
const activeTab = useState<number>('activeTab', () => 0)
const addTab = (tabMeta: TabItem) => {
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 = []
}

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

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

Loading…
Cancel
Save