Skip to content

Commit f3ddbc3

Browse files
committed
Placing donate button text update in useEffect hook
1 parent 224c6e2 commit f3ddbc3

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

client/index.jsx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Suspense } from 'react';
1+
import React, { Suspense, useEffect } from 'react';
22
import { render } from 'react-dom';
33
import { Provider } from 'react-redux';
44
import { Router } from 'react-router-dom';
@@ -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,29 @@ 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();
6968

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);
69+
useEffect(() => {
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 = DONATE_LOGO_IMAGE_URL;
78+
79+
donateButton.text = t('About.Donate');
80+
donateButton.prepend(donateLogoImage);
81+
}
82+
}, 500);
83+
}, [t]);
8384

8485
return (
8586
<div>

0 commit comments

Comments
 (0)