Merge pull request #1518 from appwrite/fix-prefs-empty-case

fix: prefs empty array case
This commit is contained in:
Steven Nguyen
2024-11-15 11:08:08 -08:00
committed by GitHub
+3 -3
View File
@@ -19,12 +19,12 @@ const userPreferences = () => get(user)?.prefs;
const notificationPrefs = (): Record<string, NotificationPrefItem> => {
const prefs = userPreferences();
if (prefs === null) {
// due to php backend, empty object can be returnd as an empty array
if (!prefs?.notificationPrefs || 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<string, NotificationPrefItem>) {