Skip to content

Commit

Permalink
Don't dynamically create the static logo
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhjacobs committed Mar 2, 2024
1 parent 8b4ba03 commit 51d8b62
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/app/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
transform: translateY(-50%);
}

.hidden {
display: none;
}

.title {
text-align: center;
margin-bottom: calc(var(--mantine-spacing-xl));
Expand Down
29 changes: 12 additions & 17 deletions src/components/logo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import React from "react";
import Image from "next/image";
import Script from "next/script";
import classes from "../app/index.module.css";

Expand Down Expand Up @@ -36,17 +37,6 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
this.container = React.createRef();
}

private createStaticLogo() {
if (this.container.current) {
const staticLogo = document.createElement("IMG") as HTMLImageElement;
staticLogo.src = "/logo.svg";
staticLogo.alt = "Ruffle Logo";
staticLogo.className = classes.staticLogo;
this.container.current.textContent = "";
this.container.current.appendChild(staticLogo);
}
}

private load() {
if (this.player) {
// Already loaded.
Expand All @@ -57,7 +47,6 @@ export default class InteractiveLogo extends React.Component<LogoProps> {

if (this.player) {
this.container.current!.appendChild(this.player);

this.player.load({
url: "/logo-anim.swf",
autoplay: "on",
Expand All @@ -66,16 +55,21 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
contextMenu: "off",
splashScreen: false,
preferredRenderer: "canvas",
}).then(() => {
this?.container?.current?.querySelector("img")?.classList?.toggle(classes.hidden);
}).catch(() => {
this.createStaticLogo();
this.player?.remove();
this.player = null;
});
this.player.style.width = "100%";
this.player.style.height = "100%";
} else {
this.createStaticLogo();
}
}

componentDidMount() {
this.load();
}

componentWillUnmount() {
this.player?.remove();
this.player = null;
Expand All @@ -87,9 +81,10 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
<Script
src="https://unpkg.com/@ruffle-rs/ruffle"
onReady={() => this.load()}
onError={() => this.createStaticLogo()}
/>
<div ref={this.container} className={this.props.className} />
<div ref={this.container} className={this.props.className}>
<Image src="/logo.svg" alt="Ruffle Logo" className={classes.staticLogo} />
</div>
</>
);
}
Expand Down

0 comments on commit 51d8b62

Please sign in to comment.