Save list view per list and not globally

This commit is contained in:
kolaente 2020-05-22 17:28:26 +02:00
parent 68e6b23610
commit 8592652e5b
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
6 changed files with 45 additions and 6 deletions

View file

@ -27,6 +27,7 @@
import ListModel from '../../models/list' import ListModel from '../../models/list'
import ListService from '../../services/list' import ListService from '../../services/list'
import {CURRENT_LIST} from '../../store/mutation-types' import {CURRENT_LIST} from '../../store/mutation-types'
import {getListView} from '../../helpers/saveListView'
export default { export default {
data() { data() {
@ -69,9 +70,9 @@
this.$route.name !== 'list.kanban' this.$route.name !== 'list.kanban'
) { ) {
const savedListView = localStorage.getItem('listView') const savedListView = getListView(this.$route.params.listId)
router.replace({name: savedListView ? savedListView : 'list.list', params: {id: this.$route.params.listId}}) router.replace({name: savedListView, params: {id: this.$route.params.listId}})
return return
} }

View file

@ -63,6 +63,7 @@
import GanttChart from '../../tasks/gantt-component' import GanttChart from '../../tasks/gantt-component'
import flatPickr from 'vue-flatpickr-component' import flatPickr from 'vue-flatpickr-component'
import Fancycheckbox from '../../global/fancycheckbox' import Fancycheckbox from '../../global/fancycheckbox'
import {saveListView} from '../../../helpers/saveListView'
export default { export default {
name: 'Gantt', name: 'Gantt',
@ -74,7 +75,7 @@
created() { created() {
// Save the current list view to local storage // Save the current list view to local storage
// We use local storage and not vuex here to make it persistent across reloads. // We use local storage and not vuex here to make it persistent across reloads.
localStorage.setItem('listView', this.$route.name) saveListView(this.$route.params.listId, this.$route.name)
}, },
data() { data() {
return { return {

View file

@ -199,6 +199,7 @@
import {applyDrag} from '../../../helpers/applyDrag' import {applyDrag} from '../../../helpers/applyDrag'
import {mapState} from 'vuex' import {mapState} from 'vuex'
import {LOADING} from '../../../store/mutation-types' import {LOADING} from '../../../store/mutation-types'
import {saveListView} from '../../../helpers/saveListView'
export default { export default {
name: 'Kanban', name: 'Kanban',
@ -240,7 +241,7 @@
// Save the current list view to local storage // Save the current list view to local storage
// We use local storage and not vuex here to make it persistent across reloads. // We use local storage and not vuex here to make it persistent across reloads.
localStorage.setItem('listView', this.$route.name) saveListView(this.$route.params.listId, this.$route.name)
}, },
watch: { watch: {
'$route.params.listId': 'loadBuckets', '$route.params.listId': 'loadBuckets',

View file

@ -113,6 +113,7 @@
import TaskModel from '../../../models/task' import TaskModel from '../../../models/task'
import SingleTaskInList from '../../tasks/reusable/singleTaskInList' import SingleTaskInList from '../../tasks/reusable/singleTaskInList'
import taskList from '../../tasks/helpers/taskList' import taskList from '../../tasks/helpers/taskList'
import {saveListView} from '../../../helpers/saveListView'
export default { export default {
name: 'List', name: 'List',
@ -139,7 +140,7 @@
// Save the current list view to local storage // Save the current list view to local storage
// We use local storage and not vuex here to make it persistent across reloads. // We use local storage and not vuex here to make it persistent across reloads.
localStorage.setItem('listView', this.$route.name) saveListView(this.$route.params.listId, this.$route.name)
}, },
methods: { methods: {
// This function initializes the tasks page and loads the first page of tasks // This function initializes the tasks page and loads the first page of tasks

View file

@ -154,6 +154,7 @@
import DateTableCell from '../../tasks/reusable/date-table-cell' import DateTableCell from '../../tasks/reusable/date-table-cell'
import Fancycheckbox from '../../global/fancycheckbox' import Fancycheckbox from '../../global/fancycheckbox'
import Sort from '../../tasks/reusable/sort' import Sort from '../../tasks/reusable/sort'
import {saveListView} from '../../../helpers/saveListView'
export default { export default {
name: 'Table', name: 'Table',
@ -205,7 +206,7 @@
// Save the current list view to local storage // Save the current list view to local storage
// We use local storage and not vuex here to make it persistent across reloads. // We use local storage and not vuex here to make it persistent across reloads.
localStorage.setItem('listView', this.$route.name) saveListView(this.$route.params.listId, this.$route.name)
}, },
methods: { methods: {
initTasks(page, search = '') { initTasks(page, search = '') {

View file

@ -0,0 +1,34 @@
export const saveListView = (listId, routeName) => {
const savedListViewJson = JSON.parse(localStorage.getItem('listView'))
let listView = {}
if(savedListViewJson) {
listView = savedListViewJson
}
listView[listId] = routeName
localStorage.setItem('listView', JSON.stringify(listView))
}
export const getListView = listId => {
// Remove old stored settings
const savedListView = localStorage.getItem('listView')
if(savedListView !== null && savedListView.startsWith('list.')) {
localStorage.removeItem('listView')
}
console.log('saved list view state', savedListView)
if (!savedListView) {
return 'list.list'
}
const savedListViewJson = JSON.parse(savedListView)
if(!savedListViewJson[listId]) {
return 'list.list'
}
return savedListViewJson[listId]
}