2024-03-20 15:12:19 +01:00
|
|
|
import { useState } from 'react';
|
|
|
|
|
import { useSubplebbitStats } from '@plebbit/plebbit-react-hooks';
|
|
|
|
|
import styles from './board-stats.module.css';
|
2024-03-20 16:58:22 +01:00
|
|
|
import { Trans, useTranslation } from 'react-i18next';
|
2024-03-20 15:12:19 +01:00
|
|
|
|
|
|
|
|
export interface BoardStatsProps {
|
|
|
|
|
address: string | undefined;
|
2024-03-22 15:31:02 +01:00
|
|
|
createdAt: number | undefined;
|
2024-03-20 15:12:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const BoardStats = ({ address, createdAt }: BoardStatsProps) => {
|
2024-03-20 16:58:22 +01:00
|
|
|
const { t } = useTranslation();
|
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 (
|
|
|
|
|
<div className={styles.content}>
|
|
|
|
|
<table className={styles.blotter}>
|
2024-03-20 17:22:22 +01:00
|
|
|
<hr />
|
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;
|