From 89fb1bbc0754d84b225a6fb383535eac1cc74838 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Thu, 30 Nov 2023 23:47:58 +0800 Subject: [PATCH] Experiment show replies count for questions --- src/components/status.css | 8 ++++++++ src/components/status.jsx | 42 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/components/status.css b/src/components/status.css index e110e1af..08a635f8 100644 --- a/src/components/status.css +++ b/src/components/status.css @@ -520,6 +520,14 @@ color: inherit; } */ +.status .content-comment-hint { + margin-top: 0.25em; + font-size: 90%; + display: flex; + gap: 4px; + align-items: center; +} + .status.compact-thread .spoiler-badge { font-size: smaller; color: var(--button-bg-color); diff --git a/src/components/status.jsx b/src/components/status.jsx index 202ba726..0c707a5f 100644 --- a/src/components/status.jsx +++ b/src/components/status.jsx @@ -65,6 +65,7 @@ import MenuLink from './menu-link'; import RelativeTime from './relative-time'; import TranslationBlock from './translation-block'; +const SHOW_COMMENT_COUNT_LIMIT = 280; const INLINE_TRANSLATE_LIMIT = 140; const throttle = pThrottle({ limit: 1, @@ -1021,6 +1022,40 @@ function Status({ repliesCount, visibility, ]); + const showCommentCount = useMemo(() => { + if ( + card || + poll || + sensitive || + spoilerText || + mediaAttachments?.length || + isThread || + withinContext || + inReplyToId || + repliesCount <= 0 + ) { + return false; + } + const questionRegex = /[???︖❓❔⁇⁈⁉¿‽؟]/; + const containsQuestion = questionRegex.test(content); + if (!containsQuestion) return false; + const contentLength = htmlContentLength(content); + if (contentLength > 0 && contentLength <= SHOW_COMMENT_COUNT_LIMIT) { + return true; + } + }, [ + card, + poll, + sensitive, + spoilerText, + mediaAttachments, + reblog, + isThread, + withinContext, + inReplyToId, + repliesCount, + content, + ]); return (
- {showCommentHint ? ( + {showCommentHint && !showCommentCount ? ( )} + {!isSizeLarge && showCommentCount && ( +
+ {repliesCount} +
+ )} {isSizeLarge && ( <>