2024-03-19 21:12:57 +01:00
|
|
|
import { useState } from 'react';
|
2024-05-17 14:55:41 +02:00
|
|
|
import { useLocation, useParams } from 'react-router-dom';
|
|
|
|
|
import { useAccountComment, useSubplebbit } from '@plebbit/plebbit-react-hooks';
|
|
|
|
|
import { isAllView, isSubscriptionsView } from '../../lib/utils/view-utils';
|
2024-05-29 21:00:13 +02:00
|
|
|
import styles from './board-header.module.css';
|
2024-05-17 14:55:41 +02:00
|
|
|
import { useMultisubMetadata } from '../../hooks/use-default-subplebbits';
|
2024-03-19 21:12:57 +01:00
|
|
|
|
2024-06-04 14:19:53 +02:00
|
|
|
const totalBanners = 59;
|
2024-03-19 21:12:57 +01:00
|
|
|
|
|
|
|
|
const ImageBanner = () => {
|
|
|
|
|
const [imagePath] = useState(() => {
|
|
|
|
|
const randomBannerIndex = Math.floor(Math.random() * totalBanners) + 1;
|
2024-05-29 15:53:41 +02:00
|
|
|
return `/assets/banners/banner-${randomBannerIndex}.jpg`;
|
2024-03-19 21:12:57 +01:00
|
|
|
});
|
|
|
|
|
|
2024-04-13 20:53:25 +02:00
|
|
|
return <img src={imagePath} alt='' />;
|
2024-03-19 21:12:57 +01:00
|
|
|
};
|
|
|
|
|
|
2024-05-29 21:00:13 +02:00
|
|
|
const BoardHeader = () => {
|
2024-05-17 14:55:41 +02:00
|
|
|
const location = useLocation();
|
2024-04-25 22:02:55 +02:00
|
|
|
const params = useParams();
|
2024-05-17 14:55:41 +02:00
|
|
|
|
2024-06-17 12:17:36 +02:00
|
|
|
const isInAllView = isAllView(location.pathname, params);
|
|
|
|
|
const isInSubscriptionsView = isSubscriptionsView(location.pathname, useParams());
|
2024-05-17 14:55:41 +02:00
|
|
|
|
2024-04-25 22:02:55 +02:00
|
|
|
const accountComment = useAccountComment({ commentIndex: params?.accountCommentIndex as any });
|
|
|
|
|
const subplebbitAddress = params?.subplebbitAddress || accountComment?.subplebbitAddress;
|
|
|
|
|
|
2024-04-08 17:13:02 +02:00
|
|
|
const subplebbit = useSubplebbit({ subplebbitAddress });
|
2024-05-29 16:13:14 +02:00
|
|
|
const { address, shortAddress } = subplebbit || {};
|
2024-05-17 14:55:41 +02:00
|
|
|
|
|
|
|
|
const multisubMetadata = useMultisubMetadata();
|
|
|
|
|
|
2024-06-09 16:40:32 +02:00
|
|
|
const title = isInAllView ? multisubMetadata?.title || 'all' : isInSubscriptionsView ? 'Subscriptions' : subplebbit?.title;
|
2024-05-29 16:13:14 +02:00
|
|
|
const subtitle = isInAllView ? 'p/all' : isInSubscriptionsView ? 'p/subscriptions' : `p/${address}`;
|
2024-04-08 17:13:02 +02:00
|
|
|
|
2024-06-08 21:22:17 +02:00
|
|
|
const isBoardOffline = subplebbit?.updatedAt && subplebbit.updatedAt < Date.now() / 1000 - 60 * 60;
|
|
|
|
|
|
2024-03-19 21:12:57 +01:00
|
|
|
return (
|
|
|
|
|
<div className={styles.content}>
|
|
|
|
|
<div className={styles.bannerCnt}>
|
2024-05-29 16:13:14 +02:00
|
|
|
<ImageBanner key={isInAllView ? 'all' : isInSubscriptionsView ? 'subscriptions' : address} />
|
2024-03-19 21:12:57 +01:00
|
|
|
</div>
|
2024-06-08 21:22:17 +02:00
|
|
|
<div className={styles.boardTitle}>
|
|
|
|
|
{title || `p/${shortAddress || subplebbitAddress}`}
|
|
|
|
|
{isBoardOffline && <span className={styles.offlineIcon} />}
|
|
|
|
|
</div>
|
2024-05-17 14:55:41 +02:00
|
|
|
<div className={styles.boardSubtitle}>{subtitle}</div>
|
2024-03-19 21:12:57 +01:00
|
|
|
<hr />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-29 21:00:13 +02:00
|
|
|
export default BoardHeader;
|