Skip to content

Commit

Permalink
feat: only show TransCallToActionBanner in appropriate cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nsantacruz committed Sep 13, 2023
1 parent b426b1a commit badc373
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions static/js/ReaderPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1384,10 +1384,12 @@ class ReaderControls extends Component {
<DisplaySettingsButton onClick={this.props.openDisplaySettings} />
</div>);
const openTranslations = this.props.openConnectionsPanel.bind(null, [this.props.currentRef], null, {"connectionsMode": "Translations"});
const transCallToActionApplies = () => Sefaria.transCallToActionApplies(this.props.currentBook(), this.props.settings.language);
let banner = (hideHeader || connectionsHeader) ? null : (
<TextColumnBannerChooser
setTranslationLanguagePreference={this.props.setTranslationLanguagePreference}
openTranslations={openTranslations}
transCallToActionApplies={transCallToActionApplies}
/>
);
const classes = classNames({
Expand Down
10 changes: 8 additions & 2 deletions static/js/TextColumnBanner.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import {
const cookie = Sefaria._inBrowser ? $.cookie : Sefaria.util.cookie;
const { translation_language_preference_suggestion } = Sefaria;

export const TextColumnBannerChooser = ({ setTranslationLanguagePreference, openTranslations }) => {
export const TextColumnBannerChooser = ({ setTranslationLanguagePreference, openTranslations, transCallToActionApplies }) => {
const [bannerAccepted, setBannerAccepted] = useState(false);
const shouldTransPrefBannerRender = () => {
// we haven't suggested yet and we have a suggestion
return !cookie("translation_language_preference_suggested") && translation_language_preference_suggestion
};
const shouldTransCallToActionRender = () => {
return transCallToActionApplies() && !cookie("translation_call_to_action_shown"); // && textMode in (bilingual, english) && category in (Tanakh, Mishnah, Bavli)
}
if (shouldTransPrefBannerRender()) {
return (<TransLangPrefBanner
setAccepted={setBannerAccepted}
Expand All @@ -22,7 +25,10 @@ export const TextColumnBannerChooser = ({ setTranslationLanguagePreference, open
} else if (bannerAccepted) {
return <TransLangPrefAcceptedBanner />;
}
return <TransCallToActionBanner openTranslations={openTranslations} />;
if (shouldTransCallToActionRender()) {
return <TransCallToActionBanner openTranslations={openTranslations} />;
}
return null;
};


Expand Down
9 changes: 9 additions & 0 deletions static/js/sefaria/sefaria.js
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,15 @@ Sefaria = extend(Sefaria, {
}
return ref ? this.getRefFromCache(ref) : null;
},
transCallToActionApplies: (book, textLanguage) => {
/**
* Should we display the translaiton call-to-action banner?
* Return `true` if `book`s corpus is Tanakh, Mishnah or Bavli AND textLanguage isn't Hebrew
*/
const applicableCorpora = ["Tanakh", "Mishnah", "Bavli"];
const currCorpus = Sefaria.index(book)?.corpus;
return textLanguage !== "hebrew" && applicableCorpora.indexOf(currCorpus) !== -1;
},
_lookups: {},

// getName w/ refOnly true should work as a replacement for parseRef - it uses a callback rather than return value. Besides that - same data.
Expand Down

0 comments on commit badc373

Please sign in to comment.