2024-04-03 22:52:27 +02:00
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
import { Link, useLocation, useParams } from 'react-router-dom';
|
2024-03-22 12:09:17 +01:00
|
|
|
import { useSubscribe } from '@plebbit/plebbit-react-hooks';
|
|
|
|
|
import styles from './board-buttons.module.css';
|
2024-04-12 17:47:30 +02:00
|
|
|
import { isCatalogView, isPostPageView } from '../../lib/utils/view-utils';
|
2024-03-22 12:09:17 +01:00
|
|
|
|
|
|
|
|
interface BoardButtonsProps {
|
2024-04-08 17:13:02 +02:00
|
|
|
address: string | undefined;
|
2024-04-12 17:47:30 +02:00
|
|
|
isInCatalogView?: boolean;
|
2024-03-22 12:09:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const OptionsButton = () => {
|
2024-03-22 12:22:20 +01:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
return <button className='button'>{t('options')}</button>;
|
2024-03-22 12:09:17 +01:00
|
|
|
};
|
|
|
|
|
|
2024-04-12 17:47:30 +02:00
|
|
|
const CatalogButton = ({ address, isInCatalogView }: BoardButtonsProps) => {
|
2024-03-22 12:22:20 +01:00
|
|
|
const { t } = useTranslation();
|
2024-04-03 22:52:27 +02:00
|
|
|
return (
|
|
|
|
|
<button className='button'>
|
2024-04-12 17:47:30 +02:00
|
|
|
<Link to={isInCatalogView ? `/p/${address}` : `/p/${address}/catalog`}>{t(isInCatalogView ? 'return' : 'catalog')}</Link>
|
2024-04-03 22:52:27 +02:00
|
|
|
</button>
|
|
|
|
|
);
|
2024-03-22 12:09:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const SubscribeButton = ({ address }: BoardButtonsProps) => {
|
2024-03-22 12:22:20 +01:00
|
|
|
const { t } = useTranslation();
|
2024-03-22 12:09:17 +01:00
|
|
|
const { subscribed, subscribe, unsubscribe } = useSubscribe({ subplebbitAddress: address });
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<button className='button' onClick={subscribed ? unsubscribe : subscribe}>
|
2024-03-22 12:22:20 +01:00
|
|
|
{subscribed ? t('unsubscribe') : t('subscribe')}
|
2024-03-22 12:09:17 +01:00
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-03 22:52:27 +02:00
|
|
|
const ReturnButton = ({ address }: BoardButtonsProps) => {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
return (
|
|
|
|
|
<button className='button'>
|
|
|
|
|
<Link to={`/p/${address}`}>{t('return')}</Link>
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const BottomButton = () => {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
return (
|
|
|
|
|
<button className='button' onClick={() => window.scrollTo(0, document.body.scrollHeight)}>
|
|
|
|
|
{t('bottom')}
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-08 17:13:02 +02:00
|
|
|
export const MobileBoardButtons = () => {
|
|
|
|
|
const { subplebbitAddress: address } = useParams<{ subplebbitAddress: string }>();
|
2024-04-03 22:52:27 +02:00
|
|
|
const isInPostPage = isPostPageView(useLocation().pathname, useParams());
|
2024-03-22 12:09:17 +01:00
|
|
|
return (
|
|
|
|
|
<div className={styles.mobileBoardButtons}>
|
2024-04-03 22:52:27 +02:00
|
|
|
{isInPostPage ? (
|
|
|
|
|
<div className={styles.mobilePostPageButtons}>
|
|
|
|
|
<ReturnButton address={address} />
|
|
|
|
|
<CatalogButton address={address} />
|
|
|
|
|
<BottomButton />
|
2024-04-04 12:06:37 +02:00
|
|
|
<div className={styles.mobilePostPageButtonsSecondRow}>
|
2024-04-03 22:52:27 +02:00
|
|
|
<OptionsButton />
|
|
|
|
|
<SubscribeButton address={address} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<OptionsButton />
|
|
|
|
|
<CatalogButton address={address} />
|
|
|
|
|
<SubscribeButton address={address} />
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2024-03-22 12:09:17 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-08 17:13:02 +02:00
|
|
|
export const DesktopBoardButtons = () => {
|
|
|
|
|
const { subplebbitAddress: address } = useParams<{ subplebbitAddress: string }>();
|
2024-04-12 17:47:30 +02:00
|
|
|
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
const params = useParams();
|
|
|
|
|
const isInPostPage = isPostPageView(location.pathname, params);
|
|
|
|
|
const isInCatalogView = isCatalogView(location.pathname, params);
|
|
|
|
|
|
2024-03-22 12:09:17 +01:00
|
|
|
return (
|
|
|
|
|
<div className={styles.desktopBoardButtons}>
|
2024-03-22 13:03:04 +01:00
|
|
|
<hr />
|
2024-04-03 22:52:27 +02:00
|
|
|
{isInPostPage ? (
|
|
|
|
|
<>
|
2024-04-12 17:47:30 +02:00
|
|
|
[<ReturnButton address={address} />] [<CatalogButton address={address} isInCatalogView={isInCatalogView} />] [<BottomButton />] [<OptionsButton />]
|
2024-04-03 22:52:27 +02:00
|
|
|
<span className={styles.subscribeButton}>
|
|
|
|
|
[<SubscribeButton address={address} />]
|
|
|
|
|
</span>
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
2024-04-12 17:47:30 +02:00
|
|
|
[<OptionsButton />] [<CatalogButton address={address} isInCatalogView={isInCatalogView} />]
|
2024-04-03 22:52:27 +02:00
|
|
|
<span className={styles.subscribeButton}>
|
|
|
|
|
[<SubscribeButton address={address} />]
|
|
|
|
|
</span>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2024-03-22 12:09:17 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|