From 052476ad1ad839cb56c17bfe271b6fbe82f5df1e Mon Sep 17 00:00:00 2001 From: "Tom (plebeius.eth)" Date: Mon, 3 Jun 2024 13:52:55 +0200 Subject: [PATCH] feat: hide media if spoiler --- .../comment-media/comment-media.module.css | 15 ++++++++ .../comment-media/comment-media.tsx | 36 +++++++++---------- .../post/post-desktop/post-desktop.tsx | 28 ++++----------- .../post/post-mobile/post-mobile.tsx | 15 ++------ 4 files changed, 41 insertions(+), 53 deletions(-) diff --git a/src/components/comment-media/comment-media.module.css b/src/components/comment-media/comment-media.module.css index be69e7cf..dc952788 100644 --- a/src/components/comment-media/comment-media.module.css +++ b/src/components/comment-media/comment-media.module.css @@ -18,6 +18,17 @@ display: inline-block; } +.spoiler { + display: inline-block; + margin: 3px 20px 5px 20px; + background-color: black; + color: white; + display: flex; + cursor: pointer; + justify-content: center; + align-items: center; +} + @media (max-width: 640px) { .subplebbitAvatar { max-width: 125px; @@ -52,6 +63,10 @@ float: left; } +.thumbnail video { + cursor: pointer; +} + .hide { display: none !important; } diff --git a/src/components/comment-media/comment-media.tsx b/src/components/comment-media/comment-media.tsx index 031b7074..caa8715b 100644 --- a/src/components/comment-media/comment-media.tsx +++ b/src/components/comment-media/comment-media.tsx @@ -1,5 +1,6 @@ import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; +import { Comment } from '@plebbit/plebbit-react-hooks'; import styles from './comment-media.module.css'; import { CommentMediaInfo, getDisplayMediaInfoType, getHasThumbnail } from '../../lib/utils/media-utils'; import { getHostname } from '../../lib/utils/url-utils'; @@ -9,16 +10,22 @@ import Embed, { canEmbed } from '../embed'; interface MediaProps { commentMediaInfo?: CommentMediaInfo; - isDeleted?: boolean; - isOutOfFeed?: boolean; // virtuoso wrapper unneeded - isReply: boolean; + post?: Comment; + isReply?: boolean; linkHeight?: number; linkWidth?: number; showThumbnail?: boolean; setShowThumbnail: (showThumbnail: boolean) => void; } -const Thumbnail = ({ commentMediaInfo, isDeleted, isOutOfFeed, isReply, linkHeight, linkWidth, setShowThumbnail }: MediaProps) => { +const Thumbnail = ({ commentMediaInfo, post, setShowThumbnail }: MediaProps) => { + const { t } = useTranslation(); + const { deleted, linkHeight, linkWidth, parentCid, removed, spoiler } = post || {}; + const { isDescription, isRules } = post || {}; // custom properties, not from api + const isOutOfFeed = isDescription || isRules; // virtuoso wrapper unneeded + const isReply = parentCid; + const isDeleted = deleted || removed; + const { patternThumbnailUrl, thumbnail, type, url } = commentMediaInfo || {}; const [hasError, setHasError] = useState(false); const handleError = () => setHasError(true); @@ -72,6 +79,10 @@ const Thumbnail = ({ commentMediaInfo, isDeleted, isOutOfFeed, isReply, linkHeig return hasError || isDeleted ? ( File deleted + ) : spoiler ? ( + setShowThumbnail(false)}> + [{t('view_spoiler')}] + ) : isOutOfFeed ? ( {thumbnailComponent} ) : isMobile || isReply ? ( @@ -133,7 +144,7 @@ const Media = ({ commentMediaInfo, isReply, setShowThumbnail }: MediaProps) => { ); }; -const CommentMedia = ({ commentMediaInfo, isDeleted, isOutOfFeed, isReply, linkHeight, linkWidth, showThumbnail, setShowThumbnail }: MediaProps) => { +const CommentMedia = ({ commentMediaInfo, post, showThumbnail, setShowThumbnail }: MediaProps) => { const { t } = useTranslation(); const isMobile = useIsMobile(); const { type, url } = commentMediaInfo || {}; @@ -141,21 +152,10 @@ const CommentMedia = ({ commentMediaInfo, isDeleted, isOutOfFeed, isReply, linkH return ( - {url && ( - - )} + {url && } {isMobile && type &&
{getDisplayMediaInfoType(type, t)}
}
- {!showThumbnail && } + {!showThumbnail && }
); }; diff --git a/src/components/post/post-desktop/post-desktop.tsx b/src/components/post/post-desktop/post-desktop.tsx index 18fd1c6a..2ab016c2 100644 --- a/src/components/post/post-desktop/post-desktop.tsx +++ b/src/components/post/post-desktop/post-desktop.tsx @@ -19,6 +19,7 @@ import Markdown from '../../markdown'; import PostMenuDesktop from './post-menu-desktop/'; import { PostProps } from '../post'; import _ from 'lodash'; +import ModMenu from '../mod-menu'; const PostInfo = ({ openReplyModal, post, roles, isHidden }: PostProps) => { const { t } = useTranslation(); @@ -44,11 +45,7 @@ const PostInfo = ({ openReplyModal, post, roles, isHidden }: PostProps) => { return (
- {!isHidden && ( - - - - )} + {!isHidden && } {title && {displayTitle} } @@ -111,16 +108,12 @@ const PostInfo = ({ openReplyModal, post, roles, isHidden }: PostProps) => { const PostMedia = ({ post }: PostProps) => { const { t } = useTranslation(); - const { deleted, link, linkHeight, linkWidth, parentCid, removed } = post || {}; - const { isDescription, isRules } = post || {}; // custom properties, not from api const commentMediaInfo = getCommentMediaInfo(post); const { type, url } = commentMediaInfo || {}; const embedUrl = url && new URL(url); - const hasThumbnail = getHasThumbnail(commentMediaInfo, link); + const hasThumbnail = getHasThumbnail(commentMediaInfo, post?.link); const [showThumbnail, setShowThumbnail] = useState(true); - const isReply = parentCid; - return (
@@ -152,16 +145,7 @@ const PostMedia = ({ post }: PostProps) => {
{(hasThumbnail || (!hasThumbnail && !showThumbnail)) && (
- +
)}
@@ -169,7 +153,7 @@ const PostMedia = ({ post }: PostProps) => { }; const PostMessage = ({ post }: PostProps) => { - const { cid, content, deleted, parentCid, postCid, reason, removed, state, subplebbitAddress } = post || {}; + const { cid, content, deleted, parentCid, postCid, reason, removed, spoiler, state, subplebbitAddress } = post || {}; const { t } = useTranslation(); const params = useParams(); const location = useLocation(); @@ -201,7 +185,7 @@ const PostMessage = ({ post }: PostProps) => { ) : deleted ? ( {t('user_deleted_this_post')} ) : ( - + )} {(removed || deleted) && reason && ( diff --git a/src/components/post/post-mobile/post-mobile.tsx b/src/components/post/post-mobile/post-mobile.tsx index 21453575..eeabdad2 100644 --- a/src/components/post/post-mobile/post-mobile.tsx +++ b/src/components/post/post-mobile/post-mobile.tsx @@ -19,7 +19,7 @@ import _ from 'lodash'; const PostInfoAndMedia = ({ openReplyModal, post, roles }: PostProps) => { const { t } = useTranslation(); - const { author, cid, deleted, link, linkHeight, linkWidth, locked, parentCid, pinned, removed, shortCid, state, subplebbitAddress, timestamp, title } = post || {}; + const { author, cid, link, locked, parentCid, pinned, shortCid, state, subplebbitAddress, timestamp, title } = post || {}; const { isDescription, isRules } = post || {}; // custom properties, not from api const { address, displayName, shortAddress } = author || {}; @@ -94,18 +94,7 @@ const PostInfoAndMedia = ({ openReplyModal, post, roles }: PostProps) => { )}
- {(hasThumbnail || link) && ( - - )} + {(hasThumbnail || link) && } ); };