mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-26 00:16:51 +00:00
Fix #178 ability to restore last backup
This commit is contained in:
@@ -12,6 +12,7 @@ export namespace Store {
|
||||
export const ID_HIGHLIGHTING = 'output_highlighting'
|
||||
export const ID_SOUNDS_VERSION = 'minecraft_sounds_version'
|
||||
export const ID_PROJECTS = 'misode_projects'
|
||||
export const ID_BACKUPS = 'misode_generator_backups'
|
||||
|
||||
export function getLanguage() {
|
||||
return localStorage.getItem(ID_LANGUAGE) ?? 'en'
|
||||
@@ -53,6 +54,11 @@ export namespace Store {
|
||||
return [DRAFT_PROJECT]
|
||||
}
|
||||
|
||||
export function getBackup(id: string): object | undefined {
|
||||
const backups = JSON.parse(localStorage.getItem(ID_BACKUPS) ?? '{}')
|
||||
return backups[id]
|
||||
}
|
||||
|
||||
export function setLanguage(language: string | undefined) {
|
||||
if (language) localStorage.setItem(ID_LANGUAGE, language)
|
||||
}
|
||||
@@ -84,4 +90,14 @@ export namespace Store {
|
||||
export function setProjects(projects: Project[] | undefined) {
|
||||
if (projects) localStorage.setItem(ID_PROJECTS, JSON.stringify(projects))
|
||||
}
|
||||
|
||||
export function setBackup(id: string, data: object | undefined) {
|
||||
const backups = JSON.parse(localStorage.getItem(ID_BACKUPS) ?? '{}')
|
||||
if (data === undefined) {
|
||||
delete backups[id]
|
||||
} else {
|
||||
backups[id] = data
|
||||
}
|
||||
localStorage.setItem(ID_BACKUPS, JSON.stringify(backups))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user