2016-09-05 10:56:43 -04:00
|
|
|
import * as constants from '../actions/compose';
|
|
|
|
import { TIMELINE_DELETE } from '../actions/timelines';
|
|
|
|
import Immutable from 'immutable';
|
2016-08-31 10:15:12 -04:00
|
|
|
|
|
|
|
const initialState = Immutable.Map({
|
|
|
|
text: '',
|
2016-08-31 16:58:10 -04:00
|
|
|
in_reply_to: null,
|
2016-09-07 12:17:15 -04:00
|
|
|
is_submitting: false,
|
|
|
|
is_uploading: false,
|
|
|
|
progress: 0,
|
|
|
|
media_attachments: Immutable.List([])
|
2016-08-31 10:15:12 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
export default function compose(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
2016-08-31 16:58:10 -04:00
|
|
|
case constants.COMPOSE_CHANGE:
|
2016-08-31 10:15:12 -04:00
|
|
|
return state.set('text', action.text);
|
2016-08-31 16:58:10 -04:00
|
|
|
case constants.COMPOSE_REPLY:
|
2016-08-31 10:15:12 -04:00
|
|
|
return state.withMutations(map => {
|
2016-09-05 10:56:43 -04:00
|
|
|
map.set('in_reply_to', action.status.get('id'));
|
|
|
|
map.set('text', `@${action.status.getIn(['account', 'acct'])} `);
|
2016-08-31 10:15:12 -04:00
|
|
|
});
|
2016-08-31 16:58:10 -04:00
|
|
|
case constants.COMPOSE_REPLY_CANCEL:
|
|
|
|
return state.withMutations(map => {
|
2016-09-07 12:17:15 -04:00
|
|
|
map.set('in_reply_to', null);
|
|
|
|
map.set('text', '');
|
2016-08-31 16:58:10 -04:00
|
|
|
});
|
|
|
|
case constants.COMPOSE_SUBMIT_REQUEST:
|
|
|
|
return state.set('is_submitting', true);
|
|
|
|
case constants.COMPOSE_SUBMIT_SUCCESS:
|
|
|
|
return state.withMutations(map => {
|
2016-09-07 12:17:15 -04:00
|
|
|
map.set('text', '');
|
|
|
|
map.set('is_submitting', false);
|
|
|
|
map.set('in_reply_to', null);
|
|
|
|
map.update('media_attachments', list => list.clear());
|
2016-08-31 16:58:10 -04:00
|
|
|
});
|
|
|
|
case constants.COMPOSE_SUBMIT_FAIL:
|
|
|
|
return state.set('is_submitting', false);
|
2016-09-07 12:17:15 -04:00
|
|
|
case constants.COMPOSE_UPLOAD_REQUEST:
|
|
|
|
return state.set('is_uploading', true);
|
|
|
|
case constants.COMPOSE_UPLOAD_SUCCESS:
|
|
|
|
return state.withMutations(map => {
|
|
|
|
map.update('media_attachments', list => list.push(Immutable.fromJS(action.media)));
|
|
|
|
map.set('is_uploading', false);
|
|
|
|
});
|
|
|
|
case constants.COMPOSE_UPLOAD_FAIL:
|
|
|
|
return state.set('is_uploading', false);
|
|
|
|
case constants.COMPOSE_UPLOAD_UNDO:
|
|
|
|
return state.update('media_attachments', list => list.filterNot(item => item.get('id') === action.media_id));
|
|
|
|
case constants.COMPOSE_UPLOAD_PROGRESS:
|
|
|
|
return state.set('progress', Math.round((action.loaded / action.total) * 100));
|
2016-09-05 10:56:43 -04:00
|
|
|
case TIMELINE_DELETE:
|
|
|
|
if (action.id === state.get('in_reply_to')) {
|
|
|
|
return state.set('in_reply_to', null);
|
|
|
|
} else {
|
|
|
|
return state;
|
|
|
|
}
|
2016-08-31 10:15:12 -04:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2016-09-12 13:20:55 -04:00
|
|
|
};
|