闭社主体 forked from https://github.com/tootsuite/mastodon
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.

91 lines
2.2 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. community: Immutable.Map({
  43. regex: Immutable.Map({
  44. body: '',
  45. }),
  46. }),
  47. public: Immutable.Map({
  48. regex: Immutable.Map({
  49. body: '',
  50. }),
  51. }),
  52. });
  53. const moveColumn = (state, uuid, direction) => {
  54. const columns = state.get('columns');
  55. const index = columns.findIndex(item => item.get('uuid') === uuid);
  56. const newIndex = index + direction;
  57. let newColumns;
  58. newColumns = columns.splice(index, 1);
  59. newColumns = newColumns.splice(newIndex, 0, columns.get(index));
  60. return state.set('columns', newColumns);
  61. };
  62. export default function settings(state = initialState, action) {
  63. switch(action.type) {
  64. case STORE_HYDRATE:
  65. return state.mergeDeep(action.state.get('settings'));
  66. case SETTING_CHANGE:
  67. return state.setIn(action.key, action.value);
  68. case COLUMN_ADD:
  69. return state.update('columns', list => list.push(Immutable.fromJS({ id: action.id, uuid: uuid(), params: action.params })));
  70. case COLUMN_REMOVE:
  71. return state.update('columns', list => list.filterNot(item => item.get('uuid') === action.uuid));
  72. case COLUMN_MOVE:
  73. return moveColumn(state, action.uuid, action.direction);
  74. default:
  75. return state;
  76. }
  77. };