Skip to content

Commit

Permalink
standardise defaultSettingsMiddleware.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
faiqali1 committed Aug 3, 2023
1 parent b1294d2 commit 0c84cc0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/redux/middleware/defaultSettingsMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Middleware } from 'redux';

import { RootState } from '../RootState';
import { setIsUsingDefaultSettings } from '../slices/defaultSettings';
import { setIsUsingDefaultSettingsAction } from '../slices/defaultSettings';
import SliceName from '../types/SliceName';

import { RESET_SETTINGS_EVENT } from '@/redux/actions/reset-settings';
Expand Down Expand Up @@ -46,9 +46,11 @@ const DefaultSettingsMiddleware: Middleware<
const { type } = action;
// the moment any of the actions that change the settings has changed, it means we are no longer using the default settings
if (OBSERVED_ACTIONS.includes(type)) {
storeAPI.dispatch({ type: setIsUsingDefaultSettings.type, payload: false });
// storeAPI.dispatch({ type: setIsUsingDefaultSettings.type, payload: false });
storeAPI.dispatch(setIsUsingDefaultSettingsAction(false));
} else if (type === RESET_SETTINGS_EVENT) {
storeAPI.dispatch({ type: setIsUsingDefaultSettings.type, payload: true });
// storeAPI.dispatch({ type: setIsUsingDefaultSettings.type, payload: true });
storeAPI.dispatch(setIsUsingDefaultSettingsAction(true));
}
return next(action);
};
Expand Down
5 changes: 5 additions & 0 deletions src/redux/slices/defaultSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export const persistDefaultSettings = createAsyncThunk<void, string, { state: Ro

export const { setIsUsingDefaultSettings } = defaultSettingsSlice.actions;

export const setIsUsingDefaultSettingsAction = (isUsingDefaultSettings: boolean) => ({
type: setIsUsingDefaultSettings.type,
payload: isUsingDefaultSettings,
});

export default defaultSettingsSlice.reducer;

export const selectIsUsingDefaultSettings = (state: RootState) =>
Expand Down

0 comments on commit 0c84cc0

Please sign in to comment.