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 {
display: block;
margin: auto;
max-height: 500px;
max-width: 500px;
}
.backToBoard {
+8 -6
View File
@@ -1,8 +1,8 @@
import { useState } from 'react';
import { Link, useParams } from 'react-router-dom';
import { Link, useLocation } from 'react-router-dom';
import { HomeLogo } from '../home';
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;
@@ -16,8 +16,10 @@ const NotFoundImage = () => {
};
const NotFound = () => {
const { subplebbitAddress } = useParams();
const isValidSubplebbitAddress = !subplebbitAddress || subplebbitAddress.includes('.') || /^12D3K[a-zA-Z0-9]{44}$/.test(subplebbitAddress);
const location = useLocation();
const subplebbitAddress = location.pathname.startsWith('/p/') ? location.pathname.split('/')[2] : '';
const subplebbit = useSubplebbit({ subplebbitAddress });
const { address, shortAddress } = subplebbit || {};
return (
<div className={styles.wrapper}>
@@ -30,11 +32,11 @@ const NotFound = () => {
</div>
<div className={styles.boxContent}>
<NotFoundImage />
{subplebbitAddress && isValidSubplebbitAddress && (
{address && (
<>
<br />
<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>
</>
)}