You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.2 KiB

  1. import * as constants from '../actions/compose';
  2. import Immutable from 'immutable';
  3. const initialState = Immutable.Map({
  4. text: '',
  5. in_reply_to: null,
  6. is_submitting: false
  7. });
  8. export default function compose(state = initialState, action) {
  9. switch(action.type) {
  10. case constants.COMPOSE_CHANGE:
  11. return state.set('text', action.text);
  12. case constants.COMPOSE_REPLY:
  13. return state.withMutations(map => {
  14. map.set('in_reply_to', action.payload).set('text', `@${action.payload.getIn(['account', 'acct'])} `);
  15. });
  16. case constants.COMPOSE_REPLY_CANCEL:
  17. return state.withMutations(map => {
  18. map.set('in_reply_to', null).set('text', '');
  19. });
  20. case constants.COMPOSE_SUBMIT_REQUEST:
  21. return state.set('is_submitting', true);
  22. case constants.COMPOSE_SUBMIT_SUCCESS:
  23. return state.withMutations(map => {
  24. map.set('text', '').set('is_submitting', false),set('in_reply_to', null);
  25. });
  26. case constants.COMPOSE_SUBMIT_FAIL:
  27. return state.set('is_submitting', false);
  28. default:
  29. return state;
  30. }
  31. }