chore: add const for project settings
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
kolaente 2023-01-18 14:05:52 +01:00
parent ac0b4dcf36
commit c8ceefe12e
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 8 additions and 5 deletions

View File

@ -3,6 +3,7 @@ import type { IProject } from '@/modelTypes/IProject'
type ProjectView = Record<IProject['id'], string> type ProjectView = Record<IProject['id'], string>
const DEFAULT_PROJECT_VIEW = 'project.list' as const const DEFAULT_PROJECT_VIEW = 'project.list' as const
const PROJECT_VIEW_SETTINGS_KEY = 'projectView'
/** /**
* Save the current project view to local storage * Save the current project view to local storage
@ -17,7 +18,7 @@ export function saveProjectView(projectId: IProject['id'], routeName: string) {
} }
// We use local storage and not the store here to make it persistent across reloads. // We use local storage and not the store here to make it persistent across reloads.
const savedProjectView = localStorage.getItem('projectView') const savedProjectView = localStorage.getItem(PROJECT_VIEW_SETTINGS_KEY)
let savedProjectViewJson: ProjectView | false = false let savedProjectViewJson: ProjectView | false = false
if (savedProjectView !== null) { if (savedProjectView !== null) {
savedProjectViewJson = JSON.parse(savedProjectView) as ProjectView savedProjectViewJson = JSON.parse(savedProjectView) as ProjectView
@ -29,21 +30,23 @@ export function saveProjectView(projectId: IProject['id'], routeName: string) {
} }
projectView[projectId] = routeName projectView[projectId] = routeName
localStorage.setItem('projectView', JSON.stringify(projectView)) localStorage.setItem(PROJECT_VIEW_SETTINGS_KEY, JSON.stringify(projectView))
} }
export const getProjectView = (projectId: IProject['id']) => { export const getProjectView = (projectId: IProject['id']) => {
// Migrate old setting over // Migrate old setting over
// TODO: remove when 1.0 release
const oldListViewSettings = localStorage.getItem('listView') const oldListViewSettings = localStorage.getItem('listView')
if (oldListViewSettings !== null) { if (oldListViewSettings !== null) {
localStorage.setItem('projectView', oldListViewSettings) localStorage.setItem(PROJECT_VIEW_SETTINGS_KEY, oldListViewSettings)
localStorage.removeItem('listView') localStorage.removeItem('listView')
} }
// Remove old stored settings // Remove old stored settings
const savedProjectView = localStorage.getItem('projectView') // TODO: remove when 1.0 release
const savedProjectView = localStorage.getItem(PROJECT_VIEW_SETTINGS_KEY)
if (savedProjectView !== null && savedProjectView.startsWith('project.')) { if (savedProjectView !== null && savedProjectView.startsWith('project.')) {
localStorage.removeItem('projectView') localStorage.removeItem(PROJECT_VIEW_SETTINGS_KEY)
} }
if (!savedProjectView) { if (!savedProjectView) {