Files
5chan/src/app.tsx
T

63 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-02-28 21:18:37 +01:00
import { useEffect } from 'react';
import { Outlet, Route, Routes, useLocation, useParams } from 'react-router-dom';
2024-03-20 13:00:11 +01:00
import { isHomeView } from './lib/utils/view-utils';
import { useSubplebbit } from '@plebbit/plebbit-react-hooks';
2024-02-27 17:58:08 +01:00
import styles from './app.module.css';
2024-02-28 21:18:37 +01:00
import useTheme from './hooks/use-theme';
2024-03-20 13:00:11 +01:00
import Home from './views/home';
import Subplebbit from './views/subplebbit';
import BoardNav from './components/board-nav';
2024-03-19 21:12:57 +01:00
import BoardBanner from './components/board-banner';
import BoardStats from './components/board-stats';
2024-03-20 13:00:11 +01:00
import PostForm from './components/post-form';
2024-02-27 17:58:08 +01:00
const BoardLayout = () => {
const { subplebbitAddress } = useParams<{ subplebbitAddress: string }>();
const subplebbit = useSubplebbit({ subplebbitAddress });
return (
<>
{subplebbitAddress && (
<>
<BoardNav address={subplebbitAddress} />
<BoardBanner title={subplebbit.title} address={subplebbitAddress} />
<PostForm address={subplebbitAddress} />
<BoardStats address={subplebbitAddress} />
</>
)}
<Outlet />
</>
);
};
2024-02-27 17:58:08 +01:00
const App = () => {
2024-02-28 21:18:37 +01:00
const [theme] = useTheme();
const location = useLocation();
const isInHomeView = isHomeView(location.pathname);
2024-02-28 21:18:37 +01:00
useEffect(() => {
document.body.classList.forEach((className) => document.body.classList.remove(className));
document.body.classList.add(theme);
}, [theme]);
2024-03-17 21:47:16 +01:00
// const globalLayout = (
// <>
// <ChallengeModal />
// <Outlet />
// </>
// );
2024-02-27 17:58:08 +01:00
return (
<div className={`${styles.app} ${isInHomeView ? 'yotsuba' : theme}`}>
2024-02-27 17:58:08 +01:00
<Routes>
<Route path='/' element={<Home />} />
<Route element={<BoardLayout />}>
2024-03-18 15:04:30 +01:00
<Route path='/p/:subplebbitAddress' element={<Subplebbit />} />
</Route>
2024-02-27 17:58:08 +01:00
</Routes>
</div>
);
};
export default App;