feat: re-implement current year logic by using a component
This commit is contained in:
parent
878d31fd90
commit
c0ea13a2be
22
src/CurrentYear.tsx
Normal file
22
src/CurrentYear.tsx
Normal file
@ -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}</>;
|
||||
}
|
@ -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() {
|
||||
{') - 移除已购音乐的加密保护。'}
|
||||
</Flex>
|
||||
<Text>
|
||||
{'Copyright © 2019 - 2023 '}
|
||||
{'Copyright © 2019 - '}
|
||||
<CurrentYear />{' '}
|
||||
<Link href="https://git.unlock-music.dev/um" isExternal>
|
||||
UnlockMusic 团队
|
||||
</Link>
|
||||
|
Loading…
Reference in New Issue
Block a user