store settings in localstorage
This commit is contained in:
24
src/composables/useSettings.ts
Normal file
24
src/composables/useSettings.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { notesSourceValues } from '@/composables/useNotes'
|
||||
|
||||
interface Settings {
|
||||
preferredNotesSource: notesSourceValues
|
||||
}
|
||||
|
||||
export const preferredNotesSource = ref<notesSourceValues>(null)
|
||||
|
||||
const updateSettings = () => {
|
||||
const settings: Settings = {
|
||||
preferredNotesSource: preferredNotesSource.value
|
||||
}
|
||||
localStorage.setItem('settings', JSON.stringify(settings))
|
||||
}
|
||||
|
||||
export const initializeSettings = () => {
|
||||
watch([preferredNotesSource], () => updateSettings())
|
||||
try {
|
||||
const settings: Settings = JSON.parse(localStorage.getItem('settings') || '{}')
|
||||
preferredNotesSource.value = settings.preferredNotesSource
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user