mirror of
https://github.com/woodchen-ink/nezha-dash-v1.git
synced 2025-07-18 17:41:56 +08:00
feat: enhance time display with NumberFlow component
This commit is contained in:
parent
c02d25e127
commit
7aad81518a
@ -14,6 +14,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fontsource/inter": "^5.1.1",
|
"@fontsource/inter": "^5.1.1",
|
||||||
"@heroicons/react": "^2.2.0",
|
"@heroicons/react": "^2.2.0",
|
||||||
|
"@number-flow/react": "^0.5.5",
|
||||||
"@radix-ui/react-accordion": "^1.2.2",
|
"@radix-ui/react-accordion": "^1.2.2",
|
||||||
"@radix-ui/react-checkbox": "^1.1.3",
|
"@radix-ui/react-checkbox": "^1.1.3",
|
||||||
"@radix-ui/react-dialog": "^1.1.5",
|
"@radix-ui/react-dialog": "^1.1.5",
|
||||||
|
@ -5,6 +5,7 @@ import { useBackground } from "@/hooks/use-background"
|
|||||||
import { useWebSocketContext } from "@/hooks/use-websocket-context"
|
import { useWebSocketContext } from "@/hooks/use-websocket-context"
|
||||||
import { fetchLoginUser, fetchSetting } from "@/lib/nezha-api"
|
import { fetchLoginUser, fetchSetting } from "@/lib/nezha-api"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
import NumberFlow, { NumberFlowGroup } from "@number-flow/react"
|
||||||
import { useQuery } from "@tanstack/react-query"
|
import { useQuery } from "@tanstack/react-query"
|
||||||
import { AnimatePresence, m } from "framer-motion"
|
import { AnimatePresence, m } from "framer-motion"
|
||||||
import { ImageMinus } from "lucide-react"
|
import { ImageMinus } from "lucide-react"
|
||||||
@ -266,31 +267,35 @@ function DashboardLink() {
|
|||||||
|
|
||||||
function Overview() {
|
function Overview() {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [mouted, setMounted] = useState(false)
|
const [time, setTime] = useState({
|
||||||
|
hh: DateTime.now().setLocale("en-US").hour,
|
||||||
|
mm: DateTime.now().setLocale("en-US").minute,
|
||||||
|
ss: DateTime.now().setLocale("en-US").second,
|
||||||
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setMounted(true)
|
const timer = setInterval(() => {
|
||||||
}, [])
|
setTime({
|
||||||
const timeOption = DateTime.TIME_WITH_SECONDS
|
hh: DateTime.now().setLocale("en-US").hour,
|
||||||
timeOption.hour12 = true
|
mm: DateTime.now().setLocale("en-US").minute,
|
||||||
const [timeString, setTimeString] = useState(DateTime.now().setLocale("en-US").toLocaleString(timeOption))
|
ss: DateTime.now().setLocale("en-US").second,
|
||||||
useEffect(() => {
|
})
|
||||||
const updateTime = () => {
|
}, 1000)
|
||||||
const now = DateTime.now().setLocale("en-US").toLocaleString(timeOption)
|
|
||||||
setTimeString(now)
|
return () => clearInterval(timer)
|
||||||
requestAnimationFrame(updateTime)
|
|
||||||
}
|
|
||||||
requestAnimationFrame(updateTime)
|
|
||||||
}, [])
|
}, [])
|
||||||
return (
|
return (
|
||||||
<section className={"mt-10 flex flex-col md:mt-16 header-timer"}>
|
<section className={"mt-10 flex flex-col md:mt-16 header-timer"}>
|
||||||
<p className="text-base font-semibold">👋 {t("overview")}</p>
|
<p className="text-base font-semibold">👋 {t("overview")}</p>
|
||||||
<div className="flex items-center gap-1.5">
|
<div className="flex items-center gap-1.5">
|
||||||
<p className="text-sm font-medium opacity-50">{t("whereTheTimeIs")}</p>
|
<p className="text-sm font-medium opacity-50">{t("whereTheTimeIs")}</p>
|
||||||
{mouted ? (
|
<NumberFlowGroup>
|
||||||
<p className="text-sm font-medium">{timeString}</p>
|
<div style={{ fontVariantNumeric: "tabular-nums" }} className="flex text-sm font-medium mt-0.5">
|
||||||
) : (
|
<NumberFlow trend={1} value={time.hh} format={{ minimumIntegerDigits: 2 }} />
|
||||||
<Skeleton className="h-[20px] w-[50px] rounded-[5px] bg-muted-foreground/10 animate-none"></Skeleton>
|
<NumberFlow prefix=":" trend={1} value={time.mm} digits={{ 1: { max: 5 } }} format={{ minimumIntegerDigits: 2 }} />
|
||||||
)}
|
<NumberFlow prefix=":" trend={1} value={time.ss} digits={{ 1: { max: 5 } }} format={{ minimumIntegerDigits: 2 }} />
|
||||||
|
</div>
|
||||||
|
</NumberFlowGroup>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user