Skip to content

Commit 86c8207

Browse files
committed
donation banner and widget
1 parent 691e6a9 commit 86c8207

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

client/modules/IDE/pages/IDEView.jsx

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import PreviewFrame from '../components/PreviewFrame';
1010
import Console from '../components/Console';
1111
import Toast from '../components/Toast';
1212
import { updateFileContent } from '../actions/files';
13+
import { CrossIcon } from '../../../common/icons';
1314

1415
import {
1516
autosaveProject,
@@ -114,6 +115,79 @@ const IDEView = () => {
114115
dispatch(updateFileContent(file.id, file.content));
115116
};
116117

118+
const Banner = () => {
119+
// temporary banner to display funding opportunities
120+
const textObj = {
121+
copy:
122+
'Help us raise $20K to continue our mission of building equitable and accessible creative coding tools!',
123+
url: 'https://p5js.org/donate/'
124+
};
125+
126+
const [isBannerVisible, setIsBannerVisible] = useState(true);
127+
128+
// eslint-disable-next-line consistent-return
129+
useEffect(() => {
130+
const script = document.createElement('script');
131+
script.type = 'text/javascript';
132+
script.defer = true;
133+
script.src = 'https://donorbox.org/install-popup-button.js';
134+
script.id = 'donorbox-popup-button-installer';
135+
script.setAttribute(
136+
'data-href',
137+
'https://donorbox.org/building-together?default_interval=o'
138+
);
139+
script.setAttribute(
140+
'data-style',
141+
// eslint-disable-next-line max-len
142+
'background: rgb(85, 1, 164); color: rgb(255, 255, 255); text-decoration: none; font-family: Verdana, sans-serif; display: flex; font-size: 16px; padding: 8px 22px 8px 18px; border-radius: 0px 0px 5px 5px; gap: 8px; width: fit-content; line-height: 24px; position: fixed; top: 70%; transform-origin: center center; z-index: 9999; overflow: hidden; left: 20px; transform: translate(-50%, -50%) rotate(-90deg);'
143+
);
144+
script.setAttribute(
145+
'data-img-src',
146+
'https://donorbox.org/images/white_logo.svg'
147+
);
148+
149+
document.body.appendChild(script);
150+
151+
return () => {
152+
const existingScript = document.getElementById(
153+
'donorbox-popup-button-installer'
154+
);
155+
if (existingScript) {
156+
existingScript.remove();
157+
}
158+
};
159+
}, []);
160+
161+
const handleCloseBanner = () => {
162+
setIsBannerVisible(false);
163+
164+
const existingScript = document.getElementById(
165+
'donorbox-popup-button-installer'
166+
);
167+
if (existingScript) {
168+
existingScript.remove();
169+
}
170+
171+
const popupButton = document.querySelector('.dbox-donation-button');
172+
if (popupButton) {
173+
popupButton.remove();
174+
}
175+
};
176+
177+
return (
178+
isBannerVisible && (
179+
<div className="banner">
180+
<a href={textObj.url} target="_blank" rel="noopener noreferrer">
181+
{textObj.copy}
182+
</a>
183+
<button className="banner-close-button" onClick={handleCloseBanner}>
184+
<CrossIcon />
185+
</button>
186+
</div>
187+
)
188+
);
189+
};
190+
117191
useEffect(() => {
118192
dispatch(clearPersistedState());
119193
}, [dispatch]);
@@ -170,6 +244,7 @@ const IDEView = () => {
170244
<Helmet>
171245
<title>{getTitle(project)}</title>
172246
</Helmet>
247+
<Banner />
173248
<IDEKeyHandlers getContent={() => cmRef.current?.getContent()} />
174249
<WarnIfUnsavedChanges />
175250
<Toast />

client/styles/layout/_ide.scss

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,29 @@
2121
height: 100%;
2222
}
2323

24+
.banner {
25+
width: 100%;
26+
min-height: 2.2rem;
27+
text-align: center;
28+
padding: 0.5rem;
29+
font-weight: bold;
30+
border-bottom: 1px dashed #A6A6A6;
31+
32+
@media (max-width: 770px) {
33+
min-height: 3.3rem;
34+
}
35+
}
36+
37+
.banner-close-button{
38+
display: flex;
39+
flex-direction: column;
40+
align-items: center;
41+
justify-content: center;
42+
height: 20px;
43+
width:20px;
44+
float: right;
45+
}
46+
2447
@media print {
2548
.sidebar {
2649
display: none;

0 commit comments

Comments
 (0)