2024-04-08 18:09:25 +02:00
|
|
|
import { Link, useNavigate, useParams } from 'react-router-dom';
|
2024-03-20 21:35:53 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-03-27 15:10:58 +01:00
|
|
|
import { Subplebbit } from '@plebbit/plebbit-react-hooks';
|
2024-03-19 13:18:12 +01:00
|
|
|
import styles from './board-nav.module.css';
|
|
|
|
|
|
|
|
|
|
interface BoardNavProps {
|
2024-03-27 15:10:58 +01:00
|
|
|
subplebbits: (Subplebbit | undefined)[];
|
2024-03-19 13:18:12 +01:00
|
|
|
currentSubplebbit?: string | undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const BoardNavDesktop = ({ subplebbits }: BoardNavProps) => {
|
2024-03-20 21:35:53 +01:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
2024-03-19 13:18:12 +01:00
|
|
|
return (
|
|
|
|
|
<div className={styles.boardNavDesktop}>
|
2024-03-20 21:35:53 +01:00
|
|
|
<span className={styles.boardList}>
|
|
|
|
|
[
|
2024-03-27 15:10:58 +01:00
|
|
|
{subplebbits.map((subplebbit: any, index: number) => {
|
2024-03-28 09:31:28 +01:00
|
|
|
const address = subplebbit?.address || '';
|
|
|
|
|
const title = subplebbit?.title || '';
|
2024-03-27 15:10:58 +01:00
|
|
|
return (
|
2024-03-28 09:31:28 +01:00
|
|
|
<span key={index}>
|
2024-03-27 15:10:58 +01:00
|
|
|
{index === 0 ? null : ' '}
|
|
|
|
|
<Link to={`/p/${address}`} title={title || ''}>
|
|
|
|
|
{address.includes('.') ? address : title || address.slice(0, 10).concat('...')}
|
|
|
|
|
</Link>
|
|
|
|
|
{index !== subplebbits.length - 1 ? ' /' : null}
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2024-03-20 21:35:53 +01:00
|
|
|
]
|
|
|
|
|
</span>
|
|
|
|
|
<span className={styles.navTopRight}>
|
2024-03-21 22:16:24 +01:00
|
|
|
[<Link to='/settings'>{t('settings')}</Link>] [<Link to='/'>{t('home')}</Link>]
|
2024-03-20 21:35:53 +01:00
|
|
|
</span>
|
2024-03-19 13:18:12 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const BoardNavMobile = ({ subplebbits, currentSubplebbit }: BoardNavProps) => {
|
2024-03-22 12:22:20 +01:00
|
|
|
const { t } = useTranslation();
|
2024-03-19 13:18:12 +01:00
|
|
|
const navigate = useNavigate();
|
2024-03-26 20:45:41 +01:00
|
|
|
const displaySubplebbitAddress = currentSubplebbit && currentSubplebbit.length > 30 ? currentSubplebbit.slice(0, 30).concat('...') : currentSubplebbit;
|
|
|
|
|
|
2024-03-28 17:21:27 +01:00
|
|
|
const currentSubplebbitIsInList = subplebbits.some((subplebbit: any) => subplebbit?.address === currentSubplebbit);
|
2024-03-19 13:18:12 +01:00
|
|
|
|
2024-03-19 14:43:25 +01:00
|
|
|
const boardSelect = (
|
2024-03-26 20:45:41 +01:00
|
|
|
<select value={currentSubplebbit || 'all'} onChange={(e) => navigate(`/p/${e.target.value}`)}>
|
|
|
|
|
{!currentSubplebbitIsInList && currentSubplebbit && <option value={currentSubplebbit}>{displaySubplebbitAddress}</option>}
|
2024-03-26 16:08:06 +01:00
|
|
|
<option value='all'>{t('all')}</option>
|
|
|
|
|
<option value='subscriptions'>{t('subscriptions')}</option>
|
2024-03-26 18:08:50 +01:00
|
|
|
{subplebbits.map((subplebbit: any, index: number) => {
|
2024-03-28 09:31:28 +01:00
|
|
|
const address = subplebbit?.address || '';
|
|
|
|
|
const title = subplebbit?.title || '';
|
|
|
|
|
const subplebbitAddress = address?.includes('.') ? address : title || address?.slice(0, 10).concat('...');
|
2024-03-26 18:08:50 +01:00
|
|
|
return (
|
2024-03-28 09:31:28 +01:00
|
|
|
<option key={index} value={address}>
|
2024-03-26 18:08:50 +01:00
|
|
|
{subplebbitAddress}
|
|
|
|
|
</option>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2024-03-19 14:43:25 +01:00
|
|
|
</select>
|
|
|
|
|
);
|
|
|
|
|
|
2024-03-19 13:18:12 +01:00
|
|
|
return (
|
|
|
|
|
<div className={styles.boardNavMobile}>
|
|
|
|
|
<div className={styles.boardSelect}>
|
2024-03-22 12:22:20 +01:00
|
|
|
<strong>{t('board')}</strong>
|
2024-03-19 14:43:25 +01:00
|
|
|
{boardSelect}
|
|
|
|
|
</div>
|
|
|
|
|
<div className={styles.pageJump}>
|
2024-03-22 12:22:20 +01:00
|
|
|
<Link to='settings'>{t('settings')}</Link>
|
|
|
|
|
<Link to='/'>{t('home')}</Link>
|
2024-03-19 13:18:12 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-08 18:09:25 +02:00
|
|
|
const BoardNav = ({ subplebbits }: BoardNavProps) => {
|
|
|
|
|
const { subplebbitAddress: address } = useParams();
|
2024-03-19 13:18:12 +01:00
|
|
|
return (
|
|
|
|
|
<>
|
2024-03-27 15:10:58 +01:00
|
|
|
<BoardNavDesktop subplebbits={subplebbits} />
|
|
|
|
|
<BoardNavMobile subplebbits={subplebbits} currentSubplebbit={address} />
|
2024-03-19 13:18:12 +01:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default BoardNav;
|