mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat: add "hidden threads" counter and button in catalog and board view, store and hook
This commit is contained in:
@@ -17,6 +17,15 @@
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
.showBlockedButton {
|
||||
color: var(--button-desktop-text-color);
|
||||
}
|
||||
|
||||
.showBlockedButton:hover {
|
||||
color: var(--button-desktop-text-color-hover);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.desktopBoardButtons {
|
||||
display: none;
|
||||
|
||||
@@ -3,10 +3,12 @@ import { Link, useLocation, useParams } from 'react-router-dom';
|
||||
import { useAccountComment, useSubscribe } from '@plebbit/plebbit-react-hooks';
|
||||
import styles from './board-buttons.module.css';
|
||||
import { isAllView, isCatalogView, isPendingPostView, isPostPageView, isSubscriptionsView } from '../../lib/utils/view-utils';
|
||||
import useBlockedComments from '../../hooks/use-blocked-comments';
|
||||
import useBlockedCommentsStore from '../../stores/useBlockedCommentsStore';
|
||||
|
||||
interface BoardButtonsProps {
|
||||
isInAllView?: boolean;
|
||||
address: string | undefined;
|
||||
address?: string | undefined;
|
||||
isInCatalogView?: boolean;
|
||||
isInSubscriptionsView?: boolean;
|
||||
}
|
||||
@@ -105,6 +107,9 @@ export const DesktopBoardButtons = () => {
|
||||
const isInPostView = isPostPageView(location.pathname, params);
|
||||
const isInSubscriptionsView = isSubscriptionsView(location.pathname);
|
||||
|
||||
const { showBlockedComments, setShowBlockedComments } = useBlockedCommentsStore();
|
||||
const blockedComments = useBlockedComments(params?.subplebbitAddress);
|
||||
|
||||
return (
|
||||
<div className={styles.desktopBoardButtons}>
|
||||
<hr />
|
||||
@@ -120,6 +125,16 @@ export const DesktopBoardButtons = () => {
|
||||
<>
|
||||
[<OptionsButton />] [
|
||||
<CatalogButton address={subplebbitAddress} isInAllView={isInAllView} isInCatalogView={isInCatalogView} isInSubscriptionsView={isInSubscriptionsView} />]
|
||||
{blockedComments?.length > 0 && (
|
||||
<span className={styles.blockedAddresses}>
|
||||
{' '}
|
||||
— Hidden threads: <strong>{blockedComments.length}</strong> [
|
||||
<span className={styles.showBlockedButton} onClick={() => setShowBlockedComments(!showBlockedComments)}>
|
||||
{showBlockedComments ? 'Back' : 'Show'}
|
||||
</span>
|
||||
]
|
||||
</span>
|
||||
)}
|
||||
{!(isInAllView || isInSubscriptionsView) && (
|
||||
<span className={styles.subscribeButton}>
|
||||
[<SubscribeButton address={subplebbitAddress} />]
|
||||
|
||||
@@ -15,7 +15,6 @@ interface MediaProps {
|
||||
linkWidth?: number;
|
||||
showThumbnail?: boolean;
|
||||
setShowThumbnail: (showThumbnail: boolean) => void;
|
||||
toggleExpanded?: () => void;
|
||||
}
|
||||
|
||||
const Thumbnail = ({ commentMediaInfo, isOutOfFeed, isReply, linkHeight, linkWidth, setShowThumbnail }: MediaProps) => {
|
||||
|
||||
@@ -20,7 +20,7 @@ import PostMenuDesktop from './post-menu-desktop/';
|
||||
import { PostProps } from '../post';
|
||||
import _ from 'lodash';
|
||||
|
||||
const PostInfo = ({ openReplyModal, post, roles, isBlocked }: PostProps) => {
|
||||
const PostInfo = ({ openReplyModal, post, roles, isHidden }: PostProps) => {
|
||||
const { t } = useTranslation();
|
||||
const { author, cid, locked, pinned, parentCid, postCid, shortCid, state, subplebbitAddress, timestamp, title } = post || {};
|
||||
const { address, displayName, shortAddress } = author || {};
|
||||
@@ -44,7 +44,7 @@ const PostInfo = ({ openReplyModal, post, roles, isBlocked }: PostProps) => {
|
||||
|
||||
return (
|
||||
<div className={styles.postInfo}>
|
||||
{!isBlocked && (
|
||||
{!isHidden && (
|
||||
<span className={styles.checkbox}>
|
||||
<input type='checkbox' />
|
||||
</span>
|
||||
@@ -92,7 +92,7 @@ const PostInfo = ({ openReplyModal, post, roles, isBlocked }: PostProps) => {
|
||||
<img src='/assets/icons/closed.gif' alt='' className={styles.closedIcon} title={t('closed')} />
|
||||
</span>
|
||||
)}
|
||||
{!isInPostView && !isReply && !isBlocked && (
|
||||
{!isInPostView && !isReply && !isHidden && (
|
||||
<span className={styles.replyButton}>
|
||||
[
|
||||
<Link
|
||||
@@ -216,13 +216,14 @@ const PostDesktop = ({ openReplyModal, post, roles, showAllReplies }: PostProps)
|
||||
const { cid, content, link, pinned, replyCount, subplebbitAddress } = post || {};
|
||||
const { isDescription, isRules } = post || {}; // custom properties, not from api
|
||||
|
||||
const { blocked, unblock, block } = useBlock({ address: cid });
|
||||
|
||||
const params = useParams();
|
||||
const location = useLocation();
|
||||
const isInPendingPostView = isPendingPostView(location.pathname, params);
|
||||
const isInPostPageView = isPostPageView(location.pathname, params);
|
||||
|
||||
const { blocked, unblock, block } = useBlock({ address: cid });
|
||||
const isHidden = blocked && !isInPostPageView;
|
||||
|
||||
const replies = useReplies(post);
|
||||
const visiblelinksCount = useCountLinksInReplies(post, 5);
|
||||
const totallinksCount = useCountLinksInReplies(post);
|
||||
@@ -234,17 +235,17 @@ const PostDesktop = ({ openReplyModal, post, roles, showAllReplies }: PostProps)
|
||||
<div className={styles.hrWrapper}>
|
||||
<hr />
|
||||
</div>
|
||||
<div className={blocked ? styles.postDesktopBlocked : ''}>
|
||||
<div className={isHidden ? styles.postDesktopBlocked : ''}>
|
||||
{!isInPostPageView && !isDescription && !isRules && (
|
||||
<span className={styles.hideButtonWrapper}>
|
||||
<span className={`${styles.hideButton} ${blocked ? styles.unhideThread : styles.hideThread}`} onClick={blocked ? unblock : block} />
|
||||
</span>
|
||||
)}
|
||||
{link && !blocked && isValidURL(link) && <PostMedia post={post} />}
|
||||
<PostInfo isBlocked={blocked} openReplyModal={openReplyModal} post={post} roles={roles} />
|
||||
{!blocked && !content && <div className={styles.spacer} />}
|
||||
{!blocked && content && <PostMessage post={post} />}
|
||||
{!blocked && !isDescription && !isRules && !isInPendingPostView && (replies.length > 5 || (pinned && replies.length > 0)) && !isInPostPageView && (
|
||||
{link && !isHidden && isValidURL(link) && <PostMedia post={post} />}
|
||||
<PostInfo isHidden={isHidden} openReplyModal={openReplyModal} post={post} roles={roles} />
|
||||
{!isHidden && !content && <div className={styles.spacer} />}
|
||||
{!isHidden && content && <PostMessage post={post} />}
|
||||
{!isHidden && !isDescription && !isRules && !isInPendingPostView && (replies.length > 5 || (pinned && replies.length > 0)) && !isInPostPageView && (
|
||||
<span className={styles.summary}>
|
||||
<span className={styles.expandButtonWrapper}>
|
||||
<span className={styles.expandButton} />
|
||||
@@ -261,7 +262,7 @@ const PostDesktop = ({ openReplyModal, post, roles, showAllReplies }: PostProps)
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
{!blocked &&
|
||||
{!isHidden &&
|
||||
!(pinned && !isInPostPageView) &&
|
||||
!isInPendingPostView &&
|
||||
!isDescription &&
|
||||
|
||||
@@ -141,7 +141,13 @@ const PostMenuDesktop = ({ post }: { post: Comment }) => {
|
||||
<div className={styles.postMenu} ref={refs.setFloating} style={floatingStyles} aria-labelledby={headingId} {...getFloatingProps()}>
|
||||
{cid && subplebbitAddress && <CopyLinkButton cid={cid} subplebbitAddress={subplebbitAddress} onClose={handleClose} />}
|
||||
{!isInPostPageView && !isDescription && !isRules && (
|
||||
<div className={styles.postMenuItem} onClick={blocked ? unblock : block}>
|
||||
<div
|
||||
className={styles.postMenuItem}
|
||||
onClick={() => {
|
||||
blocked ? unblock() : block();
|
||||
handleClose();
|
||||
}}
|
||||
>
|
||||
{blocked ? 'Unhide' : 'Hide'} {postCid === cid ? 'thread' : 'post'}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -6,7 +6,7 @@ import PostMobile from './post-mobile';
|
||||
|
||||
export interface PostProps {
|
||||
index?: number;
|
||||
isBlocked?: boolean;
|
||||
isHidden?: boolean;
|
||||
post?: any;
|
||||
reply?: any;
|
||||
roles?: Role[];
|
||||
|
||||
Reference in New Issue
Block a user