about summary refs log tree commit diff
path: root/app/javascript/mastodon/reducers/settings.js
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-06-04 01:39:38 +0200
committerGitHub <noreply@github.com>2017-06-04 01:39:38 +0200
commit8ee2eb5d2e7bd3c601c0277f12d8ad0c5f84cc43 (patch)
tree2c51c5c5cd47273cf1b66d553e1cc5c7f762a0f8 /app/javascript/mastodon/reducers/settings.js
parent20b647020bf8de2af6d2ce44ed76566d137dd1f6 (diff)
Allow mounting arbitrary columns (#3207)
* Allow mounting arbitrary columns

* Refactor column headers, allow pinning/unpinning and moving columns around

* Collapse animation

* Re-introduce scroll to top

* Save column settings properly, do not display pin options in
single-column view, do not display collapse icon if there is
nothing to collapse

* Fix one instance of public timeline being closed closing the stream
Fix back buttons inconsistently sending you back to / even if history exists

* Getting started displays links to columns that are not mounted
Diffstat (limited to 'app/javascript/mastodon/reducers/settings.js')
-rw-r--r--app/javascript/mastodon/reducers/settings.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/javascript/mastodon/reducers/settings.js b/app/javascript/mastodon/reducers/settings.js
index ababd4983..ad70806b1 100644
--- a/app/javascript/mastodon/reducers/settings.js
+++ b/app/javascript/mastodon/reducers/settings.js
@@ -1,10 +1,18 @@
 import { SETTING_CHANGE } from '../actions/settings';
+import { COLUMN_ADD, COLUMN_REMOVE, COLUMN_MOVE } from '../actions/columns';
 import { STORE_HYDRATE } from '../actions/store';
 import Immutable from 'immutable';
+import uuid from '../uuid';
 
 const initialState = Immutable.Map({
   onboarded: false,
 
+  columns: Immutable.fromJS([
+    { id: 'COMPOSE', uuid: uuid(), params: {} },
+    { id: 'HOME', uuid: uuid(), params: {} },
+    { id: 'NOTIFICATIONS', uuid: uuid(), params: {} },
+  ]),
+
   home: Immutable.Map({
     shows: Immutable.Map({
       reblog: true,
@@ -40,12 +48,31 @@ const initialState = Immutable.Map({
   }),
 });
 
+const moveColumn = (state, uuid, direction) => {
+  const columns  = state.get('columns');
+  const index    = columns.findIndex(item => item.get('uuid') === uuid);
+  const newIndex = index + direction;
+
+  let newColumns;
+
+  newColumns = columns.splice(index, 1);
+  newColumns = newColumns.splice(newIndex, 0, columns.get(index));
+
+  return state.set('columns', newColumns);
+};
+
 export default function settings(state = initialState, action) {
   switch(action.type) {
   case STORE_HYDRATE:
     return state.mergeDeep(action.state.get('settings'));
   case SETTING_CHANGE:
     return state.setIn(action.key, action.value);
+  case COLUMN_ADD:
+    return state.update('columns', list => list.push(Immutable.fromJS({ id: action.id, uuid: uuid(), params: action.params })));
+  case COLUMN_REMOVE:
+    return state.update('columns', list => list.filterNot(item => item.get('uuid') === action.uuid));
+  case COLUMN_MOVE:
+    return moveColumn(state, action.uuid, action.direction);
   default:
     return state;
   }