Skip to content

Commit

Permalink
fix: use router instead of window.location to set hash
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik committed Sep 28, 2024
1 parent 2f58da9 commit 6be8329
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 4 additions & 2 deletions frontend/src/composables/useActiveTabManager.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { useRoute, useRouter } from 'vue-router'
import { useDebounceFn, useStorage } from '@vueuse/core'

export function useActiveTabManager(tabs, storageKey) {
const activieTab = useStorage(storageKey, 'activity')
const route = useRoute()
const router = useRouter()

const preserveLastVisitedTab = useDebounceFn((tabName) => {
activieTab.value = tabName.toLowerCase()
}, 300)

function setActiveTabInUrl(tabName) {
window.location.hash = '#' + tabName.toLowerCase()
let hash = '#' + tabName.toLowerCase()
router.push({ ...route, hash })
}

function getActiveTabFromUrl() {
Expand Down
11 changes: 5 additions & 6 deletions frontend/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,12 @@ router.beforeEach(async (to, from, next) => {
window.location.href = '/login?redirect-to=/crm'
} else if (to.matched.length === 0) {
next({ name: 'Invalid Page' })
} else if (['Deal', 'Lead'].includes(to.name) && !to.hash) {
let storageKey = to.name === 'Deal' ? 'lastDealTab' : 'lastLeadTab'
const activeTab = localStorage.getItem(storageKey) || 'activity'
const hash = '#' + activeTab
next({ ...to, hash })
} else {
if (['Deal', 'Lead'].includes(to.name) && !to.hash) {
let storageKey = to.name === 'Deal' ? 'lastDealTab' : 'lastLeadTab'
const activeTab = localStorage.getItem(storageKey) || 'activity'
const hash = '#' + activeTab
next({ ...to, hash })
}
next()
}
})
Expand Down

0 comments on commit 6be8329

Please sign in to comment.