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-06-30 11:47:09 +02:00
|
|
|
import useIsMobile from '../../hooks/use-is-mobile';
|
2024-07-07 20:02:58 +02:00
|
|
|
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
|
|
|
|
2025-02-24 12:18:02 +01:00
|
|
|
const totalBanners = 62;
|
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
|
|
|
};
|
|
|
|
|
|
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-10-29 17:40:09 +01:00
|
|
|
const isInAllView = isAllView(location.pathname);
|
2024-06-17 12:17:36 +02:00
|
|
|
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-07-07 20:02:58 +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-07-09 14:59:18 +02:00
|
|
|
const { isOffline, isOnlineStatusLoading, offlineIconClass, offlineTitle } = useIsSubplebbitOffline(subplebbit);
|
2024-06-08 21:22:17 +02:00
|
|
|
|
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>
|
|
|
|
|
)}
|
2024-06-08 21:22:17 +02:00
|
|
|
<div className={styles.boardTitle}>
|
2024-11-02 18:42:52 +01:00
|
|
|
{title || (shortAddress ? (shortAddress.endsWith('.eth') || shortAddress.endsWith('.sol') ? shortAddress.slice(0, -4) : shortAddress) : subplebbitAddress)}
|
2024-07-23 09:01:03 +02:00
|
|
|
{(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>
|
2024-07-23 09:01:03 +02:00
|
|
|
)}
|
2024-06-08 21:22:17 +02:00
|
|
|
</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;
|