From 2cfb151542dd7a47b1636cd54f1ff5988ae01a7e Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 15 Apr 2022 17:41:53 -0500 Subject: [PATCH] StatusContent: break out ReadMoreButton and SpoilerButton into FC's --- app/soapbox/components/status_content.tsx | 85 +++++++++++++---------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/app/soapbox/components/status_content.tsx b/app/soapbox/components/status_content.tsx index 6459f93e1..00b9ef30f 100644 --- a/app/soapbox/components/status_content.tsx +++ b/app/soapbox/components/status_content.tsx @@ -11,8 +11,6 @@ import { onlyEmoji as isOnlyEmoji } from 'soapbox/utils/rich_content'; import { isRtl } from '../rtl'; -// import Permalink from './permalink'; - import type { Status, Mention } from 'soapbox/types/entities'; const MAX_HEIGHT = 642; // 20px * 32 (+ 2px padding at the top) @@ -23,15 +21,58 @@ type Point = [ y: number, ] +interface IReadMoreButton { + onClick: React.MouseEventHandler, +} + +/** Button to expand a truncated status (due to too much content) */ +const ReadMoreButton: React.FC = ({ onClick }) => ( + +); + +interface ISpoilerButton { + onClick: React.MouseEventHandler, + hidden: boolean, + tabIndex?: number, +} + +/** Button to expand status text behind a content warning */ +const SpoilerButton: React.FC = ({ onClick, hidden, tabIndex }) => ( + +); + interface IStatusContent { status: Status, - reblogContent?: string, + reblogContent?: string, // FIXME: not used! expanded?: boolean, onExpandedToggle?: () => void, onClick?: () => void, collapsable?: boolean, } +/** Renders the text content of a status */ const StatusContent: React.FC = ({ status, expanded = false, onExpandedToggle, onClick, collapsable = false }) => { const history = useHistory(); @@ -141,6 +182,7 @@ const StatusContent: React.FC = ({ status, expanded = false, onE const handleSpoilerClick: React.EventHandler = (e) => { e.preventDefault(); + e.stopPropagation(); if (onExpandedToggle) { // The parent manages the state @@ -181,48 +223,19 @@ const StatusContent: React.FC = ({ status, expanded = false, onE directionStyle.direction = 'rtl'; } - const readMoreButton = ( - - ); - if (status.spoiler_text.length > 0) { - // let mentionsPlaceholder: React.ReactNode = ''; - // - // const mentionLinks = status.mentions.map(mention => ( - // - // @{mention.username} - // - // )).reduce((aggregate, mention) => [...aggregate, mention, ' '], []); - // - // if (isHidden) { - // mentionsPlaceholder =
{mentionLinks}
; - // } - return (

- + hidden={isHidden} + />

- {/* mentionsPlaceholder */} -
= ({ status, expanded = false, onE ]; if (collapsed) { - output.push(readMoreButton); + output.push(); } if (status.poll && typeof status.poll === 'string') {