fix(views): correctly save and retrieve last accessed project views
This commit is contained in:
parent
b65d05ec3d
commit
b0ad087a36
@ -33,14 +33,14 @@ describe('Projects', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('Should redirect to a specific project view after visited', () => {
|
it('Should redirect to a specific project view after visited', () => {
|
||||||
cy.intercept(Cypress.env('API_URL') + '/projects/*/buckets*').as('loadBuckets')
|
cy.intercept(Cypress.env('API_URL') + '/projects/*/views/*/tasks**').as('loadBuckets')
|
||||||
cy.visit('/projects/1/kanban')
|
cy.visit('/projects/1/4')
|
||||||
cy.url()
|
cy.url()
|
||||||
.should('contain', '/projects/1/kanban')
|
.should('contain', '/projects/1/4')
|
||||||
cy.wait('@loadBuckets')
|
cy.wait('@loadBuckets')
|
||||||
cy.visit('/projects/1')
|
cy.visit('/projects/1')
|
||||||
cy.url()
|
cy.url()
|
||||||
.should('contain', '/projects/1/kanban')
|
.should('contain', '/projects/1/4')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should rename the project in all places', () => {
|
it('Should rename the project in all places', () => {
|
||||||
|
@ -30,19 +30,15 @@ export function saveProjectView(projectId: IProject['id'], viewId: number) {
|
|||||||
localStorage.setItem(SETTINGS_KEY_PROJECT_VIEW, JSON.stringify(projectViewSettings))
|
localStorage.setItem(SETTINGS_KEY_PROJECT_VIEW, JSON.stringify(projectViewSettings))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getProjectView = (projectId: IProject['id']) => {
|
export function getProjectViewId(projectId: IProject['id']): number {
|
||||||
try {
|
|
||||||
const projectViewSettingsString = localStorage.getItem(SETTINGS_KEY_PROJECT_VIEW)
|
const projectViewSettingsString = localStorage.getItem(SETTINGS_KEY_PROJECT_VIEW)
|
||||||
if (!projectViewSettingsString) {
|
if (!projectViewSettingsString) {
|
||||||
throw new Error()
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const projectViewSettings = JSON.parse(projectViewSettingsString) as ProjectViewSettings
|
const projectViewSettings = JSON.parse(projectViewSettingsString) as ProjectViewSettings
|
||||||
if (!router.hasRoute(projectViewSettings[projectId])) {
|
if (isNaN(projectViewSettings[projectId])) {
|
||||||
throw new Error()
|
return 0
|
||||||
}
|
}
|
||||||
return projectViewSettings[projectId]
|
return projectViewSettings[projectId]
|
||||||
} catch (e) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -2,7 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router'
|
|||||||
import type { RouteLocation } from 'vue-router'
|
import type { RouteLocation } from 'vue-router'
|
||||||
import {saveLastVisited} from '@/helpers/saveLastVisited'
|
import {saveLastVisited} from '@/helpers/saveLastVisited'
|
||||||
|
|
||||||
import {saveProjectView, getProjectView} from '@/helpers/projectView'
|
import {saveProjectView, getProjectViewId} from '@/helpers/projectView'
|
||||||
import {parseDateOrString} from '@/helpers/time/parseDateOrString'
|
import {parseDateOrString} from '@/helpers/time/parseDateOrString'
|
||||||
import {getNextWeekDate} from '@/helpers/time/getNextWeekDate'
|
import {getNextWeekDate} from '@/helpers/time/getNextWeekDate'
|
||||||
import {LINK_SHARE_HASH_PREFIX} from '@/constants/linkShareHash'
|
import {LINK_SHARE_HASH_PREFIX} from '@/constants/linkShareHash'
|
||||||
@ -347,7 +347,8 @@ const router = createRouter({
|
|||||||
path: '/projects/:projectId',
|
path: '/projects/:projectId',
|
||||||
name: 'project.index',
|
name: 'project.index',
|
||||||
redirect(to) {
|
redirect(to) {
|
||||||
const viewId = getProjectView(Number(to.params.projectId as string))
|
const viewId = getProjectViewId(Number(to.params.projectId as string))
|
||||||
|
console.log(viewId)
|
||||||
|
|
||||||
if (viewId) {
|
if (viewId) {
|
||||||
console.debug('Replaced list view with', viewId)
|
console.debug('Replaced list view with', viewId)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user