about summary refs log tree commit diff
path: root/app/assets/javascripts/components/reducers
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-09-19 23:25:59 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-09-19 23:26:21 +0200
commit337462aa5e68014aa15788e4513e190b2e434d7e (patch)
treea760e80e2bc9b1fef55f118ddeb8603b20155a61 /app/assets/javascripts/components/reducers
parentf820edb463109e313e836d8e2f210927a0eba7d1 (diff)
Re-organizing components to be more modular, adding loading bars
Diffstat (limited to 'app/assets/javascripts/components/reducers')
-rw-r--r--app/assets/javascripts/components/reducers/compose.jsx36
-rw-r--r--app/assets/javascripts/components/reducers/follow.jsx19
-rw-r--r--app/assets/javascripts/components/reducers/index.jsx16
-rw-r--r--app/assets/javascripts/components/reducers/notifications.jsx2
-rw-r--r--app/assets/javascripts/components/reducers/timelines.jsx38
5 files changed, 65 insertions, 46 deletions
diff --git a/app/assets/javascripts/components/reducers/compose.jsx b/app/assets/javascripts/components/reducers/compose.jsx
index c0d9f4ff2..688c494c0 100644
--- a/app/assets/javascripts/components/reducers/compose.jsx
+++ b/app/assets/javascripts/components/reducers/compose.jsx
@@ -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')) {
diff --git a/app/assets/javascripts/components/reducers/follow.jsx b/app/assets/javascripts/components/reducers/follow.jsx
index 838f12259..e1dc293c6 100644
--- a/app/assets/javascripts/components/reducers/follow.jsx
+++ b/app/assets/javascripts/components/reducers/follow.jsx
@@ -1,22 +1,27 @@
-import * as constants from '../actions/follow';
-import Immutable                                                                                              from 'immutable';
+import {
+  FOLLOW_CHANGE,
+  FOLLOW_SUBMIT_REQUEST,
+  FOLLOW_SUBMIT_SUCCESS,
+  FOLLOW_SUBMIT_FAIL
+}                from '../actions/follow';
+import Immutable from 'immutable';
 
 const initialState = Immutable.Map({
   text: '',
   is_submitting: false
 });
 
