Skip to content

Commit eb0400a

Browse files
committed
fix(screen)
1 parent 72c49ea commit eb0400a

File tree

1 file changed

+18
-31
lines changed

1 file changed

+18
-31
lines changed

src/components/SakanaWidgets.jsx

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import { useEffect, useRef } from "react";
2-
import { Box, useBreakpointValue } from "@chakra-ui/react";
2+
import { Box } from "@chakra-ui/react";
33

44
function SakanaWidgets() {
5-
const isDesktop = useBreakpointValue(
6-
{ base: false, lg: true },
7-
{ ssr: false }
8-
);
9-
105
const leftElRef = useRef(null);
116
const rightElRef = useRef(null);
12-
const widgetsRef = useRef({ left: null, right: null });
7+
const widgetsInitialized = useRef(false);
138

149
useEffect(() => {
1510
const initWidgets = async () => {
11+
if (widgetsInitialized.current) return;
12+
widgetsInitialized.current = true;
13+
1614
try {
1715
await import("sakana-widget/lib/index.css");
1816
const { default: SakanaWidget } = await import("sakana-widget");
@@ -25,59 +23,48 @@ function SakanaWidgets() {
2523
threshold: 0.1,
2624
};
2725

28-
if (leftElRef.current && !widgetsRef.current.left) {
26+
if (leftElRef.current) {
2927
const leftWidget = new SakanaWidget({
3028
...widgetOptions,
3129
character: "chisato",
3230
});
3331
leftWidget.mount(leftElRef.current);
34-
widgetsRef.current.left = leftWidget;
3532
}
3633

37-
if (rightElRef.current && !widgetsRef.current.right) {
34+
if (rightElRef.current) {
3835
const rightWidget = new SakanaWidget({
3936
...widgetOptions,
4037
character: "takina",
4138
});
4239
rightWidget.mount(rightElRef.current);
43-
widgetsRef.current.right = rightWidget;
4440
}
4541
} catch (error) {
4642
console.error("Failed to load or mount SakanaWidget:", error);
4743
}
4844
};
4945

50-
if (isDesktop) {
51-
initWidgets();
52-
}
53-
54-
return () => {
55-
if (widgetsRef.current.left) {
56-
widgetsRef.current.left.unmount();
57-
widgetsRef.current.left = null;
58-
}
59-
if (widgetsRef.current.right) {
60-
widgetsRef.current.right.unmount();
61-
widgetsRef.current.right = null;
62-
}
63-
};
64-
}, [isDesktop]);
65-
66-
if (!isDesktop) {
67-
return null;
68-
}
46+
initWidgets();
47+
}, []);
6948

7049
return (
7150
<>
7251
{/*左下角*/}
73-
<Box ref={leftElRef} position="fixed" bottom="0" left="0" zIndex="999" />
52+
<Box
53+
ref={leftElRef}
54+
position="fixed"
55+
bottom="0"
56+
left="0"
57+
zIndex="999"
58+
display={{ base: "none", lg: "block" }}
59+
/>
7460
{/*右下角*/}
7561
<Box
7662
ref={rightElRef}
7763
position="fixed"
7864
bottom="0"
7965
right="0"
8066
zIndex="999"
67+
display={{ base: "none", lg: "block" }}
8168
/>
8269
</>
8370
);

0 commit comments

Comments
 (0)