Skip to content

Commit

Permalink
refactor(frontend): refactor 404 page route logic
Browse files Browse the repository at this point in the history
  • Loading branch information
UNIkeEN committed Nov 28, 2024
1 parent 858e3a6 commit 4a901ca
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions frontend/src/pages/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ const NotFoundPage = () => {
const [seconds, setSeconds] = useState(3);

useEffect(() => {
if (seconds > 1) {
const timer = setTimeout(() => {
setSeconds(seconds - 1);
}, 1000);
return () => clearTimeout(timer);
} else {
const timer = setTimeout(() => {
router.push('/home');
}, 1500);
return () => clearTimeout(timer);
}
}, [seconds, router]);
const interval = setInterval(() => {
setSeconds((prev) => {
if (prev === 1) {
clearInterval(interval);
router.push('/home');
}
return prev - 1;
});
}, 1000);

return () => clearInterval(interval);
}, [router]);

return (
<>
Expand All @@ -39,14 +39,12 @@ const NotFoundPage = () => {
}}
>
<VStack>
<Icon as={FiX} w={8} h={8} color='red.500' />
<Text>
{t('NotFoundPage.text', { seconds: seconds })}
</Text>
<Icon as={FiX} w={8} h={8} color="red.500" />
<Text>{t('NotFoundPage.text', { seconds })}</Text>
</VStack>
</div>
</>
);
};

export default NotFoundPage;
export default NotFoundPage;

0 comments on commit 4a901ca

Please sign in to comment.