Skip to content

Commit

Permalink
Merge pull request #1631 from Sefaria/strapi-cms-revised
Browse files Browse the repository at this point in the history
Merge PR to allow background colors on banners
  • Loading branch information
relyks committed Sep 12, 2023
2 parents e4ed154 + fda3ca8 commit f698af0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
32 changes: 22 additions & 10 deletions static/js/Misc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2278,7 +2278,8 @@ const InterruptingMessage = ({
InterruptingMessage.displayName = "InterruptingMessage";

const Banner = ({ onClose }) => {
const [bannerShowDelayHasElapsed, setBannerShowDelayHasElapsed] = useState(false);
const [bannerShowDelayHasElapsed, setBannerShowDelayHasElapsed] =
useState(false);
const [hasInteractedWithBanner, setHasInteractedWithBanner] = useState(false);
const strapi = useContext(StrapiDataContext);

Expand Down Expand Up @@ -2306,7 +2307,11 @@ const Banner = ({ onClose }) => {

const shouldShow = () => {
if (!strapi.banner) return false;
if (Sefaria.interfaceLang === 'hebrew' && !strapi.banner.locales.includes('he')) return false;
if (
Sefaria.interfaceLang === "hebrew" &&
!strapi.banner.locales.includes("he")
)
return false;
if (hasBannerBeenInteractedWith(strapi.banner.internalBannerName))
return false;

Expand Down Expand Up @@ -2340,15 +2345,11 @@ const Banner = ({ onClose }) => {
if (onClose) onClose();
markBannerAsHasBeenInteractedWith(strapi.banner.internalBannerName);
setHasInteractedWithBanner(true);
trackBannerInteraction(
strapi.banner.internalBannerName,
eventDescription
);
trackBannerInteraction(strapi.banner.internalBannerName, eventDescription);
};

useEffect(() => {
if (shouldShow()) {

const timeoutId = setTimeout(() => {
// s2 is the div that contains the React root and needs to be manipulated by traditional DOM methods
if (document.getElementById("s2").classList.contains("headerOnly")) {
Expand All @@ -2365,10 +2366,22 @@ const Banner = ({ onClose }) => {
if (!hasInteractedWithBanner) {
return (
<OnInView onVisible={trackBannerImpression}>
<div id="bannerMessage" className={bannerShowDelayHasElapsed ? "" : "hidden"}>
<div
id="bannerMessage"
className={bannerShowDelayHasElapsed ? "" : "hidden"}
style={
strapi.banner.bannerBackgroundColor && {
backgroundColor: strapi.banner.bannerBackgroundColor,
}
}
>
<div id="bannerMessageContent">
<div id="bannerTextBox">
<InterfaceText markdown={replaceNewLinesWithLinebreaks(strapi.banner.bannerText)} />
<InterfaceText
markdown={replaceNewLinesWithLinebreaks(
strapi.banner.bannerText
)}
/>
</div>
<div id="bannerButtonBox">
<a
Expand All @@ -2385,7 +2398,6 @@ const Banner = ({ onClose }) => {
</a>
</div>
</div>
<div id="bannerMessageClose">×</div>
<div id="bannerMessageClose" onClick={closeBanner}>
×
</div>
Expand Down
1 change: 1 addition & 0 deletions static/js/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function StrapiDataProvider({ children }) {
buttonText
buttonURL
showDelay
bannerBackgroundColor
createdAt
locale
localizations {
Expand Down

0 comments on commit f698af0

Please sign in to comment.