From 93b2c8164ec40da95f138d0b038d018863eb7ea3 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 16 Sep 2024 16:51:56 +0200 Subject: [PATCH] [Glitch] Fix selectSettingsNotificationsExcludedTypes not being memoized properly Port ca8e892c1abb91722c256030c83cabec8e3445ff to glitch-soc Signed-off-by: Claire --- .../flavours/glitch/selectors/settings.ts | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/app/javascript/flavours/glitch/selectors/settings.ts b/app/javascript/flavours/glitch/selectors/settings.ts index 9a1a2c990b..d66f00f0e1 100644 --- a/app/javascript/flavours/glitch/selectors/settings.ts +++ b/app/javascript/flavours/glitch/selectors/settings.ts @@ -1,17 +1,27 @@ +import { createSelector } from '@reduxjs/toolkit'; + import type { RootState } from 'flavours/glitch/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 selectSettingsNotificationsShows = createSelector( + [ + (state) => + state.settings.getIn(['notifications', 'shows']) as Immutable.Map< + string, + boolean + >, + ], + (shows) => shows.toJS() as Record, +); -export const selectSettingsNotificationsExcludedTypes = (state: RootState) => - Object.entries(selectSettingsNotificationsShows(state)) - .filter(([_type, enabled]) => !enabled) - .map(([type, _enabled]) => type); +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;