Move Soapbox config to fetchable endpoint

This commit is contained in:
Alex Gleason 2020-04-01 14:38:08 -05:00
parent 2a245d076a
commit c9c08dff5c
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
8 changed files with 56 additions and 9 deletions

View file

@ -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,
};
};

View file

@ -17,6 +17,7 @@ import { getLocale } from '../locales';
import initialState from '../initial_state'; import initialState from '../initial_state';
import { me } from '../initial_state'; import { me } from '../initial_state';
import ErrorBoundary from '../components/error_boundary'; import ErrorBoundary from '../components/error_boundary';
import { fetchSoapboxConfig } from 'gabsocial/actions/soapbox';
const { localeData, messages } = getLocale(); const { localeData, messages } = getLocale();
addLocaleData(localeData); addLocaleData(localeData);
@ -26,6 +27,7 @@ const hydrateAction = hydrateStore(initialState);
store.dispatch(hydrateAction); store.dispatch(hydrateAction);
store.dispatch(fetchCustomEmojis()); store.dispatch(fetchCustomEmojis());
store.dispatch(fetchSoapboxConfig());
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
const account = state.getIn(['accounts', me]); const account = state.getIn(['accounts', me]);

View file

@ -1,7 +1,6 @@
import React from 'react'; import React from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { me, funding } from 'gabsocial/initial_state'; import { me } from 'gabsocial/initial_state';
import soapbox from 'soapbox/config';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import ImmutablePureComponent from 'react-immutable-pure-component'; import ImmutablePureComponent from 'react-immutable-pure-component';
import WhoToFollowPanel from '../features/ui/components/who_to_follow_panel'; import WhoToFollowPanel from '../features/ui/components/who_to_follow_panel';
@ -16,12 +15,13 @@ import GroupSidebarPanel from '../features/groups/sidebar_panel';
const mapStateToProps = state => ({ const mapStateToProps = state => ({
account: state.getIn(['accounts', me]), account: state.getIn(['accounts', me]),
hasPatron: state.getIn(['soapbox', 'features', 'patron']),
}); });
export default @connect(mapStateToProps) export default @connect(mapStateToProps)
class HomePage extends ImmutablePureComponent { class HomePage extends ImmutablePureComponent {
render () { render () {
const {children, account} = this.props; const {children, account, hasPatron} = this.props;
return ( return (
<div className='page'> <div className='page'>
@ -31,7 +31,7 @@ class HomePage extends ImmutablePureComponent {
<div className='columns-area__panels__pane columns-area__panels__pane--left'> <div className='columns-area__panels__pane columns-area__panels__pane--left'>
<div className='columns-area__panels__pane__inner'> <div className='columns-area__panels__pane__inner'>
<UserPanel /> <UserPanel />
{soapbox.features.patron && <FundingPanel />} {hasPatron && <FundingPanel />}
<PromoPanel /> <PromoPanel />
<LinkFooter /> <LinkFooter />
</div> </div>

View file

@ -38,6 +38,7 @@ import group_lists from './group_lists';
import group_editor from './group_editor'; import group_editor from './group_editor';
import sidebar from './sidebar'; import sidebar from './sidebar';
import patron from './patron'; import patron from './patron';
import soapbox from './soapbox';
const reducers = { const reducers = {
dropdown_menu, dropdown_menu,
@ -79,6 +80,7 @@ const reducers = {
group_editor, group_editor,
sidebar, sidebar,
patron, patron,
soapbox,
}; };
export default combineReducers(reducers); export default combineReducers(reducers);

View file

@ -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;
}
};

View file

@ -1,5 +0,0 @@
export default {
features: {
patron: true,
},
}

View file

@ -0,0 +1,5 @@
{
"features": {
"patron": false
}
}

View file

@ -69,6 +69,7 @@ module.exports = merge(sharedConfig, {
'/socket': backendUrl, '/socket': backendUrl,
'/oauth/revoke': backendUrl, '/oauth/revoke': backendUrl,
'/.well-known/webfinger': backendUrl, '/.well-known/webfinger': backendUrl,
'/static': backendUrl,
'/patron': patronUrl, '/patron': patronUrl,
}, },
}, },