mirror of
https://git.unlock-music.dev/um/um-react.git
synced 2024-11-24 00:42:16 +00:00
feat: re-implement current year logic by using a component
This commit is contained in:
parent
0f99f9ac4f
commit
bbb43ba2f5
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 { 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>
|
||||||
|
Loading…
Reference in New Issue
Block a user