mirror of
https://github.com/ManInDark/HabitTrove.git
synced 2026-01-21 06:34:30 +01:00
Added jotai (#14)
* Added jotai * cache settings by using jotai state * use hydrateAtom with SSR * remove useSettings * fix test
This commit is contained in:
@@ -2,14 +2,17 @@
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { DateTime } from 'luxon'
|
||||
import { d2s } from '@/lib/utils'
|
||||
import { d2s, getNow } from '@/lib/utils'
|
||||
import { useAtom } from 'jotai'
|
||||
import { settingsAtom } from '@/lib/atoms'
|
||||
|
||||
interface DynamicTimeProps {
|
||||
timezone: string
|
||||
}
|
||||
|
||||
export function DynamicTime({ timezone }: DynamicTimeProps) {
|
||||
const [time, setTime] = useState(DateTime.now().setZone(timezone))
|
||||
export function DynamicTime() {
|
||||
const [settings] = useAtom(settingsAtom)
|
||||
const [time, setTime] = useState<DateTime>(getNow({ timezone: settings.system.timezone }))
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setInterval(() => {
|
||||
@@ -21,7 +24,7 @@ export function DynamicTime({ timezone }: DynamicTimeProps) {
|
||||
|
||||
return (
|
||||
<div className="text-sm text-muted-foreground">
|
||||
{d2s({ dateTime: time })}
|
||||
{d2s({ dateTime: time, timezone: settings.system.timezone })}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user