2022-06-12 07:14:46 -07:00
|
|
|
import { Record as ImmutableRecord } from 'immutable';
|
2020-03-27 13:59:38 -07:00
|
|
|
|
|
|
|
import {
|
|
|
|
MUTES_INIT_MODAL,
|
|
|
|
MUTES_TOGGLE_HIDE_NOTIFICATIONS,
|
2022-07-31 02:57:31 -07:00
|
|
|
MUTES_CHANGE_DURATION,
|
2020-03-27 13:59:38 -07:00
|
|
|
} from '../actions/mutes';
|
|
|
|
|
2022-06-12 07:14:46 -07:00
|
|
|
import type { AnyAction } from 'redux';
|
|
|
|
|
|
|
|
const NewMuteRecord = ImmutableRecord({
|
|
|
|
isSubmitting: false,
|
|
|
|
accountId: null,
|
|
|
|
notifications: true,
|
2022-07-31 02:57:31 -07:00
|
|
|
duration: 0,
|
2022-06-12 07:14:46 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
const ReducerRecord = ImmutableRecord({
|
|
|
|
new: NewMuteRecord(),
|
2020-03-27 13:59:38 -07:00
|
|
|
});
|
|
|
|
|
2022-06-12 07:14:46 -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);
|
2022-06-12 07:14:46 -07:00
|
|
|
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);
|
2022-07-31 02:57:31 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|