feat: re-implement current year logic by using a component

This commit is contained in:
鲁树人 2023-05-21 14:24:06 +01:00
parent 0f99f9ac4f
commit bbb43ba2f5
2 changed files with 25 additions and 1 deletions

22
src/CurrentYear.tsx Normal file
View 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}</>;
}

View File

@ -1,6 +1,7 @@
import { Center, Flex, Link, Text } from '@chakra-ui/react'; import { Center, Flex, Link, Text } from '@chakra-ui/react';
import { Suspense } from 'react'; import { Suspense } from 'react';
import { SDKVersion } from './SDKVersion'; import { SDKVersion } from './SDKVersion';
import { CurrentYear } from './CurrentYear';
export function Footer() { export function Footer() {
return ( return (
@ -25,7 +26,8 @@ export function Footer() {
{') - 移除已购音乐的加密保护。'} {') - 移除已购音乐的加密保护。'}
</Flex> </Flex>
<Text> <Text>
{'Copyright © 2019 - 2023 '} {'Copyright © 2019 - '}
<CurrentYear />{' '}
<Link href="https://git.unlock-music.dev/um" isExternal> <Link href="https://git.unlock-music.dev/um" isExternal>
UnlockMusic UnlockMusic
</Link> </Link>