-export default function compose(state = initialState, action) {
+export default function follow(state = initialState, action) {
   switch(action.type) {
-    case constants.FOLLOW_CHANGE:
+    case FOLLOW_CHANGE:
       return state.set('text', action.text);
-    case constants.FOLLOW_SUBMIT_REQUEST:
+    case FOLLOW_SUBMIT_REQUEST:
       return state.set('is_submitting', true);
-    case constants.FOLLOW_SUBMIT_SUCCESS:
+    case FOLLOW_SUBMIT_SUCCESS:
       return state.withMutations(map => {
         map.set('text', '').set('is_submitting', false);
       });
-    case constants.FOLLOW_SUBMIT_FAIL:
+    case FOLLOW_SUBMIT_FAIL:
       return state.set('is_submitting', false);
     default:
       return state;
diff --git a/app/assets/javascripts/components/reducers/index.jsx b/app/assets/javascripts/components/reducers/index.jsx
index 6d275654a..da9ab1a21 100644
--- a/app/assets/javascripts/components/reducers/index.jsx
+++ b/app/assets/javascripts/components/reducers/index.jsx
@@ -1,14 +1,16 @@
-import { combineReducers } from 'redux-immutable';
-import timelines           from './timelines';
-import meta                from './meta';
-import compose             from './compose';
-import follow              from './follow';
-import notifications       from './notifications';
+import { combineReducers }   from 'redux-immutable';
+import timelines             from './timelines';
+import meta                  from './meta';
+import compose               from './compose';
+import follow                from './follow';
+import notifications         from './notifications';
+import { loadingBarReducer } from 'react-redux-loading-bar';
 
 export default combineReducers({
   timelines,
   meta,
   compose,
   follow,
-  notifications
+  notifications,
+  loadingBar: loadingBarReducer,
 });
diff --git a/app/assets/javascripts/components/reducers/notifications.jsx b/app/assets/javascripts/components/reducers/notifications.jsx
index bdd2de993..694d9ff4b 100644
--- a/app/assets/javascripts/components/reducers/notifications.jsx
+++ b/app/assets/javascripts/components/reducers/notifications.jsx
@@ -24,7 +24,7 @@ function notificationFromError(state, error) {
   return state.push(n);
 };
 
-export default function meta(state = initialState, action) {
+export default function notifications(state = initialState, action) {
   switch(action.type) {
     case COMPOSE_SUBMIT_FAIL:
     case COMPOSE_UPLOAD_FAIL:
diff --git a/app/assets/javascripts/components/reducers/timelines.jsx b/app/assets/javascripts/components/reducers/timelines.jsx
index 04a49e16d..2bc4e6eb6 100644
--- a/app/assets/javascripts/components/reducers/timelines.jsx
+++ b/app/assets/javascripts/components/reducers/timelines.jsx
@@ -45,7 +45,7 @@ export function selectStatus(state, id) {
   return status;
 };
 
-function statusToMaps(state, status) {
+function normalizeStatus(state, status) {
   // Separate account
   let account = status.get('account');
   status = status.set('account', account.get('id'));
@@ -55,7 +55,7 @@ function statusToMaps(state, status) {
 
   if (reblog !== null) {
     status = status.set('reblog', reblog.get('id'));
-    state  = statusToMaps(state, reblog);
+    state  = normalizeStatus(state, reblog);
   }
 
   // Replies
@@ -80,26 +80,26 @@ function statusToMaps(state, status) {
   });
 };
 
-function timelineToMaps(state, timeline, statuses) {
+function normalizeTimeline(state, timeline, statuses) {
   statuses.forEach((status, i) => {
-    state = statusToMaps(state, status);
+    state = normalizeStatus(state, status);
     state = state.setIn([timeline, i], status.get('id'));
   });
 
   return state;
 };
 
-function accountTimelineToMaps(state, accountId, statuses) {
+function normalizeAccountTimeline(state, accountId, statuses) {
   statuses.forEach((status, i) => {
-    state = statusToMaps(state, status);
+    state = normalizeStatus(state, status);
     state = state.updateIn(['accounts_timelines', accountId], Immutable.List(), list => list.set(i, status.get('id')));
   });
 
   return state;
 };
 
-function updateTimelineWithMaps(state, timeline, status) {
-  state = statusToMaps(state, status);
+function updateTimeline(state, timeline, status) {
+  state = normalizeStatus(state, status);
   state = state.update(timeline, list => list.unshift(status.get('id')));
   state = state.updateIn(['accounts_timelines', status.getIn(['account', 'id'])], Immutable.List(), list => list.unshift(status.get('id')));
 
@@ -114,20 +114,20 @@ function deleteStatus(state, id) {
   return state.deleteIn(['statuses', id]);
 };
 
-function accountToMaps(state, account) {
+function normalizeAccount(state, account) {
   return state.setIn(['accounts', account.get('id')], account);
 };
 
-function contextToMaps(state, status, ancestors, descendants) {
-  state = statusToMaps(state, status);
+function normalizeContext(state, status, ancestors, descendants) {
+  state = normalizeStatus(state, status);
 
   let ancestorsIds = ancestors.map(ancestor => {
-    state = statusToMaps(state, ancestor);
+    state = normalizeStatus(state, ancestor);
     return ancestor.get('id');
   }).toOrderedSet();
 
   let descendantsIds = descendants.map(descendant => {
-    state = statusToMaps(state, descendant);
+    state = normalizeStatus(state, descendant);
     return descendant.get('id');
   }).toOrderedSet();
 
@@ -140,14 +140,14 @@ function contextToMaps(state, status, ancestors, descendants) {
 export default function timelines(state = initialState, action) {
   switch(action.type) {
     case TIMELINE_SET:
-      return timelineToMaps(state, action.timeline, Immutable.fromJS(action.statuses));
+      return normalizeTimeline(state, action.timeline, Immutable.fromJS(action.statuses));
     case TIMELINE_UPDATE:
-      return updateTimelineWithMaps(state, action.timeline, Immutable.fromJS(action.status));
+      return updateTimeline(state, action.timeline, Immutable.fromJS(action.status));
     case TIMELINE_DELETE:
       return deleteStatus(state, action.id);
     case REBLOG_SUCCESS:
     case FAVOURITE_SUCCESS:
-      return statusToMaps(state, Immutable.fromJS(action.response));
+      return normalizeStatus(state, Immutable.fromJS(action.response));
     case ACCOUNT_SET_SELF:
       return state.withMutations(map => {
         map.setIn(['accounts', action.account.id], Immutable.fromJS(action.account));
@@ -157,11 +157,11 @@ export default function timelines(state = initialState, action) {
     case FOLLOW_SUBMIT_SUCCESS:
     case ACCOUNT_FOLLOW_SUCCESS:
     case ACCOUNT_UNFOLLOW_SUCCESS:
-      return accountToMaps(state, Immutable.fromJS(action.account));
+      return normalizeAccount(state, Immutable.fromJS(action.account));
     case STATUS_FETCH_SUCCESS:
-      return contextToMaps(state, Immutable.fromJS(action.status), Immutable.fromJS(action.context.ancestors), Immutable.fromJS(action.context.descendants));
+      return normalizeContext(state, Immutable.fromJS(action.status), Immutable.fromJS(action.context.ancestors), Immutable.fromJS(action.context.descendants));
     case ACCOUNT_TIMELINE_FETCH_SUCCESS:
-      return accountTimelineToMaps(state, action.id, Immutable.fromJS(action.statuses));
+      return normalizeAccountTimeline(state, action.id, Immutable.fromJS(action.statuses));
     default:
       return state;
   }