From f3ddbc3055d166dc838f0cc62b72d77dd8f8d7da Mon Sep 17 00:00:00 2001 From: Cassiano D'Andrea Date: Sat, 27 Sep 2025 00:18:07 -0300 Subject: [PATCH 1/2] Placing donate button text update in `useEffect` hook --- client/index.jsx | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/client/index.jsx b/client/index.jsx index b507634e6c..fbd4255a36 100644 --- a/client/index.jsx +++ b/client/index.jsx @@ -1,4 +1,4 @@ -import React, { Suspense } from 'react'; +import React, { Suspense, useEffect } from 'react'; import { render } from 'react-dom'; import { Provider } from 'react-redux'; import { Router } from 'react-router-dom'; @@ -21,6 +21,8 @@ const initialState = window.__INITIAL_STATE__; const store = configureStore(initialState); +const DONATE_LOGO_IMAGE_URL = 'https://donorbox.org/images/white_logo.svg'; + if ( window.location.href.indexOf('full') === -1 && window.location.href.indexOf('embed') === -1 @@ -56,10 +58,7 @@ if ( 'background: #f1678e; color: #fff; text-decoration: none; font-family: Verdana, sans-serif; display: flex; gap: 8px; width: fit-content; font-size: 16px; border-radius: 0 0 5px 5px; line-height: 24px; position: fixed; top: 50%; transform-origin: center; z-index: 9999; overflow: hidden; padding: 8px 22px 8px 18px; right: 20px; left: auto; transform: translate(50%, -50%) rotate(90deg)' ); buttonScript.setAttribute('data-button-cta', 'Donate'); - buttonScript.setAttribute( - 'data-img-src', - 'https://donorbox.org/images/white_logo.svg' - ); + buttonScript.setAttribute('data-img-src', DONATE_LOGO_IMAGE_URL); document.body.appendChild(buttonScript); } @@ -67,19 +66,21 @@ if ( const App = () => { const { t } = useTranslation(); - setTimeout(() => { - const donateButton = document.getElementsByClassName( - 'dbox-donation-button' - )[0]; - - if (donateButton) { - const donateLogoImage = document.createElement('img'); - donateLogoImage.src = 'https://donorbox.org/images/white_logo.svg'; - - donateButton.text = t('About.Donate'); - donateButton.prepend(donateLogoImage); - } - }, 0); + useEffect(() => { + setTimeout(() => { + const donateButton = document.getElementsByClassName( + 'dbox-donation-button' + )[0]; + + if (donateButton) { + const donateLogoImage = document.createElement('img'); + donateLogoImage.src = DONATE_LOGO_IMAGE_URL; + + donateButton.text = t('About.Donate'); + donateButton.prepend(donateLogoImage); + } + }, 500); + }, [t]); return (
From 4cad4b9f67a791ff4b54b323673c1563ab70a43c Mon Sep 17 00:00:00 2001 From: Cassiano D'Andrea Date: Sat, 27 Sep 2025 01:21:52 -0300 Subject: [PATCH 2/2] Add the selected language to the `useEffect()` dependencies (and remove the `t()` function, since it is probably stable) --- client/index.jsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/index.jsx b/client/index.jsx index fbd4255a36..626466abc5 100644 --- a/client/index.jsx +++ b/client/index.jsx @@ -1,6 +1,6 @@ import React, { Suspense, useEffect } from 'react'; import { render } from 'react-dom'; -import { Provider } from 'react-redux'; +import { Provider, useSelector } from 'react-redux'; import { Router } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; @@ -65,6 +65,7 @@ if ( const App = () => { const { t } = useTranslation(); + const language = useSelector((state) => state.preferences.language); useEffect(() => { setTimeout(() => { @@ -80,7 +81,7 @@ const App = () => { donateButton.prepend(donateLogoImage); } }, 500); - }, [t]); + }, [language]); return (