Re-organizing components to be more modular, adding loading bars
This commit is contained in:
@ -1,4 +1,16 @@
|
||||
import * as constants from '../actions/compose';
|
||||
import {
|
||||
COMPOSE_CHANGE,
|
||||
COMPOSE_REPLY,
|
||||
COMPOSE_REPLY_CANCEL,
|
||||
COMPOSE_SUBMIT_REQUEST,
|
||||
COMPOSE_SUBMIT_SUCCESS,
|
||||
COMPOSE_SUBMIT_FAIL,
|
||||
COMPOSE_UPLOAD_REQUEST,
|
||||
COMPOSE_UPLOAD_SUCCESS,
|
||||
COMPOSE_UPLOAD_FAIL,
|
||||
COMPOSE_UPLOAD_UNDO,
|
||||
COMPOSE_UPLOAD_PROGRESS
|
||||
} from '../actions/compose';
|
||||
import { TIMELINE_DELETE } from '../actions/timelines';
|
||||
import Immutable from 'immutable';
|
||||
|
||||
@ -13,41 +25,41 @@ const initialState = Immutable.Map({
|
||||
|
||||
export default function compose(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case constants.COMPOSE_CHANGE:
|
||||
case COMPOSE_CHANGE:
|
||||
return state.set('text', action.text);
|
||||
case constants.COMPOSE_REPLY:
|
||||
case COMPOSE_REPLY:
|
||||
return state.withMutations(map => {
|
||||
map.set('in_reply_to', action.status.get('id'));
|
||||
map.set('text', `@${action.status.getIn(['account', 'acct'])} `);
|
||||
});
|
||||
case constants.COMPOSE_REPLY_CANCEL:
|
||||
case COMPOSE_REPLY_CANCEL:
|
||||
return state.withMutations(map => {
|
||||
map.set('in_reply_to', null);
|
||||
map.set('text', '');
|
||||
});
|
||||
case constants.COMPOSE_SUBMIT_REQUEST:
|
||||
case COMPOSE_SUBMIT_REQUEST:
|
||||
return state.set('is_submitting', true);
|
||||
case constants.COMPOSE_SUBMIT_SUCCESS:
|
||||
case COMPOSE_SUBMIT_SUCCESS:
|
||||
return state.withMutations(map => {
|
||||
map.set('text', '');
|
||||
map.set('is_submitting', false);
|
||||
map.set('in_reply_to', null);
|
||||
map.update('media_attachments', list => list.clear());
|
||||
});
|
||||
case constants.COMPOSE_SUBMIT_FAIL:
|
||||
case COMPOSE_SUBMIT_FAIL:
|
||||
return state.set('is_submitting', false);
|
||||
case constants.COMPOSE_UPLOAD_REQUEST:
|
||||
case COMPOSE_UPLOAD_REQUEST:
|
||||
return state.set('is_uploading', true);
|
||||
case constants.COMPOSE_UPLOAD_SUCCESS:
|
||||
case 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:
|
||||
case COMPOSE_UPLOAD_FAIL:
|
||||
return state.set('is_uploading', false);
|
||||
case constants.COMPOSE_UPLOAD_UNDO:
|
||||
case COMPOSE_UPLOAD_UNDO:
|
||||
return state.update('media_attachments', list => list.filterNot(item => item.get('id') === action.media_id));
|
||||
case constants.COMPOSE_UPLOAD_PROGRESS:
|
||||
case COMPOSE_UPLOAD_PROGRESS:
|
||||
return state.set('progress', Math.round((action.loaded / action.total) * 100));
|
||||
case TIMELINE_DELETE:
|
||||
if (action.id === state.get('in_reply_to')) {
|
||||
|
Reference in New Issue
Block a user