Handle theme change
This commit is contained in:
parent
6220e599cf
commit
90352503b3
|
|
@ -1,6 +1,6 @@
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useCallback, useRef, useState } from 'react'
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
import { maps } from 'hue-map'
|
import { maps } from 'hue-map'
|
||||||
import { Settings as SettingsIcon } from 'lucide-react'
|
import { Settings as SettingsIcon } from 'lucide-react'
|
||||||
|
|
@ -33,6 +33,12 @@ const Settings = () => {
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
// Use user theme preference
|
||||||
|
useEffect(() => {
|
||||||
|
document.body.classList.toggle('light', store?.theme === 'Light')
|
||||||
|
document.body.classList.toggle('dark', store?.theme === 'Dark')
|
||||||
|
}, [store?.theme])
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
@ -50,6 +56,7 @@ const Settings = () => {
|
||||||
<div onClick={e => e.stopPropagation()}>
|
<div onClick={e => e.stopPropagation()}>
|
||||||
<span className={styles.heading}>{t('options.name')}</span>
|
<span className={styles.heading}>{t('options.name')}</span>
|
||||||
|
|
||||||
|
{store && <>
|
||||||
<ToggleField
|
<ToggleField
|
||||||
label={t('options.weekStart.label')}
|
label={t('options.weekStart.label')}
|
||||||
name="weekStart"
|
name="weekStart"
|
||||||
|
|
@ -123,6 +130,7 @@ const Settings = () => {
|
||||||
value={i18n.language}
|
value={i18n.language}
|
||||||
onChange={e => i18n.changeLanguage(e.target.value).then(() => router.refresh())}
|
onChange={e => i18n.changeLanguage(e.target.value).then(() => router.refresh())}
|
||||||
/>
|
/>
|
||||||
|
</>}
|
||||||
</div>
|
</div>
|
||||||
</dialog>
|
</dialog>
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ const ToggleField = <TValue extends string>({
|
||||||
id={`${name}-${key}`}
|
id={`${name}-${key}`}
|
||||||
checked={value === key}
|
checked={value === key}
|
||||||
onChange={() => onChange(key as TValue)}
|
onChange={() => onChange(key as TValue)}
|
||||||
|
onClick={() => onChange(key as TValue)}
|
||||||
/>
|
/>
|
||||||
<label className={styles.button} htmlFor={`${name}-${key}`}>{label as React.ReactNode}</label>
|
<label className={styles.button} htmlFor={`${name}-${key}`}>{label as React.ReactNode}</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue