Files
5chan/src/components/board-header/board-header.tsx
T

65 lines
2.7 KiB
TypeScript
Raw Normal View History

2024-03-19 21:12:57 +01:00
import { useState } from 'react';
import { useLocation, useParams } from 'react-router-dom';
import { useAccountComment, useSubplebbit } from '@plebbit/plebbit-react-hooks';
import { isAllView, isSubscriptionsView } from '../../lib/utils/view-utils';
import styles from './board-header.module.css';
import { useMultisubMetadata } from '../../hooks/use-default-subplebbits';
2024-06-30 11:47:09 +02:00
import useIsMobile from '../../hooks/use-is-mobile';
import useIsSubplebbitOffline from '../../hooks/use-is-subplebbit-offline';
2024-12-24 17:13:12 +01:00
import { shouldShowSnow } from '../../lib/snow';
2025-02-21 17:31:16 +01:00
import Tooltip from '../tooltip';
2024-03-19 21:12:57 +01:00
2024-12-15 15:07:31 +01:00
const totalBanners = 61;
2024-03-19 21:12:57 +01:00
const ImageBanner = () => {
const [imagePath] = useState(() => {
const randomBannerIndex = Math.floor(Math.random() * totalBanners) + 1;
2024-06-20 17:02:11 +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
};
const BoardHeader = () => {
const location = useLocation();
2024-04-25 22:02:55 +02:00
const params = useParams();
2024-10-29 17:40:09 +01:00
const isInAllView = isAllView(location.pathname);
const isInSubscriptionsView = isSubscriptionsView(location.pathname, useParams());
2024-04-25 22:02:55 +02:00
const accountComment = useAccountComment({ commentIndex: params?.accountCommentIndex as any });
const subplebbitAddress = params?.subplebbitAddress || accountComment?.subplebbitAddress;
const subplebbit = useSubplebbit({ subplebbitAddress });
const { address, shortAddress } = subplebbit || {};
const multisubMetadata = useMultisubMetadata();
const title = isInAllView ? multisubMetadata?.title || 'all' : isInSubscriptionsView ? 'Subscriptions' : subplebbit?.title;
const subtitle = isInAllView ? 'p/all' : isInSubscriptionsView ? 'p/subscriptions' : `p/${address}`;
const { isOffline, isOnlineStatusLoading, offlineIconClass, offlineTitle } = useIsSubplebbitOffline(subplebbit);
2024-03-19 21:12:57 +01:00
return (
2024-12-24 17:13:12 +01:00
<div className={`${styles.content} ${shouldShowSnow() ? styles.garland : ''}`}>
2024-06-30 11:47:09 +02:00
{!useIsMobile() && (
<div className={styles.bannerCnt}>
<ImageBanner key={isInAllView ? 'all' : isInSubscriptionsView ? 'subscriptions' : address} />
</div>
)}
<div className={styles.boardTitle}>
{title || (shortAddress ? (shortAddress.endsWith('.eth') || shortAddress.endsWith('.sol') ? shortAddress.slice(0, -4) : shortAddress) : subplebbitAddress)}
{(isOffline || isOnlineStatusLoading) && !isInAllView && !isInSubscriptionsView && (
2025-02-21 17:31:16 +01:00
<span className={styles.offlineIconWrapper}>
<Tooltip content={offlineTitle}>
<span className={`${styles.offlineIcon} ${offlineIconClass}`} />
</Tooltip>
</span>
)}
</div>
<div className={styles.boardSubtitle}>{subtitle}</div>
2024-03-19 21:12:57 +01:00
<hr />
</div>
);
};
export default BoardHeader;