Add audio feedback for toast notifications; implement playAudio function in ToastProvider
This commit is contained in:
parent
96784c02c7
commit
2b940c3d43
BIN
public/audio/error.mp3
Normal file
BIN
public/audio/error.mp3
Normal file
Binary file not shown.
BIN
public/audio/warning.mp3
Normal file
BIN
public/audio/warning.mp3
Normal file
Binary file not shown.
@ -8,7 +8,20 @@ export const ToastContext = createContext();
|
||||
|
||||
export const ToastProvider = ({ children }) => {
|
||||
const [toast, setToast] = useState({ show: false, message: "", type: "" });
|
||||
|
||||
const playAudio = (type) => {
|
||||
let audioSrc;
|
||||
if(type === "warning") audioSrc = "/audio/warning.mp3";
|
||||
else if (type === "error") audioSrc = "/audio/error.mp3";
|
||||
|
||||
if (audioSrc) {
|
||||
const audio = new Audio(audioSrc);
|
||||
audio.play().catch((error) => console.error("Error playing audio:", error));
|
||||
}
|
||||
};
|
||||
|
||||
const showToast = (message, type) => {
|
||||
playAudio(type);
|
||||
setToast({ show: true, message, type });
|
||||
setTimeout(() => {
|
||||
setToast({ show: false, message: "", type: "" });
|
||||
|
Loading…
x
Reference in New Issue
Block a user