2025-09-23 13:03:54 +01:00
|
|
|
import { faVolumeHigh, faVolumeXmark } from "@fortawesome/free-solid-svg-icons";
|
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
|
|
import { useSoundEnabled } from "react-sounds";
|
2025-10-08 11:08:41 +01:00
|
|
|
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
|
|
|
|
|
import { useEffect } from "react";
|
2025-09-23 13:03:54 +01:00
|
|
|
|
|
|
|
|
const SoundBtn = () => {
|
2025-10-08 11:08:41 +01:00
|
|
|
const { mutation, query } = useCameraBlackboard();
|
2025-09-23 13:03:54 +01:00
|
|
|
const [enabled, setEnabled] = useSoundEnabled();
|
|
|
|
|
|
2025-10-08 11:08:41 +01:00
|
|
|
const handleClick = async () => {
|
|
|
|
|
const newEnabled = !enabled;
|
|
|
|
|
setEnabled(newEnabled);
|
|
|
|
|
await mutation.mutateAsync({
|
|
|
|
|
operation: "INSERT",
|
|
|
|
|
path: "soundEnabled",
|
|
|
|
|
value: { enabled: newEnabled },
|
|
|
|
|
});
|
2025-09-23 13:03:54 +01:00
|
|
|
};
|
2025-10-08 11:08:41 +01:00
|
|
|
useEffect(() => {
|
|
|
|
|
setEnabled(query?.data?.soundEnabled?.enabled);
|
|
|
|
|
}, [query?.data?.soundEnabled?.enabled, setEnabled]);
|
2025-09-23 13:03:54 +01:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<button onClick={handleClick}>
|
|
|
|
|
<FontAwesomeIcon
|
|
|
|
|
icon={enabled ? faVolumeHigh : faVolumeXmark}
|
|
|
|
|
size="2x"
|
|
|
|
|
/>
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default SoundBtn;
|