fix(not found): force yotsuba theme with ref, not with params in app because they can't be detected in app

This commit is contained in:
plebeius.eth
2024-05-07 22:09:00 +02:00
parent 6d06e7b80b
commit 5e8d7436f9
3 changed files with 43 additions and 26 deletions
+3 -5
View File
@@ -1,6 +1,6 @@
import { useEffect } from 'react'; import { useEffect } from 'react';
import { Outlet, Route, Routes, useLocation, useParams } from 'react-router-dom'; import { Outlet, Route, Routes, useLocation, useParams } from 'react-router-dom';
import { isHomeView, isNotFoundView } from './lib/utils/view-utils'; import { isHomeView } from './lib/utils/view-utils';
import useTheme from './hooks/use-theme'; import useTheme from './hooks/use-theme';
import styles from './app.module.css'; import styles from './app.module.css';
import Board from './views/board'; import Board from './views/board';
@@ -47,16 +47,14 @@ const BoardLayout = () => {
const App = () => { const App = () => {
const location = useLocation(); const location = useLocation();
const params = useParams();
const isInHomeView = isHomeView(location.pathname); const isInHomeView = isHomeView(location.pathname);
const isInNotFoundPage = isNotFoundView(location.pathname, params);
const [theme] = useTheme(); const [theme] = useTheme();
useEffect(() => { useEffect(() => {
document.body.classList.forEach((className) => document.body.classList.remove(className)); document.body.classList.forEach((className) => document.body.classList.remove(className));
const classToAdd = isInHomeView || isInNotFoundPage ? 'yotsuba' : theme; const classToAdd = isInHomeView ? 'yotsuba' : theme;
document.body.classList.add(classToAdd); document.body.classList.add(classToAdd);
}, [theme, isInHomeView, isInNotFoundPage]); }, [theme, isInHomeView]);
const globalLayout = ( const globalLayout = (
<> <>
+3 -3
View File
@@ -1,8 +1,8 @@
.content { .content {
margin: auto; margin: auto;
text-align: left; text-align: left;
width: 57.69em; width: 57.69em;
min-width: 750px; min-width: 750px;
} }
.boxOuter { .boxOuter {
+37 -18
View File
@@ -1,8 +1,9 @@
import { useState } from 'react'; import { useEffect, useState, useRef } from 'react';
import { Link, useParams } from 'react-router-dom'; import { Link, useParams } from 'react-router-dom';
import { HomeLogo } from '../home'; import { HomeLogo } from '../home';
import styles from './not-found.module.css'; import styles from './not-found.module.css';
import Plebbit from '@plebbit/plebbit-js/dist/browser/index.js'; import Plebbit from '@plebbit/plebbit-js/dist/browser/index.js';
import useTheme from '../../hooks/use-theme';
const totalNotFoundImages = 2; const totalNotFoundImages = 2;
@@ -19,24 +20,42 @@ const NotFoundImage = () => {
const NotFound = () => { const NotFound = () => {
const { subplebbitAddress } = useParams(); const { subplebbitAddress } = useParams();
const [theme, setTheme] = useTheme();
const previousThemeRef = useRef(theme);
useEffect(() => {
if (theme !== 'yotsuba') {
previousThemeRef.current = theme;
setTheme('yotsuba');
}
return () => {
if (theme === 'yotsuba') {
setTheme(previousThemeRef.current);
}
};
}, [theme, setTheme]);
return ( return (
<div className={styles.content}> <div className={styles.wrapper}>
<HomeLogo /> <div className={styles.content}>
<div className={styles.boxOuter}> <HomeLogo />
<div className={styles.boxInner}> <div className={styles.boxOuter}>
<div className={styles.boxBar}> <div className={styles.boxInner}>
<h2>404 Not Found</h2> <div className={styles.boxBar}>
</div> <h2>404 Not Found</h2>
<div className={styles.boxContent}> </div>
<NotFoundImage /> <div className={styles.boxContent}>
{subplebbitAddress && ( <NotFoundImage />
<> {subplebbitAddress && (
<br /> <>
<div className={styles.backToBoard}> <br />
[<Link to={`/p/${subplebbitAddress}`}>Back to p/{Plebbit.getShortAddress(subplebbitAddress)}</Link>] <div className={styles.backToBoard}>
</div> [<Link to={`/p/${subplebbitAddress}`}>Back to p/{Plebbit.getShortAddress(subplebbitAddress)}</Link>]
</> </div>
)} </>
)}
</div>
</div> </div>
</div> </div>
</div> </div>