mirror of
https://github.com/hamster1963/nezha-dash.git
synced 2025-04-24 21:10:45 +08:00
Compare commits
No commits in common. "68b7034db6d8598ba2776d81760ee154f107b786" and "0de53d888849918e310db7afe8d71e16a2b26ee5" have entirely different histories.
68b7034db6
...
0de53d8888
@ -97,25 +97,34 @@ function Links() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/streamich/react-use/blob/master/src/useInterval.ts
|
||||||
|
const useInterval = (callback: () => void, delay: number | null) => {
|
||||||
|
const savedCallback = useRef<() => void>(() => {})
|
||||||
|
useEffect(() => {
|
||||||
|
savedCallback.current = callback
|
||||||
|
})
|
||||||
|
useEffect(() => {
|
||||||
|
if (delay !== null) {
|
||||||
|
const interval = setInterval(() => savedCallback.current(), delay || 0)
|
||||||
|
return () => clearInterval(interval)
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
}, [delay])
|
||||||
|
}
|
||||||
function Overview() {
|
function Overview() {
|
||||||
const t = useTranslations("Overview")
|
const t = useTranslations("Overview")
|
||||||
const [mouted, setMounted] = useState(false)
|
const [mouted, setMounted] = useState(false)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setMounted(true)
|
setMounted(true)
|
||||||
}, [])
|
}, [])
|
||||||
const timeOption = DateTime.TIME_WITH_SECONDS
|
const timeOption = DateTime.TIME_SIMPLE
|
||||||
timeOption.hour12 = true
|
timeOption.hour12 = true
|
||||||
const [timeString, setTimeString] = useState(
|
const [timeString, setTimeString] = useState(
|
||||||
DateTime.now().setLocale("en-US").toLocaleString(timeOption),
|
DateTime.now().setLocale("en-US").toLocaleString(timeOption),
|
||||||
)
|
)
|
||||||
useEffect(() => {
|
useInterval(() => {
|
||||||
const updateTime = () => {
|
setTimeString(DateTime.now().setLocale("en-US").toLocaleString(timeOption))
|
||||||
const now = DateTime.now().setLocale("en-US").toLocaleString(timeOption)
|
}, 1000)
|
||||||
setTimeString(now)
|
|
||||||
requestAnimationFrame(updateTime)
|
|
||||||
}
|
|
||||||
requestAnimationFrame(updateTime)
|
|
||||||
}, [])
|
|
||||||
return (
|
return (
|
||||||
<section className={"mt-10 flex flex-col md:mt-16"}>
|
<section className={"mt-10 flex flex-col md:mt-16"}>
|
||||||
<p className="text-base font-semibold">{t("p_2277-2331_Overview")}</p>
|
<p className="text-base font-semibold">{t("p_2277-2331_Overview")}</p>
|
||||||
|
@ -59,24 +59,7 @@ export default function Switch({
|
|||||||
w: currentTagElement.offsetWidth,
|
w: currentTagElement.offsetWidth,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}, [nowTag])
|
}, [nowTag, allTag])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const currentTagElement = tagRefs.current[allTag.indexOf(nowTag)]?.current
|
|
||||||
const container = scrollRef.current
|
|
||||||
|
|
||||||
if (currentTagElement && container) {
|
|
||||||
const containerRect = container.getBoundingClientRect()
|
|
||||||
const tagRect = currentTagElement.getBoundingClientRect()
|
|
||||||
|
|
||||||
const scrollLeft = currentTagElement.offsetLeft - (containerRect.width - tagRect.width) / 2
|
|
||||||
|
|
||||||
container.scrollTo({
|
|
||||||
left: Math.max(0, scrollLeft),
|
|
||||||
behavior: "smooth",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}, [nowTag])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@ -99,10 +82,7 @@ export default function Switch({
|
|||||||
<div
|
<div
|
||||||
key={tag}
|
key={tag}
|
||||||
ref={tagRefs.current[index]}
|
ref={tagRefs.current[index]}
|
||||||
onClick={() => {
|
onClick={() => onTagChange(tag)}
|
||||||
onTagChange(tag)
|
|
||||||
sessionStorage.setItem("selectedTag", tag)
|
|
||||||
}}
|
|
||||||
className={cn(
|
className={cn(
|
||||||
"relative cursor-pointer rounded-3xl px-2.5 py-[8px] text-[13px] font-[600]",
|
"relative cursor-pointer rounded-3xl px-2.5 py-[8px] text-[13px] font-[600]",
|
||||||
"transition-all duration-500 ease-in-out text-stone-400 dark:text-stone-500",
|
"transition-all duration-500 ease-in-out text-stone-400 dark:text-stone-500",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nezha-dash",
|
"name": "nezha-dash",
|
||||||
"version": "2.1.0",
|
"version": "2.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev -p 3040",
|
"dev": "next dev -p 3040",
|
||||||
|
Loading…
Reference in New Issue
Block a user