From d0b7bd42501fcf704dbfead4cc1c08ced49371a8 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 14 Nov 2022 00:43:24 +0100 Subject: [PATCH] Fix wrong cut-off point for "Read more" in web UI (#20599) --- .../mastodon/components/status_content.js | 27 +++++++++++-------- .../styles/mastodon/components.scss | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/javascript/mastodon/components/status_content.js b/app/javascript/mastodon/components/status_content.js index 2a933c0a7..fbc66eabf 100644 --- a/app/javascript/mastodon/components/status_content.js +++ b/app/javascript/mastodon/components/status_content.js @@ -8,7 +8,7 @@ import PollContainer from 'mastodon/containers/poll_container'; import Icon from 'mastodon/components/icon'; import { autoPlayGif, languages as preloadedLanguages, translationEnabled } from 'mastodon/initial_state'; -const MAX_HEIGHT = 642; // 20px * 32 (+ 2px padding at the top) +const MAX_HEIGHT = 706; // 22px * 32 (+ 2px padding at the top) class TranslateButton extends React.PureComponent { @@ -77,16 +77,21 @@ class StatusContent extends React.PureComponent { return; } + const { status, onCollapsedToggle } = this.props; const links = node.querySelectorAll('a'); + let link, mention; + for (var i = 0; i < links.length; ++i) { - let link = links[i]; + link = links[i]; + if (link.classList.contains('status-link')) { continue; } + link.classList.add('status-link'); - let mention = this.props.status.get('mentions').find(item => link.href === item.get('url')); + mention = this.props.status.get('mentions').find(item => link.href === item.get('url')); if (mention) { link.addEventListener('click', this.onMentionClick.bind(this, mention), false); @@ -101,16 +106,16 @@ class StatusContent extends React.PureComponent { } } - if (this.props.status.get('collapsed', null) === null) { - let collapsed = - this.props.collapsable - && this.props.onClick + if (status.get('collapsed', null) === null && onCollapsedToggle) { + const { collapsable, onClick } = this.props; + + const collapsed = + collapsable + && onClick && node.clientHeight > MAX_HEIGHT - && this.props.status.get('spoiler_text').length === 0; + && status.get('spoiler_text').length === 0; - if(this.props.onCollapsedToggle) this.props.onCollapsedToggle(collapsed); - - this.props.status.set('collapsed', collapsed); + onCollapsedToggle(collapsed); } } diff --git a/app/javascript/styles/mastodon/components.scss b/app/javascript/styles/mastodon/components.scss index 8b43604c8..606e20355 100644 --- a/app/javascript/styles/mastodon/components.scss +++ b/app/javascript/styles/mastodon/components.scss @@ -964,7 +964,7 @@ } .status__content.status__content--collapsed { - max-height: 20px * 15; // 15 lines is roughly above 500 characters + max-height: 22px * 15; // 15 lines is roughly above 500 characters } .status__content__read-more-button {