-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsefulLinksPage.jsx
More file actions
52 lines (43 loc) · 1.37 KB
/
UsefulLinksPage.jsx
File metadata and controls
52 lines (43 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React, { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import Seo from '../components/Seo';
const UsefulLinksPage = () => {
const navigate = useNavigate();
const [loading, setLoading] = useState(true);
useEffect(() => {
const fetchAndRedirect = async () => {
try {
const logsResponse = await fetch('/logs/logs.json');
const logs = await logsResponse.json();
const allLogUrls = logs.map((log) => `/logs/${log.slug}`);
const randomUrl =
allLogUrls[Math.floor(Math.random() * allLogUrls.length)];
navigate(randomUrl, { replace: true });
} catch (error) {
console.error('Error fetching content for redirection:', error);
// Fallback or error message
setLoading(false);
}
};
fetchAndRedirect();
}, [navigate]);
if (loading) {
return (
<div className="text-center py-16">Finding a random log for you...</div>
);
}
return (
<div className="text-center py-16">
<Seo
title="Redirecting... | Fezcodex"
description="Redirecting to a random log entry on Fezcodex."
keywords={['Fezcodex', 'redirect', 'random', 'log']}
/>
<p>
If you are not redirected, please click <a href="/">here</a> to go to
the homepage.
</p>
</div>
);
};
export default UsefulLinksPage;