From 6c39ed22a3f92428dfea53eaf75a56c81dc4fddb Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 15 Nov 2024 19:43:48 +0100 Subject: [PATCH 1/5] fix: prefs empty array case --- src/lib/helpers/notifications.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/helpers/notifications.ts b/src/lib/helpers/notifications.ts index bd67a8ac5..cd4b82608 100644 --- a/src/lib/helpers/notifications.ts +++ b/src/lib/helpers/notifications.ts @@ -24,7 +24,7 @@ const notificationPrefs = (): Record => { } // for some reason, the prefs become array as default or on all clear. let's reset. - return Array.isArray(prefs.notificationPrefs) ? {} : prefs.notificationPrefs || {}; + return Array.isArray(prefs?.notificationPrefs) ? {} : prefs?.notificationPrefs ?? {}; }; function updateNotificationPrefs(parsedPrefs: Record) { From 1ea4bccedffe77acba46d4f35697929583ad8e73 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 15 Nov 2024 19:45:52 +0100 Subject: [PATCH 2/5] chore: run formatter --- src/lib/helpers/notifications.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/helpers/notifications.ts b/src/lib/helpers/notifications.ts index cd4b82608..114980389 100644 --- a/src/lib/helpers/notifications.ts +++ b/src/lib/helpers/notifications.ts @@ -24,7 +24,7 @@ const notificationPrefs = (): Record => { } // for some reason, the prefs become array as default or on all clear. let's reset. - return Array.isArray(prefs?.notificationPrefs) ? {} : prefs?.notificationPrefs ?? {}; + return Array.isArray(prefs?.notificationPrefs) ? {} : (prefs?.notificationPrefs ?? {}); }; function updateNotificationPrefs(parsedPrefs: Record) { From 81af03fa839d995aa14ba17733d021ea5615cd0c Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 15 Nov 2024 19:50:24 +0100 Subject: [PATCH 3/5] style: improve null handling --- src/lib/helpers/notifications.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/helpers/notifications.ts b/src/lib/helpers/notifications.ts index 114980389..c0cb819f9 100644 --- a/src/lib/helpers/notifications.ts +++ b/src/lib/helpers/notifications.ts @@ -19,12 +19,12 @@ const userPreferences = () => get(user)?.prefs; const notificationPrefs = (): Record => { const prefs = userPreferences(); - if (prefs === null) { + // due to php backend, empty object can be returnd as an empty array + if (prefs?.notificationPrefs === null || Array.isArray(prefs?.notificationPrefs)) { return {}; } - // for some reason, the prefs become array as default or on all clear. let's reset. - return Array.isArray(prefs?.notificationPrefs) ? {} : (prefs?.notificationPrefs ?? {}); + return prefs.notificationPrefs; }; function updateNotificationPrefs(parsedPrefs: Record) { From 04b01d03b9b91f028b3acc9c187ef7d09e11bdc9 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 15 Nov 2024 19:59:00 +0100 Subject: [PATCH 4/5] fix: code style --- src/lib/helpers/notifications.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/helpers/notifications.ts b/src/lib/helpers/notifications.ts index c0cb819f9..0b0956b70 100644 --- a/src/lib/helpers/notifications.ts +++ b/src/lib/helpers/notifications.ts @@ -18,9 +18,9 @@ const userPreferences = () => get(user)?.prefs; const notificationPrefs = (): Record => { const prefs = userPreferences(); - + console.log(prefs); // due to php backend, empty object can be returnd as an empty array - if (prefs?.notificationPrefs === null || Array.isArray(prefs?.notificationPrefs)) { + if (!prefs?.notificationPrefs || Array.isArray(prefs.notificationPrefs)) { return {}; } From 6b6c8aeb311cd76f0c05cdf62d2df4b4f57b5f1b Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 15 Nov 2024 19:59:22 +0100 Subject: [PATCH 5/5] revert: remove leftover console.log --- src/lib/helpers/notifications.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/helpers/notifications.ts b/src/lib/helpers/notifications.ts index 0b0956b70..706f67ecd 100644 --- a/src/lib/helpers/notifications.ts +++ b/src/lib/helpers/notifications.ts @@ -18,7 +18,7 @@ const userPreferences = () => get(user)?.prefs; const notificationPrefs = (): Record => { const prefs = userPreferences(); - console.log(prefs); + // due to php backend, empty object can be returnd as an empty array if (!prefs?.notificationPrefs || Array.isArray(prefs.notificationPrefs)) { return {};