bigbuffet-rw/app/soapbox/reducers/mutes.ts

40 lines
1 KiB
TypeScript
Raw Normal View History

import { Record as ImmutableRecord } from 'immutable';
2020-03-27 13:59:38 -07:00
import {
MUTES_INIT_MODAL,
MUTES_TOGGLE_HIDE_NOTIFICATIONS,
MUTES_CHANGE_DURATION,
2020-03-27 13:59:38 -07:00
} from '../actions/mutes';
import type { AnyAction } from 'redux';
const NewMuteRecord = ImmutableRecord({
isSubmitting: false,
accountId: null,
notifications: true,
duration: 0,
});
const ReducerRecord = ImmutableRecord({
new: NewMuteRecord(),
2020-03-27 13:59:38 -07:00
});
type State = ReturnType<typeof ReducerRecord>;
export default function mutes(state: State = ReducerRecord(), action: AnyAction) {
2020-03-27 13:59:38 -07:00
switch (action.type) {
2022-05-11 14:06:35 -07:00
case MUTES_INIT_MODAL:
return state.withMutations((state) => {
state.setIn(['new', 'isSubmitting'], false);
state.setIn(['new', 'accountId'], action.account.id);
2022-05-11 14:06:35 -07:00
state.setIn(['new', 'notifications'], true);
});
case MUTES_TOGGLE_HIDE_NOTIFICATIONS:
return state.updateIn(['new', 'notifications'], (old) => !old);
case MUTES_CHANGE_DURATION:
return state.setIn(['new', 'duration'], action.duration);
2022-05-11 14:06:35 -07:00
default:
return state;
2020-03-27 13:59:38 -07:00
}
}