import { useEffect } from 'react'; import { Outlet, Route, Routes, useLocation, useParams } from 'react-router-dom'; import { isHomeView } from './lib/utils/view-utils'; import useTheme from './hooks/use-theme'; import styles from './app.module.css'; import Board from './views/board'; import Catalog from './views/catalog'; import Home from './views/home'; import NotFound from './views/not-found'; import PendingPost from './views/pending-post'; import PostPage from './views/post-page'; import BoardHeader from './components/board-header'; import { DesktopBoardButtons, MobileBoardButtons } from './components/board-buttons'; import TopBar from './components/topbar'; import ChallengeModal from './components/challenge-modal'; import SubplebbitStats from './components/subplebbit-stats'; import PostForm from './components/post-form'; const BoardLayout = () => { const { accountCommentIndex, commentCid, subplebbitAddress } = useParams(); const location = useLocation(); const isValidAccountCommentIndex = !accountCommentIndex || (!isNaN(parseInt(accountCommentIndex)) && parseInt(accountCommentIndex) >= 0); const isValidCommentCid = !commentCid || /^Qm[a-zA-Z0-9]{44}$/.test(commentCid); const isValidSubplebbitAddress = !subplebbitAddress || subplebbitAddress.includes('.') || /^12D3KooW[a-zA-Z0-9]{44}$/.test(subplebbitAddress); if (!isValidAccountCommentIndex || !isValidCommentCid || !isValidSubplebbitAddress) { return ; } // force rerender of post form when navigating between pages const key = `${subplebbitAddress}-${location.pathname}`; return (
{subplebbitAddress && isValidSubplebbitAddress && }
); }; const App = () => { const location = useLocation(); const isInHomeView = isHomeView(location.pathname); const [theme] = useTheme(); useEffect(() => { document.body.classList.forEach((className) => document.body.classList.remove(className)); const classToAdd = isInHomeView ? 'yotsuba' : theme; document.body.classList.add(classToAdd); }, [theme, isInHomeView]); const globalLayout = ( <> ); return (
} /> }> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } />
); }; export default App;