From 986c2e79e67e0a0d097639a1998bd60f308827b2 Mon Sep 17 00:00:00 2001 From: Lina Date: Mon, 19 Jan 2026 15:44:56 +0100 Subject: [PATCH 1/5] Added hook useSound --- hooks/useSound.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 hooks/useSound.tsx diff --git a/hooks/useSound.tsx b/hooks/useSound.tsx new file mode 100644 index 0000000..996d55d --- /dev/null +++ b/hooks/useSound.tsx @@ -0,0 +1,14 @@ +import { useRef } from "react"; + +export function useSound(volume = 1) { + const audioRef = useRef(null); + + const play = (src: string) => { + if (!src) return; + audioRef.current = new Audio(src); + audioRef.current.volume = volume; + audioRef.current.play().catch(() => { }); + }; + + return play; +} \ No newline at end of file From 46fe1889bba5a5baeb0e195143a8cd98d7b750e4 Mon Sep 17 00:00:00 2001 From: Lina Date: Tue, 20 Jan 2026 11:54:42 +0100 Subject: [PATCH 2/5] Added soundSettings to User --- components/inbox-mail/types-mail.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/inbox-mail/types-mail.tsx b/components/inbox-mail/types-mail.tsx index 6dfe86b..a554f62 100644 --- a/components/inbox-mail/types-mail.tsx +++ b/components/inbox-mail/types-mail.tsx @@ -52,6 +52,11 @@ export type User = { logoutUrl: string; isAdmin: boolean; autoLogoutMinutes: number; + soundSettings: { + soundName: string; + onlyForLongTasks: boolean; + onlyIfNotInFocus: boolean; + }; } From 4c836b63dd47f42b7400bbf1b32844f58a121b2e Mon Sep 17 00:00:00 2001 From: Lina Date: Wed, 21 Jan 2026 11:25:32 +0100 Subject: [PATCH 3/5] Notification settings added in user settings --- components/inbox-mail/types-mail.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/components/inbox-mail/types-mail.tsx b/components/inbox-mail/types-mail.tsx index a554f62..5836173 100644 --- a/components/inbox-mail/types-mail.tsx +++ b/components/inbox-mail/types-mail.tsx @@ -41,6 +41,13 @@ export type InboxMailThread = { } } +export type Settings = { + soundName: string; + onlyForLongTasks: boolean; + onlyIfNotInFocus: boolean; +} + + export type User = { id: string; organizationId: string; @@ -52,11 +59,8 @@ export type User = { logoutUrl: string; isAdmin: boolean; autoLogoutMinutes: number; - soundSettings: { - soundName: string; - onlyForLongTasks: boolean; - onlyIfNotInFocus: boolean; - }; + soundSettings: Settings; + notificationSettings: Settings; } From abe170311db80cfbeb37e3f93120058956c9792c Mon Sep 17 00:00:00 2001 From: Lina Date: Wed, 21 Jan 2026 16:23:55 +0100 Subject: [PATCH 4/5] Types changed --- components/inbox-mail/types-mail.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/inbox-mail/types-mail.tsx b/components/inbox-mail/types-mail.tsx index 5836173..c2b8844 100644 --- a/components/inbox-mail/types-mail.tsx +++ b/components/inbox-mail/types-mail.tsx @@ -42,7 +42,8 @@ export type InboxMailThread = { } export type Settings = { - soundName: string; + soundName?: string; + enabled?: boolean; onlyForLongTasks: boolean; onlyIfNotInFocus: boolean; } From 5aab9c9e4de3afe68a2ca8ff4c8f1e85564f1a82 Mon Sep 17 00:00:00 2001 From: Lina Date: Wed, 28 Jan 2026 15:40:18 +0100 Subject: [PATCH 5/5] PR comments --- hooks/useSound.tsx | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/hooks/useSound.tsx b/hooks/useSound.tsx index 996d55d..38580b9 100644 --- a/hooks/useSound.tsx +++ b/hooks/useSound.tsx @@ -1,14 +1,30 @@ -import { useRef } from "react"; +import { useRef, useCallback } from "react"; + +const audioCache = new Map(); export function useSound(volume = 1) { const audioRef = useRef(null); - const play = (src: string) => { + const play = useCallback((src: string) => { if (!src) return; - audioRef.current = new Audio(src); - audioRef.current.volume = volume; - audioRef.current.play().catch(() => { }); - }; + 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