From 09c02cb367d450d35a11d001b8edc95463c4a01f Mon Sep 17 00:00:00 2001 From: eemaanamir Date: Wed, 24 Jan 2024 16:35:19 +0500 Subject: [PATCH] perf: updated onChannelToggle to improve performance --- src/notification-preferences/NotificationPreferenceApp.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/notification-preferences/NotificationPreferenceApp.jsx b/src/notification-preferences/NotificationPreferenceApp.jsx index 3ca9f98a2..480ddd919 100644 --- a/src/notification-preferences/NotificationPreferenceApp.jsx +++ b/src/notification-preferences/NotificationPreferenceApp.jsx @@ -31,11 +31,11 @@ const NotificationPreferenceApp = ({ appId }) => { const { id: notificationChannel } = event.target; const isPreferenceNonEditable = (preference) => nonEditable?.[preference.id]?.includes(notificationChannel); - const activePreferences = appPreferences.filter( + const hasActivePreferences = appPreferences.some( (preference) => preference[notificationChannel] && !isPreferenceNonEditable(preference), ); - dispatch(updateChannelPreferenceToggle(courseId, appId, notificationChannel, activePreferences.length === 0)); + dispatch(updateChannelPreferenceToggle(courseId, appId, notificationChannel, !hasActivePreferences)); }, [appId, appPreferences, courseId, dispatch, nonEditable]); const preferences = useMemo(() => (