mirror of
https://github.com/LCE-Hub/LCE-Emerald-Launcher.git
synced 2026-07-18 00:07:09 +00:00
fix: sfx issue, closes #80
This commit is contained in:
parent
b3162d4e02
commit
587d1983b8
|
|
@ -1,4 +1,4 @@
|
|||
import { useEffect } from "react";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { motion, AnimatePresence } from "framer-motion";
|
||||
import { useAudio } from "../../context/LauncherContext";
|
||||
|
||||
|
|
@ -18,20 +18,28 @@ export function AchievementToast({
|
|||
variant = "error",
|
||||
}: AchievementToastProps) {
|
||||
const { playSfx } = useAudio();
|
||||
|
||||
const prevMessage = useRef(message);
|
||||
useEffect(() => {
|
||||
if (message) {
|
||||
const wasNull = !prevMessage.current;
|
||||
const isNull = !message;
|
||||
prevMessage.current = message;
|
||||
if (message && wasNull) {
|
||||
if (variant === "update") {
|
||||
playSfx("notification.ogg");
|
||||
} else {
|
||||
playSfx("in.ogg");
|
||||
}
|
||||
}
|
||||
|
||||
if (message) {
|
||||
const timer = setTimeout(() => {
|
||||
onClose();
|
||||
}, 8000);
|
||||
return () => {
|
||||
clearTimeout(timer);
|
||||
playSfx("out.ogg");
|
||||
if (isNull) {
|
||||
playSfx("out.ogg");
|
||||
}
|
||||
};
|
||||
}
|
||||
}, [message, onClose, variant, playSfx]);
|
||||
|
|
|
|||
Loading…
Reference in a new issue