diff --git a/components/inbox-mail/types-mail.tsx b/components/inbox-mail/types-mail.tsx index 6dfe86b..c2b8844 100644 --- a/components/inbox-mail/types-mail.tsx +++ b/components/inbox-mail/types-mail.tsx @@ -41,6 +41,14 @@ export type InboxMailThread = { } } +export type Settings = { + soundName?: string; + enabled?: boolean; + onlyForLongTasks: boolean; + onlyIfNotInFocus: boolean; +} + + export type User = { id: string; organizationId: string; @@ -52,6 +60,8 @@ export type User = { logoutUrl: string; isAdmin: boolean; autoLogoutMinutes: number; + soundSettings: Settings; + notificationSettings: Settings; } diff --git a/hooks/useSound.tsx b/hooks/useSound.tsx new file mode 100644 index 0000000..38580b9 --- /dev/null +++ b/hooks/useSound.tsx @@ -0,0 +1,30 @@ +import { useRef, useCallback } from "react"; + +const audioCache = new Map(); + +export function useSound(volume = 1) { + const audioRef = useRef(null); + + const play = useCallback((src: string) => { + if (!src) return; + let audio = audioCache.get(src); + + if (!audio) { + audio = new Audio(src); + audio.volume = volume; + audio.onerror = () => { + console.error(`Failed to load audio: ${src}`); + }; + audioCache.set(src, audio); + } else { + audio.currentTime = 0; + audio.volume = volume; + } + audioRef.current = audio; + audio.play().catch((error) => { + console.error(`Failed to play audio: ${src}`, error); + }); + }, [volume]); + + return play; +} \ No newline at end of file