From cfd817dfe49368bb9fb784a0fc6a00132ad91244 Mon Sep 17 00:00:00 2001 From: YishaiGlasner Date: Wed, 8 Jan 2025 12:09:41 +0200 Subject: [PATCH 1/2] refactor(TextSegment): do not send primary / translation text to html when it shouldn't be changed. --- static/css/s2.css | 2 -- static/js/TextRange.jsx | 17 ++++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/static/css/s2.css b/static/css/s2.css index c3bdd34048..7c78508895 100644 --- a/static/css/s2.css +++ b/static/css/s2.css @@ -1525,10 +1525,8 @@ div.interfaceLinks-row a { .readerPanel.english .contentText .he, .readerPanel.hebrew .contentText .en, .readerPanel.english .contentSpan.primary, -.readerPanel.english .connectionsPanel .contentSpan.primary, .readerPanel.english .languageToggle .he, .readerPanel.hebrew .contentSpan.translation, -.readerPanel.hebrew .connectionsPanel .contentSpan.translation, .readerPanel.hebrew .languageToggle .en { display: none; } diff --git a/static/js/TextRange.jsx b/static/js/TextRange.jsx index c154ed8214..6a5c8fa38d 100644 --- a/static/js/TextRange.jsx +++ b/static/js/TextRange.jsx @@ -589,8 +589,10 @@ class TextSegment extends Component { en = this.props.formatEnAsPoetry ? this.addPoetrySpans(en) : en he = this.props.formatHeAsPoetry ? this.addPoetrySpans(he) : he - const hasOnlyRtl = (!this.props.en && this.props?.primaryDirection === 'rtl'); - const hasOnlyLtr = !this.props.en && this.props?.primaryDirection === 'ltr'; + const hasNoTranslation = !this.props.en; + + const hasOnlyRtl = (hasNoTranslation && this.props?.primaryDirection === 'rtl'); + const hasOnlyLtr = hasNoTranslation && this.props?.primaryDirection === 'ltr'; let sidebarRtl, sidebarLtr; if (panelMode === 'Connections') { const directionAttr = (language === 'hebrew') ? 'primaryDirection' : 'translationDirection'; @@ -625,14 +627,15 @@ class TextSegment extends Component { ) : null; - const primary = { + + const primary = (language !== 'english' || hasNoTranslation) ? { direction: this.props.primaryDirection, text: he + " ", - }; - const translation = { + } : {}; + const translation = (language !== 'hebrew') ? { direction: this.props.translationDirection, text: en + " ", - }; + } : {}; const classes=classNames({ segment: 1, @@ -642,7 +645,7 @@ class TextSegment extends Component { enOnly: enOnly, showNamedEntityLinks: !!this.props.onNamedEntityClick, }); - if(!this.props.en && !this.props.he){ + if(hasNoTranslation && !this.props.he){ return false; } return ( From a3de1f18bdfaecef6ff68758ae708e8e2170b672 Mon Sep 17 00:00:00 2001 From: YishaiGlasner Date: Wed, 8 Jan 2025 13:08:06 +0200 Subject: [PATCH 2/2] refactor(textSegment): explicit booleans for shouldPrimaryShow and shouldTranslationShow. --- static/js/TextRange.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/static/js/TextRange.jsx b/static/js/TextRange.jsx index 6a5c8fa38d..01ce326b63 100644 --- a/static/js/TextRange.jsx +++ b/static/js/TextRange.jsx @@ -628,11 +628,13 @@ class TextSegment extends Component { ) : null; - const primary = (language !== 'english' || hasNoTranslation) ? { + const shouldPrimaryShow = language !== 'english' || hasNoTranslation; + const primary = shouldPrimaryShow ? { direction: this.props.primaryDirection, text: he + " ", } : {}; - const translation = (language !== 'hebrew') ? { + const shouldTranslationShow = language !== 'hebrew'; + const translation = shouldTranslationShow ? { direction: this.props.translationDirection, text: en + " ", } : {};