From bbb43ba2f5d56317e4fad6c418a96fff76025365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Sun, 21 May 2023 14:24:06 +0100 Subject: [PATCH] feat: re-implement current year logic by using a component --- src/CurrentYear.tsx | 22 ++++++++++++++++++++++ src/Footer.tsx | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/CurrentYear.tsx diff --git a/src/CurrentYear.tsx b/src/CurrentYear.tsx new file mode 100644 index 0000000..651f036 --- /dev/null +++ b/src/CurrentYear.tsx @@ -0,0 +1,22 @@ +import { useEffect, useState } from 'react'; + +// Update every half hour +const TIMER_UPDATE_INTERVAL = 30 * 60 * 1000; + +const getCurrentYear = () => new Date().getFullYear(); + +export function CurrentYear() { + const [year, setYear] = useState(getCurrentYear); + + useEffect(() => { + const updateTime = () => setYear(getCurrentYear); + updateTime(); + + const timer = setInterval(updateTime, TIMER_UPDATE_INTERVAL); + return () => { + clearInterval(timer); + }; + }, []); + + return <>{year}; +} diff --git a/src/Footer.tsx b/src/Footer.tsx index a8c121e..8cd3c68 100644 --- a/src/Footer.tsx +++ b/src/Footer.tsx @@ -1,6 +1,7 @@ import { Center, Flex, Link, Text } from '@chakra-ui/react'; import { Suspense } from 'react'; import { SDKVersion } from './SDKVersion'; +import { CurrentYear } from './CurrentYear'; export function Footer() { return ( @@ -25,7 +26,8 @@ export function Footer() { {') - 移除已购音乐的加密保护。'} - {'Copyright © 2019 - 2023 '} + {'Copyright © 2019 - '} + {' '} UnlockMusic 团队