Files
5chan/src/App.js
T

94 lines
3.4 KiB
JavaScript
Raw Normal View History

2023-03-05 14:26:40 +01:00
import React, { useState, useEffect } from 'react';
2023-01-31 23:08:57 +01:00
import { Route, Routes } from 'react-router-dom';
2023-02-01 13:30:32 +01:00
import { Helmet } from 'react-helmet-async';
2023-01-31 23:08:57 +01:00
import Home from './components/Home';
import Board from './components/Board';
2023-02-12 21:20:08 +01:00
import Thread from './components/Thread';
2023-02-19 16:48:46 +01:00
import Catalog from './components/Catalog';
2023-03-06 18:38:33 +01:00
import NotFound from './components/NotFound';
2023-03-09 17:51:56 +01:00
import CaptchaModal from './components/CaptchaModal';
2023-02-08 21:49:36 +01:00
import { createGlobalStyle } from 'styled-components';
2023-02-28 16:34:33 +01:00
import 'react-tooltip/dist/react-tooltip.css';
2023-03-05 14:26:40 +01:00
import preloadImages from './utils/preloadImages';
2023-03-08 11:51:57 +01:00
import { useCookies } from 'react-cookie';
2023-02-08 21:49:36 +01:00
2023-02-09 19:08:15 +01:00
export const BoardContext = React.createContext();
2023-02-08 21:49:36 +01:00
const GlobalStyle = createGlobalStyle`
body {
margin: 0;
padding: 0;
background: ${props => props.background};
color: ${props => props.color};
font-family: ${props => props.fontFamily};
}
2023-03-01 16:51:30 +01:00
.tooltip {
border-radius: 0;
max-width: 40%;
font-size: 11px;
padding: 3px;
opacity: 100%;
}
2023-02-08 21:49:36 +01:00
`;
2023-01-31 23:08:57 +01:00
2023-02-09 19:08:15 +01:00
export default function App() {
2023-02-08 21:49:36 +01:00
const [bodyStyle, setBodyStyle] = useState({
2023-02-16 14:05:48 +01:00
background: "#ffe url(/assets/fade.png) top repeat-x",
2023-02-08 21:49:36 +01:00
color: "maroon",
fontFamily: "Helvetica, Arial, sans-serif"
});
2023-02-09 19:08:15 +01:00
const [selectedTitle, setSelectedTitle] = useState('');
const [selectedAddress, setSelectedAddress] = useState('');
const [selectedThread, setSelectedThread] = useState('');
2023-03-08 11:51:57 +01:00
const [cookies, setCookie] = useCookies(['selectedStyle']);
const [selectedStyle, setSelectedStyle] = useState(cookies.selectedStyle || 'Yotsuba');
2023-03-09 17:51:56 +01:00
const [isCaptchaOpen, setIsCaptchaOpen] = useState(false);
2023-03-08 11:51:57 +01:00
2023-02-09 19:08:15 +01:00
2023-03-05 14:26:40 +01:00
const imageUrls = Array.from({ length: 14 }, (_, index) => `/assets/banners/banner-${index + 1}.jpg`);
useEffect(() => {
preloadImages([...imageUrls]);
}, []);
2023-03-09 17:51:56 +01:00
const handleCaptchaClose = () => {
setIsCaptchaOpen(false);
};
2023-03-05 14:26:40 +01:00
2023-02-01 13:30:32 +01:00
return (
<div>
<Helmet>
2023-02-16 14:05:48 +01:00
<link rel="apple-touch-icon" sizes="180x180" href="/assets/logo/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/assets/logo/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/assets/logo/favicon-16x16.png" />
2023-02-01 13:30:32 +01:00
<link rel="manifest" href="/site.webmanifest" />
<meta name="msapplication-TileColor" content="#fee9cd" />
<meta name="theme-color" content="#ffffff" />
</Helmet>
2023-02-08 21:49:36 +01:00
<GlobalStyle
background={bodyStyle.background}
color={bodyStyle.color}
fontFamily={bodyStyle.fontFamily}
/>
2023-03-09 17:51:56 +01:00
<BoardContext.Provider value={{ selectedTitle, setSelectedTitle, selectedAddress, setSelectedAddress, selectedThread, setSelectedThread, selectedStyle, setSelectedStyle, isCaptchaOpen, setIsCaptchaOpen }}>
2023-02-09 19:08:15 +01:00
<Routes>
2023-02-13 12:05:10 +01:00
<Route exact path='/' element={<Home setBodyStyle={setBodyStyle} />} />
2023-03-02 21:51:06 +01:00
<Route path={`/:subplebbitAddress`} element={<Board setBodyStyle={setBodyStyle} />}>
2023-02-19 22:08:18 +01:00
<Route path='post' element={<Board />} />
2023-02-12 21:20:08 +01:00
</Route>
2023-03-02 21:51:06 +01:00
<Route path={`/:subplebbitAddress/thread/:threadCid`} element={<Thread setBodyStyle={setBodyStyle} />}>
2023-02-19 22:08:18 +01:00
<Route path='post' element={<Thread />} />
2023-02-11 22:00:13 +01:00
</Route>
2023-03-02 21:51:06 +01:00
<Route path={`/:subplebbitAddress/catalog`} element={<Catalog setBodyStyle={setBodyStyle} /> }>
2023-02-19 22:08:18 +01:00
<Route path='post' element={<Catalog />} />
2023-02-19 16:48:46 +01:00
</Route>
2023-03-06 18:38:33 +01:00
<Route path='*' element={<NotFound />} />
2023-02-09 19:08:15 +01:00
</Routes>
</BoardContext.Provider>
2023-03-09 17:51:56 +01:00
<CaptchaModal isOpen={isCaptchaOpen} closeModal={handleCaptchaClose} />
2023-02-01 13:30:32 +01:00
</div>
)}