Skip to content

Commit af3a38c

Browse files
authored
Merge pull request #3668 from cassiano/placing-donate-button-text-update-logic-in-use-effect-hook
Placing donate button text update in `useEffect` hook
2 parents fa70fe2 + e4e127e commit af3a38c

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

client/index.jsx

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React, { Suspense } from 'react';
1+
import React, { Suspense, useEffect } from 'react';
22
import { render } from 'react-dom';
3-
import { Provider } from 'react-redux';
3+
import { Provider, useSelector } from 'react-redux';
44
import { Router } from 'react-router-dom';
55

66
import { useTranslation } from 'react-i18next';
@@ -21,6 +21,8 @@ const initialState = window.__INITIAL_STATE__;
2121

2222
const store = configureStore(initialState);
2323

24+
const DONATE_LOGO_IMAGE_URL = 'https://donorbox.org/images/white_logo.svg';
25+
2426
if (
2527
window.location.href.indexOf('full') === -1 &&
2628
window.location.href.indexOf('embed') === -1
@@ -56,30 +58,30 @@ if (
5658
'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)'
5759
);
5860
buttonScript.setAttribute('data-button-cta', 'Donate');
59-
buttonScript.setAttribute(
60-
'data-img-src',
61-
'https://donorbox.org/images/white_logo.svg'
62-
);
61+
buttonScript.setAttribute('data-img-src', DONATE_LOGO_IMAGE_URL);
6362

6463
document.body.appendChild(buttonScript);
6564
}
6665

6766
const App = () => {
6867
const { t } = useTranslation();
69-
70-
setTimeout(() => {
71-
const donateButton = document.getElementsByClassName(
72-
'dbox-donation-button'
73-
)[0];
74-
75-
if (donateButton) {
76-
const donateLogoImage = document.createElement('img');
77-
donateLogoImage.src = 'https://donorbox.org/images/white_logo.svg';
78-
79-
donateButton.text = t('About.Donate');
80-
donateButton.prepend(donateLogoImage);
81-
}
82-
}, 0);
68+
const language = useSelector((state) => state.preferences.language);
69+
70+
useEffect(() => {
71+
setTimeout(() => {
72+
const donateButton = document.getElementsByClassName(
73+
'dbox-donation-button'
74+
)[0];
75+
76+
if (donateButton) {
77+
const donateLogoImage = document.createElement('img');
78+
donateLogoImage.src = DONATE_LOGO_IMAGE_URL;
79+
80+
donateButton.text = t('About.Donate');
81+
donateButton.prepend(donateLogoImage);
82+
}
83+
}, 500);
84+
}, [language]);
8385

8486
return (
8587
<div>

0 commit comments

Comments
 (0)