Skip to content

Commit 3ca1274

Browse files
authored
Merge pull request #2811 from metabrainz/svg-loader-update
Art Creator: Update svg-loader library and fix sidebar
2 parents 5b5cdb7 + 16d61e0 commit 3ca1274

File tree

6 files changed

+78
-106
lines changed

6 files changed

+78
-106
lines changed

Diff for: frontend/css/fresh-releases.less

-24
Original file line numberDiff line numberDiff line change
@@ -270,30 +270,6 @@
270270
flex-direction: column;
271271
}
272272

273-
.toggle-sidebar-button {
274-
position: fixed;
275-
bottom: 20px;
276-
right: 20px;
277-
z-index: 9999;
278-
width: 64px;
279-
height: 64px;
280-
padding: 10px;
281-
border-radius: 50%;
282-
border-color: black;
283-
cursor: pointer;
284-
background-color: #fff;
285-
color: #353070;
286-
287-
@media screen and (min-width: @screen-md) {
288-
display: none;
289-
}
290-
}
291-
292-
.toggle-sidebar-button.open {
293-
background-color: #353070;
294-
color: #fff;
295-
}
296-
297273
.no-release {
298274
text-align: center;
299275
margin-left: auto;

Diff for: frontend/js/src/components/Sidebar.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import {
77
} from "@fortawesome/free-solid-svg-icons";
88

99
function Sidebar(
10-
props: React.PropsWithChildren<{ toggleIcon?: IconDefinition }>
10+
props: React.PropsWithChildren<{
11+
toggleIcon?: IconDefinition;
12+
className?: string;
13+
}>
1114
) {
12-
const { children, toggleIcon } = props;
15+
const { children, toggleIcon, className } = props;
1316

1417
const [isSidebarOpen, setIsSidebarOpen] = React.useState<boolean>(false);
1518
const toggleSidebar = () => {
@@ -18,7 +21,9 @@ function Sidebar(
1821

1922
return (
2023
<>
21-
<div className={`sidebar ${isSidebarOpen ? "open" : ""}`}>{children}</div>
24+
<div className={`sidebar ${isSidebarOpen ? "open" : ""} ${className}`}>
25+
{children}
26+
</div>
2227
<button
2328
className={`toggle-sidebar-button ${isSidebarOpen ? "open" : ""}`}
2429
onClick={toggleSidebar}

Diff for: frontend/js/src/explore/art-creator/ArtCreator.tsx

+56-52
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Preview from "./components/Preview";
1212
import { svgToBlob, toPng } from "./utils";
1313
import { ToastMsg } from "../../notifications/Notifications";
1414
import UserSearch from "../../common/UserSearch";
15+
import Sidebar from "../../components/Sidebar";
1516

1617
export enum TemplateNameEnum {
1718
designerTop5 = "designer-top-5",
@@ -370,6 +371,7 @@ export default function ArtCreator() {
370371
onClickCopyURL={onClickCopyURL}
371372
/>
372373
<Preview
374+
key={previewUrl}
373375
url={previewUrl}
374376
styles={{
375377
textColor,
@@ -380,7 +382,17 @@ export default function ArtCreator() {
380382
size={DEFAULT_IMAGE_SIZE}
381383
/>
382384
</div>
383-
<div className="sidebar settings-navbar">
385+
<Sidebar className="settings-navbar">
386+
<div className="sidebar-header">
387+
<p>Art Creator</p>
388+
<p>Visualize and share images of your listening stats.</p>
389+
<p>
390+
Select your username, a date range and a template to a dynamic
391+
image that you can save, copy and share easily with your friends.
392+
Check out the #ListenbrainzMonday tag on your social platform of
393+
choice!
394+
</p>
395+
</div>
384396
<div className="basic-settings-container">
385397
<div className="sidenav-content-grid">
386398
<h4>Settings</h4>
@@ -606,65 +618,57 @@ export default function ArtCreator() {
606618
</>
607619
)}
608620
{/* <div className="flex-center input-group">
609-
<label htmlFor="bg-upload">Background image:</label>
610-
<div className="input-group">
611-
<input className="form-control" type="text" disabled />
612-
<div className="input-group-btn">
613-
<button type="button" className="btn btn-default btn-sm">
614-
<FontAwesomeIcon icon={faCloudArrowUp} />
615-
</button>
616-
<input id="bg-upload" type="file" className="hidden" />
621+
<label htmlFor="bg-upload">Background image:</label>
622+
<div className="input-group">
623+
<input className="form-control" type="text" disabled />
624+
<div className="input-group-btn">
625+
<button type="button" className="btn btn-default btn-sm">
626+
<FontAwesomeIcon icon={faCloudArrowUp} />
627+
</button>
628+
<input id="bg-upload" type="file" className="hidden" />
629+
</div>
617630
</div>
618-
</div>
619-
</div> */}
631+
</div> */}
620632

621633
{/* <div>
622-
<label htmlFor="genres">
623-
Genres: <FontAwesomeIcon icon={faCircleQuestion} />
624-
</label>
625-
<input
626-
id="genres"
627-
type="text"
628-
className="form-control"
629-
onChange={updateGenresCallback}
630-
/>
631-
</div> */}
634+
<label htmlFor="genres">
635+
Genres: <FontAwesomeIcon icon={faCircleQuestion} />
636+
</label>
637+
<input
638+
id="genres"
639+
type="text"
640+
className="form-control"
641+
onChange={updateGenresCallback}
642+
/>
643+
</div> */}
632644
{/* <div>
633-
<ToggleOption onClick={userToggler} buttonName="Users" />
634-
<ToggleOption onClick={dateToggler} buttonName="Date" />
635-
<ToggleOption onClick={rangeToggler} buttonName="Range" />
636-
<ToggleOption onClick={totalToggler} buttonName="Total" />
637-
<ToggleOption onClick={genresToggler} buttonName="Genres" />
638-
</div> */}
645+
<ToggleOption onClick={userToggler} buttonName="Users" />
646+
<ToggleOption onClick={dateToggler} buttonName="Date" />
647+
<ToggleOption onClick={rangeToggler} buttonName="Range" />
648+
<ToggleOption onClick={totalToggler} buttonName="Total" />
649+
<ToggleOption onClick={genresToggler} buttonName="Genres" />
650+
</div> */}
639651
{/* <div>
640-
<label htmlFor="font-select">Font:</label>
641-
<select
642-
id="font-select"
643-
className="form-control"
644-
value={font}
645-
onChange={updateFontCallback}
646-
>
647-
{fontOptions.map((opt) => (
648-
<option key={opt} value={opt}>
649-
{opt}
650-
</option>
651-
))}
652-
</select>
653-
</div> */}
652+
<label htmlFor="font-select">Font:</label>
653+
<select
654+
id="font-select"
655+
className="form-control"
656+
value={font}
657+
onChange={updateFontCallback}
658+
>
659+
{fontOptions.map((opt) => (
660+
<option key={opt} value={opt}>
661+
{opt}
662+
</option>
663+
))}
664+
</select>
665+
</div> */}
654666
{/* <div>
655-
<ToggleOption onClick={vaToggler} buttonName="Ignore VA" />
656-
</div> */}
667+
<ToggleOption onClick={vaToggler} buttonName="Ignore VA" />
668+
</div> */}
657669
</div>
658670
</div>
659-
{/* <div className="generate-button-container">
660-
<button
661-
type="button"
662-
className="btn btn-block btn-info text-uppercase"
663-
>
664-
Generate
665-
</button>
666-
</div> */}
667-
</div>
671+
</Sidebar>
668672
</div>
669673
</>
670674
);

Diff for: frontend/js/src/explore/art-creator/components/Preview.tsx

+9-22
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,16 @@ const Preview = React.forwardRef(function PreviewComponent(
2121
Object.values(styles)?.filter(Boolean).length
2222
);
2323
const { textColor, bgColor1, bgColor2 } = styles;
24-
/* The library used to dynamically load the SVG does not currently allow handling errors
25-
so we have to separately try to hit the URL to catch and display any API errors (no data for user for range, etc.)
26-
See https://github.com/shubhamjain/svg-loader/pull/42 */
24+
2725
React.useEffect(() => {
28-
const fetchUrl = async () => {
29-
if (!url) {
30-
return;
31-
}
32-
try {
33-
const response = await fetch(url);
34-
// We only care if there was an error
35-
if (!response.ok) {
36-
const json = await response.json();
37-
setError(json.error || "Something went wrong");
38-
} else {
39-
setError(undefined);
40-
}
41-
} catch (err) {
42-
setError(err.toString());
43-
}
26+
const errorEventListener = ((e: CustomEvent) => {
27+
setError(e.detail ?? "Something went wrong");
28+
}) as EventListener;
29+
window.addEventListener("iconloaderror", errorEventListener);
30+
return () => {
31+
window.removeEventListener("iconloaderror", errorEventListener);
4432
};
45-
fetchUrl();
46-
}, [url]);
33+
}, []);
4734

4835
if (!url) {
4936
return (
@@ -57,7 +44,7 @@ const Preview = React.forwardRef(function PreviewComponent(
5744
<div className="alert alert-danger">
5845
There was an error trying to load statistics for this user and time
5946
range:
60-
<pre>{error}</pre>
47+
<pre style={{ whiteSpace: "pre-wrap" }}>{error}</pre>
6148
Please check the username or try another time range.
6249
</div>
6350
);

Diff for: package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"d3-scale-chromatic": "^3.0.0",
6565
"debounce-async": "0.0.2",
6666
"dompurify": "^2.2.6",
67-
"external-svg-loader": "^1.6.10",
67+
"external-svg-loader": "^1.7.1",
6868
"fetch-retry": "^5.0.3",
6969
"file-saver": "^2.0.5",
7070
"he": "^1.2.0",

0 commit comments

Comments
 (0)