diff --git a/src/components/lists/ShowList.vue b/src/components/lists/ShowList.vue index b713dac51..a76dea102 100644 --- a/src/components/lists/ShowList.vue +++ b/src/components/lists/ShowList.vue @@ -27,6 +27,7 @@ import ListModel from '../../models/list' import ListService from '../../services/list' import {CURRENT_LIST} from '../../store/mutation-types' + import {getListView} from '../../helpers/saveListView' export default { data() { @@ -69,9 +70,9 @@ 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 } diff --git a/src/components/lists/views/Gantt.vue b/src/components/lists/views/Gantt.vue index d0a170f91..b684c7c4c 100644 --- a/src/components/lists/views/Gantt.vue +++ b/src/components/lists/views/Gantt.vue @@ -63,6 +63,7 @@ import GanttChart from '../../tasks/gantt-component' import flatPickr from 'vue-flatpickr-component' import Fancycheckbox from '../../global/fancycheckbox' + import {saveListView} from '../../../helpers/saveListView' export default { name: 'Gantt', @@ -74,7 +75,7 @@ created() { // Save the current list view to local storage // 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() { return { diff --git a/src/components/lists/views/Kanban.vue b/src/components/lists/views/Kanban.vue index bcac50615..2aabc2aac 100644 --- a/src/components/lists/views/Kanban.vue +++ b/src/components/lists/views/Kanban.vue @@ -199,6 +199,7 @@ import {applyDrag} from '../../../helpers/applyDrag' import {mapState} from 'vuex' import {LOADING} from '../../../store/mutation-types' + import {saveListView} from '../../../helpers/saveListView' export default { name: 'Kanban', @@ -240,7 +241,7 @@ // Save the current list view to local storage // 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: { '$route.params.listId': 'loadBuckets', diff --git a/src/components/lists/views/List.vue b/src/components/lists/views/List.vue index 6c86e505c..5aab66787 100644 --- a/src/components/lists/views/List.vue +++ b/src/components/lists/views/List.vue @@ -113,6 +113,7 @@ import TaskModel from '../../../models/task' import SingleTaskInList from '../../tasks/reusable/singleTaskInList' import taskList from '../../tasks/helpers/taskList' + import {saveListView} from '../../../helpers/saveListView' export default { name: 'List', @@ -139,7 +140,7 @@ // Save the current list view to local storage // 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: { // This function initializes the tasks page and loads the first page of tasks diff --git a/src/components/lists/views/Table.vue b/src/components/lists/views/Table.vue index 4c1c117ee..5feccee45 100644 --- a/src/components/lists/views/Table.vue +++ b/src/components/lists/views/Table.vue @@ -154,6 +154,7 @@ import DateTableCell from '../../tasks/reusable/date-table-cell' import Fancycheckbox from '../../global/fancycheckbox' import Sort from '../../tasks/reusable/sort' + import {saveListView} from '../../../helpers/saveListView' export default { name: 'Table', @@ -205,7 +206,7 @@ // Save the current list view to local storage // 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: { initTasks(page, search = '') { diff --git a/src/helpers/saveListView.js b/src/helpers/saveListView.js new file mode 100644 index 000000000..025f17045 --- /dev/null +++ b/src/helpers/saveListView.js @@ -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] +} \ No newline at end of file