mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(routing): handle empty boardPath and resolve directory codes
This commit is contained in:
@@ -45,7 +45,12 @@ const CatalogButton = ({ address, isInAllView, isInSubscriptionsView, isInModVie
|
|||||||
if (params?.timeFilterName) return `/mod/catalog/${params.timeFilterName}`;
|
if (params?.timeFilterName) return `/mod/catalog/${params.timeFilterName}`;
|
||||||
return `/mod/catalog`;
|
return `/mod/catalog`;
|
||||||
}
|
}
|
||||||
const boardPath = address ? getBoardPath(address, defaultSubplebbits) : defaultSubplebbits || '';
|
let boardPath = '';
|
||||||
|
if (address) {
|
||||||
|
boardPath = getBoardPath(address, defaultSubplebbits);
|
||||||
|
} else if (Array.isArray(defaultSubplebbits) && defaultSubplebbits.length > 0 && defaultSubplebbits[0]?.address) {
|
||||||
|
boardPath = getBoardPath(defaultSubplebbits[0].address, defaultSubplebbits);
|
||||||
|
}
|
||||||
return `/${boardPath}/catalog`;
|
return `/${boardPath}/catalog`;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -83,7 +88,12 @@ const ReturnButton = ({ address, isInAllView, isInSubscriptionsView, isInModView
|
|||||||
if (params?.timeFilterName) return `/mod/${params.timeFilterName}`;
|
if (params?.timeFilterName) return `/mod/${params.timeFilterName}`;
|
||||||
return `/mod`;
|
return `/mod`;
|
||||||
}
|
}
|
||||||
const boardPath = address ? getBoardPath(address, defaultSubplebbits) : defaultSubplebbits || '';
|
let boardPath = '';
|
||||||
|
if (address) {
|
||||||
|
boardPath = getBoardPath(address, defaultSubplebbits);
|
||||||
|
} else if (Array.isArray(defaultSubplebbits) && defaultSubplebbits.length > 0 && defaultSubplebbits[0]?.address) {
|
||||||
|
boardPath = getBoardPath(defaultSubplebbits[0].address, defaultSubplebbits);
|
||||||
|
}
|
||||||
return `/${boardPath}`;
|
return `/${boardPath}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -190,13 +190,15 @@ const Board = () => {
|
|||||||
(isInAllView || isInSubscriptionsView || isInModView) &&
|
(isInAllView || isInSubscriptionsView || isInModView) &&
|
||||||
showMorePostsSuggestion &&
|
showMorePostsSuggestion &&
|
||||||
monthlyFeed.length > feed.length &&
|
monthlyFeed.length > feed.length &&
|
||||||
(weeklyFeed.length > feed.length ? (
|
(() => {
|
||||||
|
const basePath = isInAllView ? '/all' : isInSubscriptionsView ? '/subscriptions' : isInModView ? '/mod' : boardPath ? `/${boardPath}` : '';
|
||||||
|
return weeklyFeed.length > feed.length ? (
|
||||||
<div className={styles.morePostsSuggestion}>
|
<div className={styles.morePostsSuggestion}>
|
||||||
<Trans
|
<Trans
|
||||||
i18nKey='more_threads_last_week'
|
i18nKey='more_threads_last_week'
|
||||||
values={{ currentTimeFilterName, count: feed.length }}
|
values={{ currentTimeFilterName, count: feed.length }}
|
||||||
components={{
|
components={{
|
||||||
1: <Link to={(isInAllView ? '/all' : isInSubscriptionsView ? '/subscriptions' : isInModView ? '/mod' : `/${boardPath}`) + '/1w'} />,
|
1: <Link to={`${basePath}/1w`} />,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -206,11 +208,12 @@ const Board = () => {
|
|||||||
i18nKey='more_threads_last_month'
|
i18nKey='more_threads_last_month'
|
||||||
values={{ currentTimeFilterName, count: feed.length }}
|
values={{ currentTimeFilterName, count: feed.length }}
|
||||||
components={{
|
components={{
|
||||||
1: <Link to={(isInAllView ? '/all' : isInSubscriptionsView ? '/subscriptions' : isInModView ? '/mod' : `/${boardPath}`) + '/1m'} />,
|
1: <Link to={`${basePath}/1m`} />,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
))
|
);
|
||||||
|
})()
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Link, useLocation } from 'react-router-dom';
|
import { Link, useLocation } from 'react-router-dom';
|
||||||
import useSubplebbitsStore from '@plebbit/plebbit-react-hooks/dist/stores/subplebbits';
|
import useSubplebbitsStore from '@plebbit/plebbit-react-hooks/dist/stores/subplebbits';
|
||||||
|
import { useDefaultSubplebbits } from '../../hooks/use-default-subplebbits';
|
||||||
|
import { getSubplebbitAddress } from '../../lib/utils/route-utils';
|
||||||
import { HomeLogo } from '../home';
|
import { HomeLogo } from '../home';
|
||||||
import styles from './not-found.module.css';
|
import styles from './not-found.module.css';
|
||||||
import { NOT_FOUND_IMAGES } from '../../generated/asset-manifest';
|
import { NOT_FOUND_IMAGES } from '../../generated/asset-manifest';
|
||||||
@@ -16,7 +18,8 @@ const NotFound = () => {
|
|||||||
// Extract boardIdentifier from pathname (could be directory code or address)
|
// Extract boardIdentifier from pathname (could be directory code or address)
|
||||||
const pathParts = location.pathname.split('/').filter(Boolean);
|
const pathParts = location.pathname.split('/').filter(Boolean);
|
||||||
const boardIdentifier = pathParts[0] && pathParts[0] !== 'not-found' && pathParts[0] !== 'faq' ? pathParts[0] : '';
|
const boardIdentifier = pathParts[0] && pathParts[0] !== 'not-found' && pathParts[0] !== 'faq' ? pathParts[0] : '';
|
||||||
const subplebbitAddress = boardIdentifier || '';
|
const defaultSubplebbits = useDefaultSubplebbits();
|
||||||
|
const subplebbitAddress = boardIdentifier ? getSubplebbitAddress(boardIdentifier, defaultSubplebbits) : '';
|
||||||
const subplebbit = useSubplebbitsStore((state) => state.subplebbits[subplebbitAddress]);
|
const subplebbit = useSubplebbitsStore((state) => state.subplebbits[subplebbitAddress]);
|
||||||
const { address, shortAddress } = subplebbit || {};
|
const { address, shortAddress } = subplebbit || {};
|
||||||
|
|
||||||
@@ -35,7 +38,7 @@ const NotFound = () => {
|
|||||||
<>
|
<>
|
||||||
<br />
|
<br />
|
||||||
<div className={styles.backToBoard}>
|
<div className={styles.backToBoard}>
|
||||||
[<Link to={`/${boardIdentifier || subplebbitAddress}`}>Back to p/{shortAddress}</Link>]
|
[<Link to={`/${boardIdentifier || subplebbitAddress}`}>Back to p/{shortAddress || subplebbitAddress}</Link>]
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user