import { useState } from 'react'; import { useLocation, useParams } from 'react-router-dom'; import { useComment, useSubplebbit, useSubplebbitStats } from '@plebbit/plebbit-react-hooks'; import styles from './subplebbit-stats.module.css'; import { Trans, useTranslation } from 'react-i18next'; import { isDescriptionView, isRulesView } from '../../lib/utils/view-utils'; const SubplebbitStats = () => { const { t } = useTranslation(); const { commentCid, subplebbitAddress } = useParams<{ subplebbitAddress: string; commentCid: string }>(); const subplebbit = useSubplebbit({ subplebbitAddress }); const { address, createdAt } = subplebbit || {}; const location = useLocation(); const params = useParams(); const isInDescriptionView = isDescriptionView(location.pathname, params); const isInRulesView = isRulesView(location.pathname, params); const comment = useComment({ commentCid }); const { deleted, locked, removed } = comment || {}; const hideStats = deleted || locked || removed || isInDescriptionView || isInRulesView; const stats = useSubplebbitStats({ subplebbitAddress: address }); const [showStats, setShowStats] = useState(true); const unixToMMDDYYYY = (timestamp: number) => { const date = new Date(timestamp * 1000); const month = ('0' + (date.getMonth() + 1)).slice(-2); const day = ('0' + date.getDate()).slice(-2); const year = date.getFullYear().toString().slice(-2); return month + '/' + day + '/' + year; }; return (
{showStats && ( )}

}} /> {' / '} }} />
}} /> {' / '} }} />
{createdAt && unixToMMDDYYYY(createdAt)} {t('board_created')} {' / '} }} />
[ setShowStats(!showStats)}> {showStats ? t('hide') : t('show_stats')} ]
); }; export default SubplebbitStats;