From c9c08dff5ce94173af6b18c1a3dfed0c09956b4c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 1 Apr 2020 14:38:08 -0500 Subject: [PATCH] Move Soapbox config to fetchable endpoint --- app/gabsocial/actions/soapbox.js | 29 +++++++++++++++++++++++++++ app/gabsocial/containers/gabsocial.js | 2 ++ app/gabsocial/pages/home_page.js | 8 ++++---- app/gabsocial/reducers/index.js | 2 ++ app/gabsocial/reducers/soapbox.js | 13 ++++++++++++ app/soapbox/config.js | 5 ----- public/soapbox/soapbox.json | 5 +++++ webpack/development.js | 1 + 8 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 app/gabsocial/actions/soapbox.js create mode 100644 app/gabsocial/reducers/soapbox.js delete mode 100644 app/soapbox/config.js create mode 100644 public/soapbox/soapbox.json diff --git a/app/gabsocial/actions/soapbox.js b/app/gabsocial/actions/soapbox.js new file mode 100644 index 000000000..711790c5a --- /dev/null +++ b/app/gabsocial/actions/soapbox.js @@ -0,0 +1,29 @@ +import api from '../api'; + +export const SOAPBOX_CONFIG_IMPORT = 'SOAPBOX_CONFIG_IMPORT'; +export const SOAPBOX_CONFIG_FAIL = 'SOAPBOX_CONFIG_FAIL'; + +export function fetchSoapboxConfig() { + return (dispatch, getState) => { + api(getState).get(`/soapbox/soapbox.json`).then(response => { + dispatch(importSoapboxConfig(response.data)); + }).catch(error => { + dispatch(soapboxConfigFail(error)); + }); + }; +} + +export function importSoapboxConfig(soapboxConfig) { + return { + type: SOAPBOX_CONFIG_IMPORT, + soapboxConfig + }; +} + +export function soapboxConfigFail(error) { + return { + type: SOAPBOX_CONFIG_FAIL, + error, + skipAlert: true, + }; +}; diff --git a/app/gabsocial/containers/gabsocial.js b/app/gabsocial/containers/gabsocial.js index 03d302380..a54b09b90 100644 --- a/app/gabsocial/containers/gabsocial.js +++ b/app/gabsocial/containers/gabsocial.js @@ -17,6 +17,7 @@ import { getLocale } from '../locales'; import initialState from '../initial_state'; import { me } from '../initial_state'; import ErrorBoundary from '../components/error_boundary'; +import { fetchSoapboxConfig } from 'gabsocial/actions/soapbox'; const { localeData, messages } = getLocale(); addLocaleData(localeData); @@ -26,6 +27,7 @@ const hydrateAction = hydrateStore(initialState); store.dispatch(hydrateAction); store.dispatch(fetchCustomEmojis()); +store.dispatch(fetchSoapboxConfig()); const mapStateToProps = (state) => { const account = state.getIn(['accounts', me]); diff --git a/app/gabsocial/pages/home_page.js b/app/gabsocial/pages/home_page.js index a4056e9c9..c8e6ba650 100644 --- a/app/gabsocial/pages/home_page.js +++ b/app/gabsocial/pages/home_page.js @@ -1,7 +1,6 @@ import React from 'react'; import { connect } from 'react-redux'; -import { me, funding } from 'gabsocial/initial_state'; -import soapbox from 'soapbox/config'; +import { me } from 'gabsocial/initial_state'; import PropTypes from 'prop-types'; import ImmutablePureComponent from 'react-immutable-pure-component'; import WhoToFollowPanel from '../features/ui/components/who_to_follow_panel'; @@ -16,12 +15,13 @@ import GroupSidebarPanel from '../features/groups/sidebar_panel'; const mapStateToProps = state => ({ account: state.getIn(['accounts', me]), + hasPatron: state.getIn(['soapbox', 'features', 'patron']), }); export default @connect(mapStateToProps) class HomePage extends ImmutablePureComponent { render () { - const {children, account} = this.props; + const {children, account, hasPatron} = this.props; return (
@@ -31,7 +31,7 @@ class HomePage extends ImmutablePureComponent {
- {soapbox.features.patron && } + {hasPatron && }
diff --git a/app/gabsocial/reducers/index.js b/app/gabsocial/reducers/index.js index 2225cabc4..d42916c9e 100644 --- a/app/gabsocial/reducers/index.js +++ b/app/gabsocial/reducers/index.js @@ -38,6 +38,7 @@ import group_lists from './group_lists'; import group_editor from './group_editor'; import sidebar from './sidebar'; import patron from './patron'; +import soapbox from './soapbox'; const reducers = { dropdown_menu, @@ -79,6 +80,7 @@ const reducers = { group_editor, sidebar, patron, + soapbox, }; export default combineReducers(reducers); diff --git a/app/gabsocial/reducers/soapbox.js b/app/gabsocial/reducers/soapbox.js new file mode 100644 index 000000000..bb3c58561 --- /dev/null +++ b/app/gabsocial/reducers/soapbox.js @@ -0,0 +1,13 @@ +import { SOAPBOX_CONFIG_IMPORT } from '../actions/soapbox'; +import { Map as ImmutableMap, fromJS } from 'immutable'; + +const initialState = ImmutableMap(); + +export default function soapbox(state = initialState, action) { + switch(action.type) { + case SOAPBOX_CONFIG_IMPORT: + return ImmutableMap(fromJS(action.soapboxConfig)); + default: + return state; + } +}; diff --git a/app/soapbox/config.js b/app/soapbox/config.js deleted file mode 100644 index fa0fc5f51..000000000 --- a/app/soapbox/config.js +++ /dev/null @@ -1,5 +0,0 @@ -export default { - features: { - patron: true, - }, -} diff --git a/public/soapbox/soapbox.json b/public/soapbox/soapbox.json new file mode 100644 index 000000000..424c9c60d --- /dev/null +++ b/public/soapbox/soapbox.json @@ -0,0 +1,5 @@ +{ + "features": { + "patron": false + } +} diff --git a/webpack/development.js b/webpack/development.js index 2a3da8c52..4ba66b1fa 100644 --- a/webpack/development.js +++ b/webpack/development.js @@ -69,6 +69,7 @@ module.exports = merge(sharedConfig, { '/socket': backendUrl, '/oauth/revoke': backendUrl, '/.well-known/webfinger': backendUrl, + '/static': backendUrl, '/patron': patronUrl, }, },