2017-07-13 12:26:08 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
`reducers/local_settings`
|
|
|
|
========================
|
|
|
|
|
|
|
|
> For more information on the contents of this file, please contact:
|
|
|
|
>
|
|
|
|
> - kibigo! [@kibi@glitch.social]
|
|
|
|
|
|
|
|
This file provides our Redux reducers related to local settings. The
|
|
|
|
associated actions are:
|
|
|
|
|
|
|
|
- __`STORE_HYDRATE` :__
|
|
|
|
Used to hydrate the store with its initial values.
|
|
|
|
|
|
|
|
- __`LOCAL_SETTING_CHANGE` :__
|
|
|
|
Used to change the value of a local setting in the store.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-07-14 20:13:02 +02:00
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2017-07-13 12:26:08 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2017-07-14 20:13:02 +02:00
|
|
|
Imports:
|
|
|
|
--------
|
2017-07-13 12:26:08 +02:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-07-12 10:02:51 +02:00
|
|
|
// Package imports //
|
2017-07-16 00:10:06 +02:00
|
|
|
import { Map as ImmutableMap } from 'immutable';
|
2017-06-25 04:12:34 +02:00
|
|
|
|
2017-07-12 10:02:51 +02:00
|
|
|
// Mastodon imports //
|
|
|
|
import { STORE_HYDRATE } from '../../mastodon/actions/store';
|
|
|
|
|
|
|
|
// Our imports //
|
|
|
|
import { LOCAL_SETTING_CHANGE } from '../actions/local_settings';
|
|
|
|
|
2017-07-14 20:13:02 +02:00
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2017-07-13 12:26:08 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2017-07-14 20:13:02 +02:00
|
|
|
initialState:
|
|
|
|
-------------
|
2017-07-13 12:26:08 +02:00
|
|
|
|
|
|
|
You can see the default values for all of our local settings here.
|
|
|
|
These are only used if no previously-saved values exist.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-07-16 00:10:06 +02:00
|
|
|
const initialState = ImmutableMap({
|
2017-06-29 07:00:54 +02:00
|
|
|
layout : 'auto',
|
|
|
|
stretch : true,
|
2017-07-22 19:51:34 +02:00
|
|
|
navbar_under : false,
|
2017-09-23 23:11:02 +02:00
|
|
|
side_arm : 'none',
|
2017-07-16 00:10:06 +02:00
|
|
|
collapsed : ImmutableMap({
|
2017-06-29 07:00:54 +02:00
|
|
|
enabled : true,
|
2017-07-16 00:10:06 +02:00
|
|
|
auto : ImmutableMap({
|
2017-06-29 07:00:54 +02:00
|
|
|
all : false,
|
|
|
|
notifications : true,
|
|
|
|
lengthy : true,
|
2017-11-06 00:05:12 +01:00
|
|
|
reblogs : false,
|
2017-06-29 07:00:54 +02:00
|
|
|
replies : false,
|
|
|
|
media : false,
|
2017-07-16 00:10:06 +02:00
|
|
|
}),
|
|
|
|
backgrounds : ImmutableMap({
|
2017-06-29 07:00:54 +02:00
|
|
|
user_backgrounds : false,
|
|
|
|
preview_images : false,
|
2017-07-16 00:10:06 +02:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
media : ImmutableMap({
|
2017-06-30 11:15:18 +02:00
|
|
|
letterbox : true,
|
2017-07-08 11:01:56 +02:00
|
|
|
fullwidth : true,
|
2017-07-16 00:10:06 +02:00
|
|
|
}),
|
2017-06-25 04:12:34 +02:00
|
|
|
});
|
|
|
|
|
2017-07-14 20:13:02 +02:00
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2017-07-13 12:26:08 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2017-07-14 20:13:02 +02:00
|
|
|
Helper functions:
|
|
|
|
-----------------
|
2017-07-13 12:26:08 +02:00
|
|
|
|
|
|
|
### `hydrate(state, localSettings)`
|
|
|
|
|
|
|
|
`hydrate()` is used to hydrate the `local_settings` part of our store
|
|
|
|
with its initial values. The `state` will probably just be the
|
|
|
|
`initialState`, and the `localSettings` should be whatever we pulled
|
|
|
|
from `localStorage`.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-06-25 04:12:34 +02:00
|
|
|
const hydrate = (state, localSettings) => state.mergeDeep(localSettings);
|
|
|
|
|
2017-07-14 20:13:02 +02:00
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2017-07-13 12:26:08 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2017-07-14 20:13:02 +02:00
|
|
|
`localSettings(state = initialState, action)`:
|
|
|
|
----------------------------------------------
|
2017-07-13 12:26:08 +02:00
|
|
|
|
|
|
|
This function holds our actual reducer.
|
|
|
|
|
|
|
|
If our action is `STORE_HYDRATE`, then we call `hydrate()` with the
|
|
|
|
`local_settings` property of the provided `action.state`.
|
|
|
|
|
|
|
|
If our action is `LOCAL_SETTING_CHANGE`, then we set `action.key` in
|
|
|
|
our state to the provided `action.value`. Note that `action.key` MUST
|
|
|
|
be an array, since we use `setIn()`.
|
|
|
|
|
|
|
|
> __Note :__
|
|
|
|
> We call this function `localSettings`, but its associated object
|
|
|
|
> in the store is `local_settings`.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-06-25 04:12:34 +02:00
|
|
|
export default function localSettings(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
|
|
|
case STORE_HYDRATE:
|
2017-06-29 07:00:54 +02:00
|
|
|
return hydrate(state, action.state.get('local_settings'));
|
2017-06-25 04:12:34 +02:00
|
|
|
case LOCAL_SETTING_CHANGE:
|
|
|
|
return state.setIn(action.key, action.value);
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|