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

44 lines
1.3 KiB
TypeScript
Raw Normal View History

import { Record as ImmutableRecord } from 'immutable';
import {
ACCOUNT_NOTE_INIT_MODAL,
ACCOUNT_NOTE_CHANGE_COMMENT,
ACCOUNT_NOTE_SUBMIT_REQUEST,
ACCOUNT_NOTE_SUBMIT_FAIL,
ACCOUNT_NOTE_SUBMIT_SUCCESS,
2022-05-27 11:08:41 -07:00
} from '../actions/account-notes';
import type { AnyAction } from 'redux';
2022-07-06 15:02:44 -07:00
export const EditRecord = ImmutableRecord({
isSubmitting: false,
2022-07-06 15:02:44 -07:00
account: null as string | null,
comment: '',
});
2022-07-06 15:02:44 -07:00
export const ReducerRecord = ImmutableRecord({
edit: EditRecord(),
});
type State = ReturnType<typeof ReducerRecord>;
export default function account_notes(state: State = ReducerRecord(), action: AnyAction) {
switch (action.type) {
2022-05-11 14:06:35 -07:00
case ACCOUNT_NOTE_INIT_MODAL:
return state.withMutations((state) => {
state.setIn(['edit', 'isSubmitting'], false);
state.setIn(['edit', 'account'], action.account.get('id'));
2022-05-11 14:06:35 -07:00
state.setIn(['edit', 'comment'], action.comment);
});
case ACCOUNT_NOTE_CHANGE_COMMENT:
return state.setIn(['edit', 'comment'], action.comment);
case ACCOUNT_NOTE_SUBMIT_REQUEST:
return state.setIn(['edit', 'isSubmitting'], true);
case ACCOUNT_NOTE_SUBMIT_FAIL:
case ACCOUNT_NOTE_SUBMIT_SUCCESS:
return state.setIn(['edit', 'isSubmitting'], false);
default:
return state;
}
2022-05-27 11:08:41 -07:00
}