fix(not found page): only show 'back to p/...' button if subplebbitAddress is in valid format; limit img size

This commit is contained in:
Tom (plebeius.eth)
2024-06-21 17:03:53 +02:00
parent b5b5c5ca46
commit 1900d1cdf2
2 changed files with 10 additions and 6 deletions
+2
View File
@@ -41,6 +41,8 @@
.boxContent img { .boxContent img {
display: block; display: block;
margin: auto; margin: auto;
max-height: 500px;
max-width: 500px;
} }
.backToBoard { .backToBoard {
+8 -6
View File
@@ -1,8 +1,8 @@
import { useState } from 'react'; import { useState } from 'react';
import { Link, useParams } from 'react-router-dom'; import { Link, useLocation } 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 { useSubplebbit } from '@plebbit/plebbit-react-hooks';
const totalNotFoundImages = 2; const totalNotFoundImages = 2;
@@ -16,8 +16,10 @@ const NotFoundImage = () => {
}; };
const NotFound = () => { const NotFound = () => {
const { subplebbitAddress } = useParams(); const location = useLocation();
const isValidSubplebbitAddress = !subplebbitAddress || subplebbitAddress.includes('.') || /^12D3K[a-zA-Z0-9]{44}$/.test(subplebbitAddress); const subplebbitAddress = location.pathname.startsWith('/p/') ? location.pathname.split('/')[2] : '';
const subplebbit = useSubplebbit({ subplebbitAddress });
const { address, shortAddress } = subplebbit || {};
return ( return (
<div className={styles.wrapper}> <div className={styles.wrapper}>
@@ -30,11 +32,11 @@ const NotFound = () => {
</div> </div>
<div className={styles.boxContent}> <div className={styles.boxContent}>
<NotFoundImage /> <NotFoundImage />
{subplebbitAddress && isValidSubplebbitAddress && ( {address && (
<> <>
<br /> <br />
<div className={styles.backToBoard}> <div className={styles.backToBoard}>
[<Link to={`/p/${subplebbitAddress}`}>Back to p/{Plebbit.getShortAddress(subplebbitAddress)}</Link>] [<Link to={`/p/${subplebbitAddress}`}>Back to p/{shortAddress}</Link>]
</div> </div>
</> </>
)} )}