Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions components/inbox-mail/types-mail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,6 +60,8 @@ export type User = {
logoutUrl: string;
isAdmin: boolean;
autoLogoutMinutes: number;
soundSettings: Settings;
notificationSettings: Settings;
}


Expand Down
30 changes: 30 additions & 0 deletions hooks/useSound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useRef, useCallback } from "react";

const audioCache = new Map<string, HTMLAudioElement>();

export function useSound(volume = 1) {
const audioRef = useRef<HTMLAudioElement | null>(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;
}