import { useEffect } from 'react'; import { Outlet, Route, Routes, useLocation, useParams } from 'react-router-dom'; import { isAllView, isSubscriptionsView } from './lib/utils/view-utils'; import useIsMobile from './hooks/use-is-mobile'; 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 Post from './views/post'; import { DesktopBoardButtons, MobileBoardButtons } from './components/board-buttons'; import BoardHeader from './components/board-header'; import ChallengeModal from './components/challenge-modal'; import PostForm from './components/post-form'; import SubplebbitStats from './components/subplebbit-stats'; import TopBar from './components/topbar'; import { timeFilterNames } from './hooks/use-time-filter'; import useTheme from './hooks/use-theme'; import useInitialTheme from './hooks/use-initial-theme'; const BoardLayout = () => { const { accountCommentIndex, subplebbitAddress, timeFilterName } = useParams(); const location = useLocation(); const isMobile = useIsMobile(); const isInAllView = isAllView(location.pathname, useParams()); const isInSubscriptionsView = isSubscriptionsView(location.pathname, useParams()); const isValidAccountCommentIndex = !accountCommentIndex || (!isNaN(parseInt(accountCommentIndex)) && parseInt(accountCommentIndex) >= 0); if (!isValidAccountCommentIndex || (timeFilterName && !timeFilterNames.includes(timeFilterName))) { return ; } // force rerender of post form when navigating between pages const key = `${subplebbitAddress}-${location.pathname}`; return (
{isMobile ? (subplebbitAddress || isInAllView || isInSubscriptionsView) && ( <> ) : (subplebbitAddress || isInAllView || isInSubscriptionsView) && ( <> {!(isInAllView || isInSubscriptionsView) && } )}
); }; const GlobalLayout = () => { useTheme(); return ( <> ); }; const App = () => { const initialTheme = useInitialTheme(); useEffect(() => { document.body.classList.add(initialTheme); }, [initialTheme]); return (
}> } /> }> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } />
); }; export default App;