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