Skip to content

Commit

Permalink
refactor: onChannelToggle updated for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
eemaanamir committed Jan 23, 2024
1 parent a3497ad commit a6699f9
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/notification-preferences/NotificationPreferenceApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,16 @@ const NotificationPreferenceApp = ({ appId }) => {
const updatePreferencesStatus = useSelector(selectUpdatePreferencesStatus());
const nonEditable = useSelector(selectNonEditablePreferences(appId));

const onChannelToggle = useCallback(
(event) => {
const { id: notificationChannel } = event.target;
const activePreferences = appPreferences.filter((preference) => preference[notificationChannel] === true
&& !nonEditable?.[preference.id]?.includes(notificationChannel));
dispatch(updateChannelPreferenceToggle(
courseId,
appId,
notificationChannel,
!(activePreferences.length > 0),
));
},
[appId, appPreferences, courseId, dispatch, nonEditable],
);
const onChannelToggle = useCallback((event) => {
const { id: notificationChannel } = event.target;
const isPreferenceNonEditable = (preference) => nonEditable?.[preference.id]?.includes(notificationChannel)
|| false;

const truePreferences = appPreferences.filter((preference) => preference[notificationChannel] === true
&& !isPreferenceNonEditable(preference));

dispatch(updateChannelPreferenceToggle(courseId, appId, notificationChannel, truePreferences.length === 0));
}, [appId, appPreferences, courseId, dispatch, nonEditable]);

const preferences = useMemo(() => (
appPreferences.map(preference => (
Expand Down

0 comments on commit a6699f9

Please sign in to comment.