2024-04-08 17:13:02 +02:00
|
|
|
import { useEffect } from 'react';
|
|
|
|
|
import { Outlet, Route, Routes, useLocation } from 'react-router-dom';
|
2024-03-20 13:00:11 +01:00
|
|
|
import { isHomeView } from './lib/utils/view-utils';
|
2024-04-08 17:13:02 +02:00
|
|
|
import { useSubplebbits } from '@plebbit/plebbit-react-hooks';
|
2024-03-27 15:10:58 +01:00
|
|
|
import { useDefaultSubplebbitAddresses } from './hooks/use-default-subplebbits';
|
2024-02-28 21:18:37 +01:00
|
|
|
import useTheme from './hooks/use-theme';
|
2024-03-27 15:10:58 +01:00
|
|
|
import styles from './app.module.css';
|
2024-03-20 13:00:11 +01:00
|
|
|
import Home from './views/home';
|
2024-04-02 17:00:36 +02:00
|
|
|
import PostPage from './views/post-page';
|
2024-03-20 22:06:35 +01:00
|
|
|
import Settings from './views/settings';
|
2024-03-17 16:27:15 +01:00
|
|
|
import Subplebbit from './views/subplebbit';
|
2024-03-19 13:18:12 +01:00
|
|
|
import BoardNav from './components/board-nav';
|
2024-03-19 21:12:57 +01:00
|
|
|
import BoardBanner from './components/board-banner';
|
2024-03-27 15:10:58 +01:00
|
|
|
import { DesktopBoardButtons } from './components/board-buttons';
|
|
|
|
|
import { MobileBoardButtons } from './components/board-buttons';
|
2024-03-20 14:31:31 +01:00
|
|
|
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 App = () => {
|
2024-02-28 21:18:37 +01:00
|
|
|
const [theme] = useTheme();
|
2024-03-17 16:27:15 +01:00
|
|
|
const location = useLocation();
|
|
|
|
|
const isInHomeView = isHomeView(location.pathname);
|
2024-02-28 21:18:37 +01:00
|
|
|
|
2024-03-27 15:10:58 +01:00
|
|
|
const subplebbitAddresses = useDefaultSubplebbitAddresses();
|
|
|
|
|
const { subplebbits } = useSubplebbits({ subplebbitAddresses });
|
|
|
|
|
|
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-04-08 17:13:02 +02:00
|
|
|
const boardLayout = (
|
|
|
|
|
<>
|
|
|
|
|
<BoardNav subplebbits={subplebbits} />
|
|
|
|
|
<BoardBanner />
|
|
|
|
|
<MobileBoardButtons />
|
|
|
|
|
<PostForm />
|
|
|
|
|
<BoardStats />
|
|
|
|
|
<DesktopBoardButtons />
|
|
|
|
|
<Outlet />
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
|
2024-02-27 17:58:08 +01:00
|
|
|
return (
|
2024-03-17 16:27:15 +01:00
|
|
|
<div className={`${styles.app} ${isInHomeView ? 'yotsuba' : theme}`}>
|
2024-02-27 17:58:08 +01:00
|
|
|
<Routes>
|
2024-03-27 15:10:58 +01:00
|
|
|
<Route path='/' element={<Home subplebbits={subplebbits} />} />
|
2024-04-08 17:13:02 +02:00
|
|
|
<Route element={boardLayout}>
|
2024-04-07 12:21:53 +02:00
|
|
|
<Route path='/p/:subplebbitAddress' element={<Subplebbit />} />
|
2024-04-02 17:00:36 +02:00
|
|
|
<Route path='/p/:subplebbitAddress/c/:commentCid' element={<PostPage />} />
|
2024-04-08 17:32:12 +02:00
|
|
|
<Route path='/p/:subplebbitAddress/description' element={<PostPage />} />
|
|
|
|
|
<Route path='/p/:subplebbitAddress/rules' element={<PostPage />} />
|
2024-03-18 15:04:30 +01:00
|
|
|
</Route>
|
2024-03-20 22:06:35 +01:00
|
|
|
<Route path='/settings' element={<Settings />} />
|
2024-02-27 17:58:08 +01:00
|
|
|
</Routes>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default App;
|