1
1
"use client" ;
2
2
3
3
import React from "react" ;
4
+ import Image from "next/image" ;
4
5
import Script from "next/script" ;
5
6
import classes from "../app/index.module.css" ;
6
7
@@ -36,17 +37,6 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
36
37
this . container = React . createRef ( ) ;
37
38
}
38
39
39
- private createStaticLogo ( ) {
40
- if ( this . container . current ) {
41
- const staticLogo = document . createElement ( "IMG" ) as HTMLImageElement ;
42
- staticLogo . src = "/logo.svg" ;
43
- staticLogo . alt = "Ruffle Logo" ;
44
- staticLogo . className = classes . staticLogo ;
45
- this . container . current . textContent = "" ;
46
- this . container . current . appendChild ( staticLogo ) ;
47
- }
48
- }
49
-
50
40
private load ( ) {
51
41
if ( this . player ) {
52
42
// Already loaded.
@@ -57,7 +47,6 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
57
47
58
48
if ( this . player ) {
59
49
this . container . current ! . appendChild ( this . player ) ;
60
-
61
50
this . player . load ( {
62
51
url : "/logo-anim.swf" ,
63
52
autoplay : "on" ,
@@ -66,16 +55,21 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
66
55
contextMenu : "off" ,
67
56
splashScreen : false ,
68
57
preferredRenderer : "canvas" ,
58
+ } ) . then ( ( ) => {
59
+ this ?. container ?. current ?. querySelector ( "img" ) ?. classList ?. toggle ( classes . hidden ) ;
69
60
} ) . catch ( ( ) => {
70
- this . createStaticLogo ( ) ;
61
+ this . player ?. remove ( ) ;
62
+ this . player = null ;
71
63
} ) ;
72
64
this . player . style . width = "100%" ;
73
65
this . player . style . height = "100%" ;
74
- } else {
75
- this . createStaticLogo ( ) ;
76
66
}
77
67
}
78
68
69
+ componentDidMount ( ) {
70
+ this . load ( ) ;
71
+ }
72
+
79
73
componentWillUnmount ( ) {
80
74
this . player ?. remove ( ) ;
81
75
this . player = null ;
@@ -87,9 +81,10 @@ export default class InteractiveLogo extends React.Component<LogoProps> {
87
81
< Script
88
82
src = "https://unpkg.com/@ruffle-rs/ruffle"
89
83
onReady = { ( ) => this . load ( ) }
90
- onError = { ( ) => this . createStaticLogo ( ) }
91
84
/>
92
- < div ref = { this . container } className = { this . props . className } />
85
+ < div ref = { this . container } className = { this . props . className } >
86
+ < Image src = "/logo.svg" alt = "Ruffle Logo" className = { classes . staticLogo } />
87
+ </ div >
93
88
</ >
94
89
) ;
95
90
}
0 commit comments