2024-03-20 15:12:19 +01:00
|
|
|
import { useState } from 'react';
|
2024-04-08 17:32:12 +02:00
|
|
|
import { useLocation, useParams } from 'react-router-dom';
|
2024-04-08 17:13:02 +02:00
|
|
|
import { useComment, useSubplebbit, useSubplebbitStats } from '@plebbit/plebbit-react-hooks';
|
2024-03-20 15:12:19 +01:00
|
|
|
import styles from './board-stats.module.css';
|
2024-03-20 16:58:22 +01:00
|
|
|
import { Trans, useTranslation } from 'react-i18next';
|
2024-04-08 17:32:12 +02:00
|
|
|
import { isDescriptionView, isRulesView } from '../../lib/utils/view-utils';
|
2024-03-20 15:12:19 +01:00
|
|
|
|
2024-04-08 17:13:02 +02:00
|
|
|
const BoardStats = () => {
|
2024-03-20 16:58:22 +01:00
|
|
|
const { t } = useTranslation();
|
2024-04-08 17:13:02 +02:00
|
|
|
const { commentCid, subplebbitAddress } = useParams<{ subplebbitAddress: string; commentCid: string }>();
|
|
|
|
|
|
|
|
|
|
const subplebbit = useSubplebbit({ subplebbitAddress });
|
|
|
|
|
const { address, createdAt } = subplebbit || {};
|
|
|
|
|
|
2024-04-08 17:32:12 +02:00
|
|
|
const location = useLocation();
|
|
|
|
|
const params = useParams();
|
|
|
|
|
const isInDescriptionView = isDescriptionView(location.pathname, params);
|
|
|
|
|
const isInRulesView = isRulesView(location.pathname, params);
|
|
|
|
|
|
2024-04-08 17:13:02 +02:00
|
|
|
const comment = useComment({ commentCid });
|
|
|
|
|
const { deleted, locked, removed } = comment || {};
|
2024-04-08 17:32:12 +02:00
|
|
|
const hideStats = deleted || locked || removed || isInDescriptionView || isInRulesView;
|
2024-04-08 17:13:02 +02:00
|
|
|
|
2024-03-20 15:12:19 +01:00
|
|
|
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 (
|
2024-04-08 17:13:02 +02:00
|
|
|
<div className={`${styles.content} ${hideStats ? styles.hide : styles.show}`}>
|
2024-03-20 15:12:19 +01:00
|
|
|
<table className={styles.blotter}>
|
2024-03-26 21:12:29 +01:00
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>
|
|
|
|
|
<hr />
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
2024-03-20 15:12:19 +01:00
|
|
|
{showStats && (
|
2024-03-20 21:35:53 +01:00
|
|
|
<tbody>
|
2024-03-20 15:12:19 +01:00
|
|
|
<tr>
|
|
|
|
|
<td>
|
2024-03-20 16:58:22 +01:00
|
|
|
<Trans
|
|
|
|
|
i18nKey='board_stats_hour'
|
|
|
|
|
values={{ userCount: stats.hourActiveUserCount, postCount: stats.hourPostCount }}
|
|
|
|
|
components={{ 1: <span className={styles.statValue} /> }}
|
|
|
|
|
/>
|
|
|
|
|
{' / '}
|
|
|
|
|
<Trans
|
|
|
|
|
i18nKey='board_stats_day'
|
|
|
|
|
values={{ userCount: stats.dayActiveUserCount, postCount: stats.dayPostCount }}
|
|
|
|
|
components={{ 1: <span className={styles.statValue} /> }}
|
|
|
|
|
/>
|
2024-03-20 15:12:19 +01:00
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>
|
2024-03-20 16:58:22 +01:00
|
|
|
<Trans
|
|
|
|
|
i18nKey='board_stats_week'
|
|
|
|
|
values={{ userCount: stats.weekActiveUserCount, postCount: stats.weekPostCount }}
|
|
|
|
|
components={{ 1: <span className={styles.statValue} /> }}
|
|
|
|
|
/>
|
|
|
|
|
{' / '}
|
|
|
|
|
<Trans
|
|
|
|
|
i18nKey='board_stats_month'
|
|
|
|
|
values={{ userCount: stats.monthActiveUserCount, postCount: stats.monthPostCount }}
|
|
|
|
|
components={{ 1: <span className={styles.statValue} /> }}
|
|
|
|
|
/>
|
2024-03-20 15:12:19 +01:00
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2024-03-20 16:58:22 +01:00
|
|
|
<td className={styles.lowercase}>
|
2024-03-22 15:31:02 +01:00
|
|
|
{createdAt && unixToMMDDYYYY(createdAt)} {t('board_created')}
|
2024-03-20 16:58:22 +01:00
|
|
|
{' / '}
|
|
|
|
|
<Trans
|
|
|
|
|
i18nKey='board_stats_all'
|
|
|
|
|
values={{ userCount: stats.allActiveUserCount, postCount: stats.allPostCount }}
|
|
|
|
|
components={{ 1: <span className={styles.statValue} /> }}
|
|
|
|
|
/>
|
2024-03-20 15:12:19 +01:00
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</tbody>
|
|
|
|
|
)}
|
|
|
|
|
<tfoot>
|
|
|
|
|
<tr>
|
|
|
|
|
<td colSpan={2}>
|
|
|
|
|
[
|
|
|
|
|
<span className={styles.hideButton} onClick={() => setShowStats(!showStats)}>
|
2024-03-20 16:58:22 +01:00
|
|
|
{showStats ? t('hide') : t('show_stats')}
|
2024-03-20 15:12:19 +01:00
|
|
|
</span>
|
|
|
|
|
]
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</tfoot>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default BoardStats;
|