From 178fdf8818fd46754ac5509b2544116d16f8a026 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 28 Apr 2020 12:59:15 -0500 Subject: [PATCH] Add getSettings() function --- app/gabsocial/actions/settings.js | 100 +++++++++++++++++++++++++++ app/gabsocial/reducers/settings.js | 91 ++---------------------- static/instance/soapbox.example.json | 5 +- 3 files changed, 108 insertions(+), 88 deletions(-) diff --git a/app/gabsocial/actions/settings.js b/app/gabsocial/actions/settings.js index 3616a7af6..768625b5e 100644 --- a/app/gabsocial/actions/settings.js +++ b/app/gabsocial/actions/settings.js @@ -1,12 +1,112 @@ import { debounce } from 'lodash'; import { showAlertForError } from './alerts'; import { patchMe } from 'gabsocial/actions/me'; +import { Map as ImmutableMap } from 'immutable'; export const SETTING_CHANGE = 'SETTING_CHANGE'; export const SETTING_SAVE = 'SETTING_SAVE'; export const FE_NAME = 'soapbox_fe'; +const defaultSettings = ImmutableMap({ + onboarded: false, + + skinTone: 1, + reduceMotion: false, + autoPlayGif: false, + displayMedia: true, + expandSpoilers: false, + unfollowModal: false, + boostModal: false, + deleteModal: true, + defaultPrivacy: 'public', + theme: 'lime', + + systemFont: false, + dyslexicFont: false, + demetricator: false, + + home: ImmutableMap({ + shows: ImmutableMap({ + reblog: true, + reply: true, + }), + + regex: ImmutableMap({ + body: '', + }), + }), + + notifications: ImmutableMap({ + alerts: ImmutableMap({ + follow: true, + favourite: true, + reblog: true, + mention: true, + poll: true, + }), + + quickFilter: ImmutableMap({ + active: 'all', + show: true, + advanced: false, + }), + + shows: ImmutableMap({ + follow: true, + favourite: true, + reblog: true, + mention: true, + poll: true, + }), + + sounds: ImmutableMap({ + follow: true, + favourite: true, + reblog: true, + mention: true, + poll: true, + }), + }), + + community: ImmutableMap({ + other: ImmutableMap({ + onlyMedia: false, + }), + regex: ImmutableMap({ + body: '', + }), + }), + + public: ImmutableMap({ + other: ImmutableMap({ + onlyMedia: false, + }), + regex: ImmutableMap({ + body: '', + }), + }), + + direct: ImmutableMap({ + regex: ImmutableMap({ + body: '', + }), + }), + + trends: ImmutableMap({ + show: true, + }), +}); + + +export function getSettings(getState) { + const state = getState(); + const soapboxSettings = state.getIn(['soapbox', 'defaultSettings']); + return defaultSettings + .mergeDeep(soapboxSettings) + .mergeDeep(state.get('settings')); +} + export function changeSetting(path, value) { return dispatch => { dispatch({ diff --git a/app/gabsocial/reducers/settings.js b/app/gabsocial/reducers/settings.js index da5b7ef41..1eec3151d 100644 --- a/app/gabsocial/reducers/settings.js +++ b/app/gabsocial/reducers/settings.js @@ -7,95 +7,12 @@ import { ME_FETCH_SUCCESS } from 'gabsocial/actions/me'; import { Map as ImmutableMap, fromJS } from 'immutable'; import uuid from '../uuid'; +// Default settings are in action/settings.js +// +// Settings should be accessed with `getSettings(getState).getIn(...)` +// instead of directly from the state. const initialState = ImmutableMap({ saved: true, - onboarded: false, - - skinTone: 1, - reduceMotion: false, - autoPlayGif: false, - displayMedia: true, - expandSpoilers: false, - unfollowModal: false, - boostModal: false, - deleteModal: true, - defaultPrivacy: 'public', - theme: 'lime', - - systemFont: false, - dyslexicFont: false, - demetricator: false, - - home: ImmutableMap({ - shows: ImmutableMap({ - reblog: true, - reply: true, - }), - - regex: ImmutableMap({ - body: '', - }), - }), - - notifications: ImmutableMap({ - alerts: ImmutableMap({ - follow: true, - favourite: true, - reblog: true, - mention: true, - poll: true, - }), - - quickFilter: ImmutableMap({ - active: 'all', - show: true, - advanced: false, - }), - - shows: ImmutableMap({ - follow: true, - favourite: true, - reblog: true, - mention: true, - poll: true, - }), - - sounds: ImmutableMap({ - follow: true, - favourite: true, - reblog: true, - mention: true, - poll: true, - }), - }), - - community: ImmutableMap({ - other: ImmutableMap({ - onlyMedia: false, - }), - regex: ImmutableMap({ - body: '', - }), - }), - - public: ImmutableMap({ - other: ImmutableMap({ - onlyMedia: false, - }), - regex: ImmutableMap({ - body: '', - }), - }), - - direct: ImmutableMap({ - regex: ImmutableMap({ - body: '', - }), - }), - - trends: ImmutableMap({ - show: true, - }), }); const defaultColumns = fromJS([ diff --git a/static/instance/soapbox.example.json b/static/instance/soapbox.example.json index 561d8cff0..95122252d 100644 --- a/static/instance/soapbox.example.json +++ b/static/instance/soapbox.example.json @@ -13,5 +13,8 @@ }, "extensions": { "patron": false - } + }, + "defaultSettings": { + "autoPlayGif": false, + }, }