2021-12-10 18:04:07 +01:00
|
|
|
// Save the current list view to local storage
|
|
|
|
// We use local storage and not vuex here to make it persistent across reloads.
|
2020-05-22 17:28:26 +02:00
|
|
|
export const saveListView = (listId, routeName) => {
|
2021-08-06 23:34:37 +02:00
|
|
|
if (routeName.includes('settings.')) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!listId) {
|
2021-01-30 17:17:04 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-05-29 16:33:57 +02:00
|
|
|
const savedListView = localStorage.getItem('listView')
|
|
|
|
let savedListViewJson = false
|
|
|
|
if (savedListView !== null) {
|
|
|
|
savedListViewJson = JSON.parse(savedListView)
|
|
|
|
}
|
2020-05-22 17:28:26 +02:00
|
|
|
|
|
|
|
let listView = {}
|
2020-09-05 22:35:52 +02:00
|
|
|
if (savedListViewJson) {
|
2020-05-22 17:28:26 +02:00
|
|
|
listView = savedListViewJson
|
|
|
|
}
|
|
|
|
|
|
|
|
listView[listId] = routeName
|
|
|
|
localStorage.setItem('listView', JSON.stringify(listView))
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getListView = listId => {
|
|
|
|
// Remove old stored settings
|
|
|
|
const savedListView = localStorage.getItem('listView')
|
2020-09-05 22:35:52 +02:00
|
|
|
if (savedListView !== null && savedListView.startsWith('list.')) {
|
2020-05-22 17:28:26 +02:00
|
|
|
localStorage.removeItem('listView')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!savedListView) {
|
|
|
|
return 'list.list'
|
|
|
|
}
|
|
|
|
|
|
|
|
const savedListViewJson = JSON.parse(savedListView)
|
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
if (!savedListViewJson[listId]) {
|
2020-05-22 17:28:26 +02:00
|
|
|
return 'list.list'
|
|
|
|
}
|
|
|
|
|
|
|
|
return savedListViewJson[listId]
|
|
|
|
}
|