Files
contexted-v3/src/composables/useSettings.ts
2023-05-25 00:11:18 +02:00

25 lines
698 B
TypeScript

import type { notesSourceValues } from '@/composables/useNotes'
interface Settings {
preferredNotesSource: notesSourceValues | null
}
export const preferredNotesSource = ref<notesSourceValues | null>(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)
}
}