Skip to content

Commit

Permalink
Fix selectSettingsNotificationsExcludedTypes not being memoized prope…
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored Sep 16, 2024
1 parent 6c76a7a commit ca8e892
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions app/javascript/mastodon/selectors/settings.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import { createSelector } from '@reduxjs/toolkit';

import type { RootState } from 'mastodon/store';

/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */
// state.settings is not yet typed, so we disable some ESLint checks for those selectors
export const selectSettingsNotificationsShows = (state: RootState) =>
state.settings.getIn(['notifications', 'shows']).toJS() as Record<
string,
boolean
>;

export const selectSettingsNotificationsExcludedTypes = (state: RootState) =>
Object.entries(selectSettingsNotificationsShows(state))
.filter(([_type, enabled]) => !enabled)
.map(([type, _enabled]) => type);
export const selectSettingsNotificationsShows = createSelector(
[
(state) =>
state.settings.getIn(['notifications', 'shows']) as Immutable.Map<
string,
boolean
>,
],
(shows) => shows.toJS() as Record<string, boolean>,
);

export const selectSettingsNotificationsExcludedTypes = createSelector(
[selectSettingsNotificationsShows],
(shows) =>
Object.entries(shows)
.filter(([_type, enabled]) => !enabled)
.map(([type, _enabled]) => type),
);

export const selectSettingsNotificationsQuickFilterShow = (state: RootState) =>
state.settings.getIn(['notifications', 'quickFilter', 'show']) as boolean;
Expand Down

0 comments on commit ca8e892

Please sign in to comment.