import { useTranslation } from 'react-i18next'; import { Link, useLocation, useParams } from 'react-router-dom'; import { useAccountComment, useSubscribe } from '@plebbit/plebbit-react-hooks'; import { isAllView, isCatalogView, isPendingPostView, isPostPageView, isSubscriptionsView } from '../../lib/utils/view-utils'; import useFeedResetStore from '../../stores/use-feed-reset-store'; import useSortingStore from '../../stores/use-sorting-store'; import styles from './board-buttons.module.css'; interface BoardButtonsProps { isInAllView?: boolean; address?: string | undefined; isInCatalogView?: boolean; isInSubscriptionsView?: boolean; } const OptionsButton = () => { const { t } = useTranslation(); return ; }; const CatalogButton = ({ address, isInAllView, isInSubscriptionsView }: BoardButtonsProps) => { const { t } = useTranslation(); const link = isInAllView ? `/p/all/catalog` : isInSubscriptionsView ? `/p/subscriptions/catalog` : `/p/${address}/catalog`; return ( ); }; const SubscribeButton = ({ address }: BoardButtonsProps) => { const { t } = useTranslation(); const { subscribed, subscribe, unsubscribe } = useSubscribe({ subplebbitAddress: address }); return ( ); }; const ReturnButton = ({ address, isInAllView, isInSubscriptionsView }: BoardButtonsProps) => { const { t } = useTranslation(); const link = isInAllView ? `/p/all` : isInSubscriptionsView ? `/p/subscriptions` : `/p/${address}`; return ( ); }; const RefreshButton = () => { const { t } = useTranslation(); const reset = useFeedResetStore((state) => state.reset); return ( ); }; const SortOptions = () => { const { sortType, setSortType } = useSortingStore(); const handleSortChange = (event: React.ChangeEvent) => { const type = event.target.value as 'active' | 'new'; setSortType(type); }; return ( <> Sort by:    ); }; export const MobileBoardButtons = () => { const params = useParams(); const location = useLocation(); const isInAllView = isAllView(location.pathname); const isInCatalogView = isCatalogView(location.pathname); const isInPendingPostPage = isPendingPostView(location.pathname, params); const isInPostView = isPostPageView(location.pathname, params); const isInSubscriptionsView = isSubscriptionsView(location.pathname); const accountComment = useAccountComment({ commentIndex: params?.accountCommentIndex as any }); const subplebbitAddress = params?.subplebbitAddress || accountComment?.subplebbitAddress; return (
{isInPostView || isInPendingPostPage ? ( <> ) : ( <> {isInCatalogView ? ( ) : ( )} {isInCatalogView && ( <>
)} )}
); }; export const DesktopBoardButtons = () => { const params = useParams(); const location = useLocation(); const accountComment = useAccountComment({ commentIndex: params?.accountCommentIndex as any }); const subplebbitAddress = params?.subplebbitAddress || accountComment?.subplebbitAddress; const isInCatalogView = isCatalogView(location.pathname); const isInAllView = isAllView(location.pathname); const isInPendingPostPage = isPendingPostView(location.pathname, params); const isInPostView = isPostPageView(location.pathname, params); const isInSubscriptionsView = isSubscriptionsView(location.pathname); return ( <>
{isInPostView || isInPendingPostPage ? ( <> [ ] [ ] [ ] {isInPostView && ( [ ] )} ) : ( <> {isInCatalogView ? ( <> [ ]{' '} ) : ( <> [ ]{' '} )} [ ] [ ] {isInCatalogView && } {!(isInAllView || isInSubscriptionsView) && ( <> [ ] )} )}
); };