fix: move local storage list view to router

This commit is contained in:
Dominik Pschenitschni 2021-12-10 18:04:07 +01:00
parent 5916a44724
commit 76f4cca5fe
No known key found for this signature in database
GPG key ID: B257AC0149F43A77
3 changed files with 16 additions and 23 deletions

View file

@ -1,3 +1,5 @@
// Save the current list view to local storage
// We use local storage and not vuex here to make it persistent across reloads.
export const saveListView = (listId, routeName) => { export const saveListView = (listId, routeName) => {
if (routeName.includes('settings.')) { if (routeName.includes('settings.')) {
return return

View file

@ -2,7 +2,7 @@ import { createRouter, createWebHistory, RouteLocation } from 'vue-router'
import {saveLastVisited} from '@/helpers/saveLastVisited' import {saveLastVisited} from '@/helpers/saveLastVisited'
import {store} from '@/store' import {store} from '@/store'
import {getListView} from '@/helpers/saveListView' import {saveListView, getListView} from '@/helpers/saveListView'
import HomeComponent from '../views/Home' import HomeComponent from '../views/Home'
import NotFoundComponent from '../views/404' import NotFoundComponent from '../views/404'
@ -244,9 +244,7 @@ const router = createRouter({
path: '/tasks/:id', path: '/tasks/:id',
name: 'task.detail', name: 'task.detail',
component: TaskDetailViewModal, component: TaskDetailViewModal,
props: route => ({ props: route => ({ taskId: parseInt(route.params.id) }),
taskId: parseInt(route.params.id),
}),
}, },
{ {
path: '/tasks/by/upcoming', path: '/tasks/by/upcoming',
@ -328,14 +326,16 @@ const router = createRouter({
{ {
path: '/lists/:listId', path: '/lists/:listId',
name: 'list.index', name: 'list.index',
beforeEnter(to) { redirect(to) {
// Redirect the user to list view by default // Redirect the user to list view by default
const savedListView = getListView(to.params.listId) const savedListView = getListView(to.params.listId)
console.debug('Replaced list view with', savedListView) console.debug('Replaced list view with', savedListView)
return { return {
name: savedListView, name: router.hasRoute(savedListView)
? savedListView
: 'list.list',
params: {listId: to.params.listId}, params: {listId: to.params.listId},
} }
}, },
@ -344,33 +344,29 @@ const router = createRouter({
path: '/lists/:listId/list', path: '/lists/:listId/list',
name: 'list.list', name: 'list.list',
component: ListList, component: ListList,
props: route => ({ beforeEnter: (to) => saveListView(to.params.listId, to.name),
listId: parseInt(route.params.listId), props: route => ({ listId: parseInt(route.params.listId) }),
}),
}, },
{ {
path: '/lists/:listId/gantt', path: '/lists/:listId/gantt',
name: 'list.gantt', name: 'list.gantt',
component: ListGantt, component: ListGantt,
props: route => ({ beforeEnter: (to) => saveListView(to.params.listId, to.name),
listId: parseInt(route.params.listId), props: route => ({ listId: parseInt(route.params.listId) }),
}),
}, },
{ {
path: '/lists/:listId/table', path: '/lists/:listId/table',
name: 'list.table', name: 'list.table',
component: ListTable, component: ListTable,
props: route => ({ beforeEnter: (to) => saveListView(to.params.listId, to.name),
listId: parseInt(route.params.listId), props: route => ({ listId: parseInt(route.params.listId) }),
}),
}, },
{ {
path: '/lists/:listId/kanban', path: '/lists/:listId/kanban',
name: 'list.kanban', name: 'list.kanban',
component: ListKanban, component: ListKanban,
props: route => ({ beforeEnter: (to) => saveListView(to.params.listId, to.name),
listId: parseInt(route.params.listId), props: route => ({ listId: parseInt(route.params.listId) }),
}),
}, },
{ {
path: '/teams', path: '/teams',

View file

@ -59,7 +59,6 @@ import {store} from '@/store'
import {CURRENT_LIST} from '@/store/mutation-types' import {CURRENT_LIST} from '@/store/mutation-types'
import {getListTitle} from '@/helpers/getListTitle' import {getListTitle} from '@/helpers/getListTitle'
import {saveListView} from '@/helpers/saveListView'
import {saveListToHistory} from '@/modules/listHistory' import {saveListToHistory} from '@/modules/listHistory'
import { useTitle } from '@/composables/useTitle' import { useTitle } from '@/composables/useTitle'
@ -76,10 +75,6 @@ const props = defineProps({
const route = useRoute() const route = useRoute()
// Save the current list view to local storage
// We use local storage and not vuex here to make it persistent across reloads.
saveListView(props.listId, props.viewName)
const listService = shallowRef(new ListService()) const listService = shallowRef(new ListService())
const loadedListId = ref(0) const loadedListId = ref(0)