You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
3.0 KiB
120 lines
3.0 KiB
7 years ago
|
import { SETTING_CHANGE, SETTING_SAVE } from 'flavours/glitch/actions/settings';
|
||
|
import { COLUMN_ADD, COLUMN_REMOVE, COLUMN_MOVE } from 'flavours/glitch/actions/columns';
|
||
|
import { STORE_HYDRATE } from 'flavours/glitch/actions/store';
|
||
|
import { EMOJI_USE } from 'flavours/glitch/actions/emojis';
|
||
7 years ago
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||
7 years ago
|
import uuid from 'flavours/glitch/util/uuid';
|
||
8 years ago
|
|
||
7 years ago
|
const initialState = ImmutableMap({
|
||
7 years ago
|
saved: true,
|
||
|
|
||
8 years ago
|
onboarded: false,
|
||
7 years ago
|
layout: 'auto',
|
||
8 years ago
|
|
||
7 years ago
|
skinTone: 1,
|
||
|
|
||
7 years ago
|
home: ImmutableMap({
|
||
|
shows: ImmutableMap({
|
||
8 years ago
|
reblog: true,
|
||
8 years ago
|
reply: true,
|
||
8 years ago
|
}),
|
||
|
|
||
7 years ago
|
regex: ImmutableMap({
|
||
8 years ago
|
body: '',
|
||
|
}),
|
||
8 years ago
|
}),
|
||
|
|
||
7 years ago
|
notifications: ImmutableMap({
|
||
|
alerts: ImmutableMap({
|
||
8 years ago
|
follow: true,
|
||
|
favourite: true,
|
||
|
reblog: true,
|
||
8 years ago
|
mention: true,
|
||
8 years ago
|
}),
|
||
|
|
||
7 years ago
|
shows: ImmutableMap({
|
||
8 years ago
|
follow: true,
|
||
|
favourite: true,
|
||
|
reblog: true,
|
||
8 years ago
|
mention: true,
|
||
8 years ago
|
}),
|
||
|
|
||
7 years ago
|
sounds: ImmutableMap({
|
||
8 years ago
|
follow: true,
|
||
|
favourite: true,
|
||
|
reblog: true,
|
||
8 years ago
|
mention: true,
|
||
|
}),
|
||
8 years ago
|
}),
|
||
|
|
||
7 years ago
|
community: ImmutableMap({
|
||
|
regex: ImmutableMap({
|
||
8 years ago
|
body: '',
|
||
|
}),
|
||
|
}),
|
||
|
|
||
7 years ago
|
public: ImmutableMap({
|
||
|
regex: ImmutableMap({
|
||
8 years ago
|
body: '',
|
||
|
}),
|
||
8 years ago
|
}),
|
||
7 years ago
|
|
||
|
direct: ImmutableMap({
|
||
|
regex: ImmutableMap({
|
||
|
body: '',
|
||
|
}),
|
||
|
}),
|
||
8 years ago
|
});
|
||
|
|
||
7 years ago
|
const defaultColumns = fromJS([
|
||
8 years ago
|
{ id: 'COMPOSE', uuid: uuid(), params: {} },
|
||
|
{ id: 'HOME', uuid: uuid(), params: {} },
|
||
|
{ id: 'NOTIFICATIONS', uuid: uuid(), params: {} },
|
||
|
]);
|
||
|
|
||
8 years ago
|
const hydrate = (state, settings) => state.mergeDeep(settings).update('columns', (val = defaultColumns) => val);
|
||
8 years ago
|
|
||
8 years ago
|
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));
|
||
|
|
||
7 years ago
|
return state
|
||
|
.set('columns', newColumns)
|
||
|
.set('saved', false);
|
||
8 years ago
|
};
|
||
|
|
||
7 years ago
|
const updateFrequentEmojis = (state, emoji) => state.update('frequentlyUsedEmojis', ImmutableMap(), map => map.update(emoji.id, 0, count => count + 1)).set('saved', false);
|
||
|
|
||
8 years ago
|
export default function settings(state = initialState, action) {
|
||
|
switch(action.type) {
|
||
|
case STORE_HYDRATE:
|
||
8 years ago
|
return hydrate(state, action.state.get('settings'));
|
||
8 years ago
|
case SETTING_CHANGE:
|
||
7 years ago
|
return state
|
||
|
.setIn(action.key, action.value)
|
||
|
.set('saved', false);
|
||
8 years ago
|
case COLUMN_ADD:
|
||
7 years ago
|
return state
|
||
|
.update('columns', list => list.push(fromJS({ id: action.id, uuid: uuid(), params: action.params })))
|
||
|
.set('saved', false);
|
||
8 years ago
|
case COLUMN_REMOVE:
|
||
7 years ago
|
return state
|
||
|
.update('columns', list => list.filterNot(item => item.get('uuid') === action.uuid))
|
||
|
.set('saved', false);
|
||
8 years ago
|
case COLUMN_MOVE:
|
||
|
return moveColumn(state, action.uuid, action.direction);
|
||
7 years ago
|
case EMOJI_USE:
|
||
|
return updateFrequentEmojis(state, action.emoji);
|
||
|
case SETTING_SAVE:
|
||
|
return state.set('saved', true);
|
||
8 years ago
|
default:
|
||
|
return state;
|
||
|
}
|
||
|
};
|