2017-01-09 13:00:55 +00:00
|
|
|
import { SETTING_CHANGE } from '../actions/settings';
|
2017-06-03 23:39:38 +00:00
|
|
|
import { COLUMN_ADD, COLUMN_REMOVE, COLUMN_MOVE } from '../actions/columns';
|
2017-01-09 13:00:55 +00:00
|
|
|
import { STORE_HYDRATE } from '../actions/store';
|
|
|
|
import Immutable from 'immutable';
|
2017-06-03 23:39:38 +00:00
|
|
|
import uuid from '../uuid';
|
2017-01-09 13:00:55 +00:00
|
|
|
|
|
|
|
const initialState = Immutable.Map({
|
2017-04-16 18:32:00 +00:00
|
|
|
onboarded: false,
|
|
|
|
|
2017-01-10 16:25:10 +00:00
|
|
|
home: Immutable.Map({
|
|
|
|
shows: Immutable.Map({
|
|
|
|
reblog: true,
|
2017-05-20 15:31:47 +00:00
|
|
|
reply: true,
|
2017-05-03 00:04:16 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
regex: Immutable.Map({
|
2017-05-20 15:31:47 +00:00
|
|
|
body: '',
|
|
|
|
}),
|
2017-01-10 16:25:10 +00:00
|
|
|
}),
|
|
|
|
|
2017-01-09 13:00:55 +00:00
|
|
|
notifications: Immutable.Map({
|
|
|
|
alerts: Immutable.Map({
|
|
|
|
follow: true,
|
|
|
|
favourite: true,
|
|
|
|
reblog: true,
|
2017-05-20 15:31:47 +00:00
|
|
|
mention: true,
|
2017-01-09 13:00:55 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
shows: Immutable.Map({
|
|
|
|
follow: true,
|
|
|
|
favourite: true,
|
|
|
|
reblog: true,
|
2017-05-20 15:31:47 +00:00
|
|
|
mention: true,
|
2017-01-17 19:09:03 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
sounds: Immutable.Map({
|
|
|
|
follow: true,
|
|
|
|
favourite: true,
|
|
|
|
reblog: true,
|
2017-05-20 15:31:47 +00:00
|
|
|
mention: true,
|
|
|
|
}),
|
2017-06-06 14:56:10 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
community: Immutable.Map({
|
|
|
|
regex: Immutable.Map({
|
|
|
|
body: '',
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
|
|
|
public: Immutable.Map({
|
|
|
|
regex: Immutable.Map({
|
|
|
|
body: '',
|
|
|
|
}),
|
2017-05-20 15:31:47 +00:00
|
|
|
}),
|
2017-01-09 13:00:55 +00:00
|
|
|
});
|
|
|
|
|
2017-06-14 19:59:52 +00:00
|
|
|
const defaultColumns = Immutable.fromJS([
|
|
|
|
{ id: 'COMPOSE', uuid: uuid(), params: {} },
|
|
|
|
{ id: 'HOME', uuid: uuid(), params: {} },
|
|
|
|
{ id: 'NOTIFICATIONS', uuid: uuid(), params: {} },
|
|
|
|
]);
|
|
|
|
|
2017-06-14 21:07:06 +00:00
|
|
|
const hydrate = (state, settings) => state.mergeDeep(settings).update('columns', (val = defaultColumns) => val);
|
2017-06-14 19:59:52 +00:00
|
|
|
|
2017-06-03 23:39:38 +00:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2017-01-09 13:00:55 +00:00
|
|
|
export default function settings(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
|
|
|
case STORE_HYDRATE:
|
2017-06-14 21:07:06 +00:00
|
|
|
return hydrate(state, action.state.get('settings'));
|
2017-01-09 13:00:55 +00:00
|
|
|
case SETTING_CHANGE:
|
|
|
|
return state.setIn(action.key, action.value);
|
2017-06-03 23:39:38 +00:00
|
|
|
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);
|
2017-01-09 13:00:55 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|