mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat(board stats): remember hide/show choice per subplebbit
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import { useState } from 'react';
|
|
||||||
import { useLocation, useParams } from 'react-router-dom';
|
import { useLocation, useParams } from 'react-router-dom';
|
||||||
import { useAccountComment, useComment, useSubplebbit, useSubplebbitStats } from '@plebbit/plebbit-react-hooks';
|
|
||||||
import styles from './subplebbit-stats.module.css';
|
|
||||||
import { Trans, useTranslation } from 'react-i18next';
|
import { Trans, useTranslation } from 'react-i18next';
|
||||||
|
import { useAccountComment, useComment, useSubplebbit, useSubplebbitStats } from '@plebbit/plebbit-react-hooks';
|
||||||
|
import useSubplebbitStatsVisibilityStore from '../../stores/use-subplebbit-stats-visibility-store';
|
||||||
import { isDescriptionView, isRulesView } from '../../lib/utils/view-utils';
|
import { isDescriptionView, isRulesView } from '../../lib/utils/view-utils';
|
||||||
|
import styles from './subplebbit-stats.module.css';
|
||||||
|
|
||||||
const SubplebbitStats = () => {
|
const SubplebbitStats = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -16,7 +16,8 @@ const SubplebbitStats = () => {
|
|||||||
const { address, createdAt } = subplebbit || {};
|
const { address, createdAt } = subplebbit || {};
|
||||||
|
|
||||||
const stats = useSubplebbitStats({ subplebbitAddress: address });
|
const stats = useSubplebbitStats({ subplebbitAddress: address });
|
||||||
const [showStats, setShowStats] = useState(true);
|
const { hiddenStats, toggleVisibility } = useSubplebbitStatsVisibilityStore();
|
||||||
|
const isHidden = hiddenStats[address];
|
||||||
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const isInDescriptionView = isDescriptionView(location.pathname, params);
|
const isInDescriptionView = isDescriptionView(location.pathname, params);
|
||||||
@@ -44,7 +45,7 @@ const SubplebbitStats = () => {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{showStats && (
|
{!isHidden && (
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
@@ -93,8 +94,8 @@ const SubplebbitStats = () => {
|
|||||||
<tr>
|
<tr>
|
||||||
<td colSpan={2}>
|
<td colSpan={2}>
|
||||||
[
|
[
|
||||||
<span className={styles.hideButton} onClick={() => setShowStats(!showStats)}>
|
<span className={styles.hideButton} onClick={() => toggleVisibility(address)}>
|
||||||
{showStats ? t('hide') : t('show_stats')}
|
{isHidden ? t('show_stats') : t('hide')}
|
||||||
</span>
|
</span>
|
||||||
]
|
]
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import { create } from 'zustand';
|
||||||
|
import { persist } from 'zustand/middleware';
|
||||||
|
|
||||||
|
interface SubplebbitStatsVisibilityState {
|
||||||
|
hiddenStats: { [subplebbitAddress: string]: boolean };
|
||||||
|
toggleVisibility: (subplebbitAddress: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const useSubplebbitStatsVisibilityStore = create<SubplebbitStatsVisibilityState>()(
|
||||||
|
persist(
|
||||||
|
(set) => ({
|
||||||
|
hiddenStats: {},
|
||||||
|
toggleVisibility: (subplebbitAddress) =>
|
||||||
|
set((state) => ({
|
||||||
|
hiddenStats: {
|
||||||
|
...state.hiddenStats,
|
||||||
|
[subplebbitAddress]: !state.hiddenStats[subplebbitAddress],
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
name: 'subplebbit-stats-visibility',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
export default useSubplebbitStatsVisibilityStore;
|
||||||
Reference in New Issue
Block a user