Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Stores
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Jul 15, 2022
1 parent c6668a1 commit 2005953
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
27 changes: 27 additions & 0 deletions interface/stores/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { writable, get } from "svelte/store"

export const settings = writable(
localStorage.settings
? JSON.parse(localStorage.settings)
: {
security: {
requireAuthentication: null,
password: null,
key: null,
},
}
)

settings.subscribe((data) => {
console.log("Settings changed: ", data)

localStorage.setItem("settings", JSON.stringify(data))
})

export const getSettings = (): LibSettings => {
return get(settings)
}

export const setSettings = (newSettings: LibSettings) => {
settings.set(newSettings)
}
25 changes: 22 additions & 3 deletions interface/stores/state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
import { writable } from "svelte/store"
import { writable, get } from "svelte/store"

export const state = writable({
importData: null,
export const state = writable(
sessionStorage.state
? JSON.parse(sessionStorage.state)
: {
authenticated: false,
importData: null,
}
)

state.subscribe((data) => {
console.log("State changed: ", data)

sessionStorage.setItem("state", JSON.stringify(data))
})

export const getState = (): LibState => {
return get(state)
}

export const setState = (newState: LibState) => {
state.set(newState)
}

0 comments on commit 2005953

Please sign in to comment.