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.

79 lines
2.0 KiB

  1. import { SETTING_CHANGE } from '../actions/settings';
  2. import { COLUMN_ADD, COLUMN_REMOVE, COLUMN_MOVE } from '../actions/columns';
  3. import { STORE_HYDRATE } from '../actions/store';
  4. import Immutable from 'immutable';
  5. import uuid from '../uuid';
  6. const initialState = Immutable.Map({
  7. onboarded: false,
  8. columns: Immutable.fromJS([
  9. { id: 'COMPOSE', uuid: uuid(), params: {} },
  10. { id: 'HOME', uuid: uuid(), params: {} },
  11. { id: 'NOTIFICATIONS', uuid: uuid(), params: {} },
  12. ]),
  13. home: Immutable.Map({
  14. shows: Immutable.Map({
  15. reblog: true,
  16. reply: true,
  17. }),
  18. regex: Immutable.Map({
  19. body: '',
  20. }),
  21. }),
  22. notifications: Immutable.Map({
  23. alerts: Immutable.Map({
  24. follow: true,
  25. favourite: true,
  26. reblog: true,
  27. mention: true,
  28. }),
  29. shows: Immutable.Map({
  30. follow: true,
  31. favourite: true,
  32. reblog: true,
  33. mention: true,
  34. }),
  35. sounds: Immutable.Map({
  36. follow: true,
  37. favourite: true,
  38. reblog: true,
  39. mention: true,
  40. }),
  41. }),
  42. });
  43. const moveColumn = (state, uuid, direction) => {
  44. const columns = state.get('columns');
  45. const index = columns.findIndex(item => item.get('uuid') === uuid);
  46. const newIndex = index + direction;
  47. let newColumns;
  48. newColumns = columns.splice(index, 1);
  49. newColumns = newColumns.splice(newIndex, 0, columns.get(index));
  50. return state.set('columns', newColumns);
  51. };
  52. export default function settings(state = initialState, action) {
  53. switch(action.type) {
  54. case STORE_HYDRATE:
  55. return state.mergeDeep(action.state.get('settings'));
  56. case SETTING_CHANGE:
  57. return state.setIn(action.key, action.value);
  58. case COLUMN_ADD:
  59. return state.update('columns', list => list.push(Immutable.fromJS({ id: action.id, uuid: uuid(), params: action.params })));
  60. case COLUMN_REMOVE:
  61. return state.update('columns', list => list.filterNot(item => item.get('uuid') === action.uuid));
  62. case COLUMN_MOVE:
  63. return moveColumn(state, action.uuid, action.direction);
  64. default:
  65. return state;
  66. }
  67. };