2024-03-19 21:12:57 +01:00
|
|
|
import { useState } from 'react';
|
2025-06-04 16:37:17 +02:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-05-17 14:55:41 +02:00
|
|
|
import { useLocation, useParams } from 'react-router-dom';
|
2025-03-06 13:15:33 +01:00
|
|
|
import { useAccountComment } from '@plebbit/plebbit-react-hooks';
|
2025-06-04 14:54:11 +02:00
|
|
|
import Plebbit from '@plebbit/plebbit-js';
|
2025-03-06 13:15:33 +01:00
|
|
|
import useSubplebbitsStore from '@plebbit/plebbit-react-hooks/dist/stores/subplebbits';
|
2025-03-05 17:38:34 +01:00
|
|
|
import { isAllView, isSubscriptionsView, isModView } 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';
|
2025-06-04 16:37:17 +02:00
|
|
|
import _ from 'lodash';
|
2025-11-01 19:39:22 +01:00
|
|
|
import { BANNERS } from '../../generated/asset-manifest';
|
2024-03-19 21:12:57 +01:00
|
|
|
|
|
|
|
|
const ImageBanner = () => {
|
2025-11-01 19:39:22 +01:00
|
|
|
const [banner] = useState(() => BANNERS[Math.floor(Math.random() * BANNERS.length)]);
|
2024-03-19 21:12:57 +01:00
|
|
|
|
2025-11-01 16:46:51 +01:00
|
|
|
return <img src={banner} alt='' />;
|
2024-03-19 21:12:57 +01:00
|
|
|
};
|
|
|
|
|
|
2024-05-29 21:00:13 +02:00
|
|
|
const BoardHeader = () => {
|
2025-06-04 16:37:17 +02:00
|
|
|
const { t } = useTranslation();
|
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());
|
2025-03-05 17:38:34 +01:00
|
|
|
const isInModView = isModView(location.pathname);
|
2024-04-25 22:02:55 +02:00
|
|
|
const accountComment = useAccountComment({ commentIndex: params?.accountCommentIndex as any });
|
|
|
|
|
const subplebbitAddress = params?.subplebbitAddress || accountComment?.subplebbitAddress;
|
|
|
|
|
|
2025-03-06 13:15:33 +01:00
|
|
|
const subplebbit = useSubplebbitsStore((state) => state.subplebbits[subplebbitAddress]);
|
|
|
|
|
|
2024-07-07 20:02:58 +02:00
|
|
|
const { address, shortAddress } = subplebbit || {};
|
2024-05-17 14:55:41 +02:00
|
|
|
|
|
|
|
|
const multisubMetadata = useMultisubMetadata();
|
2025-06-04 16:37:17 +02:00
|
|
|
const title = isInAllView
|
|
|
|
|
? multisubMetadata?.title || 'all'
|
|
|
|
|
: isInSubscriptionsView
|
|
|
|
|
? 'Subscriptions'
|
|
|
|
|
: isInModView
|
|
|
|
|
? _.startCase(t('boards_you_moderate'))
|
|
|
|
|
: subplebbit?.title;
|
2025-03-05 17:38:34 +01:00
|
|
|
const subtitle = isInAllView ? 'p/all' : isInSubscriptionsView ? 'p/subscriptions' : isInModView ? 'p/mod' : `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}>
|
2025-02-24 12:21:59 +01:00
|
|
|
<ImageBanner key={isInAllView ? 'all' : isInSubscriptionsView ? 'subscriptions' : subplebbitAddress} />
|
2024-06-30 11:47:09 +02:00
|
|
|
</div>
|
|
|
|
|
)}
|
2024-06-08 21:22:17 +02:00
|
|
|
<div className={styles.boardTitle}>
|
2025-06-04 14:54:11 +02:00
|
|
|
{title ||
|
|
|
|
|
(shortAddress
|
|
|
|
|
? shortAddress.endsWith('.eth') || shortAddress.endsWith('.sol')
|
|
|
|
|
? shortAddress.slice(0, -4)
|
|
|
|
|
: shortAddress
|
2025-06-12 17:51:08 +02:00
|
|
|
: subplebbitAddress && Plebbit.getShortAddress(subplebbitAddress))}
|
2025-03-05 17:38:34 +01:00
|
|
|
{(isOffline || isOnlineStatusLoading) && !isInAllView && !isInSubscriptionsView && !isInModView && (
|
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;
|