mirror of
https://github.com/ManInDark/HabitTrove.git
synced 2026-01-20 22:24:28 +01:00
24 lines
591 B
TypeScript
24 lines
591 B
TypeScript
'use client'
|
|
|
|
import { useEffect, useState } from 'react'
|
|
import { getDefaultSettings, Settings } from '@/lib/types'
|
|
import { loadSettings, saveSettings } from '@/app/actions/data'
|
|
|
|
export function useSettings() {
|
|
const [settings, setSettings] = useState<Settings>(getDefaultSettings()) // TODO: do we need to initialize the settings here?
|
|
|
|
useEffect(() => {
|
|
loadSettings().then(setSettings)
|
|
}, [])
|
|
|
|
const updateSettings = async (newSettings: Settings) => {
|
|
await saveSettings(newSettings)
|
|
setSettings(newSettings)
|
|
}
|
|
|
|
return {
|
|
settings,
|
|
updateSettings,
|
|
}
|
|
}
|