Add getSoapboxConfig() like getSettings()
This commit is contained in:
parent
0668cc786f
commit
ec42888fff
13 changed files with 60 additions and 45 deletions
|
@ -1,8 +1,29 @@
|
||||||
import api from '../api';
|
import api from '../api';
|
||||||
|
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||||
|
|
||||||
export const SOAPBOX_CONFIG_REQUEST_SUCCESS = 'SOAPBOX_CONFIG_REQUEST_SUCCESS';
|
export const SOAPBOX_CONFIG_REQUEST_SUCCESS = 'SOAPBOX_CONFIG_REQUEST_SUCCESS';
|
||||||
export const SOAPBOX_CONFIG_REQUEST_FAIL = 'SOAPBOX_CONFIG_REQUEST_FAIL';
|
export const SOAPBOX_CONFIG_REQUEST_FAIL = 'SOAPBOX_CONFIG_REQUEST_FAIL';
|
||||||
|
|
||||||
|
const defaultConfig = ImmutableMap({
|
||||||
|
logo: '',
|
||||||
|
banner: '',
|
||||||
|
brandColor: '#0482d8', // Azure
|
||||||
|
customCss: ImmutableList(),
|
||||||
|
promoPanel: ImmutableMap({
|
||||||
|
items: ImmutableList(),
|
||||||
|
}),
|
||||||
|
extensions: ImmutableMap(),
|
||||||
|
defaultSettings: ImmutableMap(),
|
||||||
|
copyright: '♥2020. Copying is an act of love. Please copy and share.',
|
||||||
|
navlinks: ImmutableMap({
|
||||||
|
homeFooter: ImmutableList(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export function getSoapboxConfig(state) {
|
||||||
|
return defaultConfig.mergeDeep(state.get('soapbox'));
|
||||||
|
}
|
||||||
|
|
||||||
export function fetchSoapboxConfig() {
|
export function fetchSoapboxConfig() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
api(getState).get('/api/pleroma/frontend_configurations').then(response => {
|
api(getState).get('/api/pleroma/frontend_configurations').then(response => {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import { fetchSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
import { fetchMe } from 'soapbox/actions/me';
|
import { fetchMe } from 'soapbox/actions/me';
|
||||||
import PublicLayout from 'soapbox/features/public_layout';
|
import PublicLayout from 'soapbox/features/public_layout';
|
||||||
import { getSettings } from 'soapbox/actions/settings';
|
import { getSettings } from 'soapbox/actions/settings';
|
||||||
|
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
import { generateThemeCss } from 'soapbox/utils/theme';
|
import { generateThemeCss } from 'soapbox/utils/theme';
|
||||||
import messages from 'soapbox/locales/messages';
|
import messages from 'soapbox/locales/messages';
|
||||||
|
|
||||||
|
@ -42,6 +43,7 @@ const mapStateToProps = (state) => {
|
||||||
const account = state.getIn(['accounts', me]);
|
const account = state.getIn(['accounts', me]);
|
||||||
const showIntroduction = account ? state.getIn(['settings', 'introductionVersion'], 0) < INTRODUCTION_VERSION : false;
|
const showIntroduction = account ? state.getIn(['settings', 'introductionVersion'], 0) < INTRODUCTION_VERSION : false;
|
||||||
const settings = getSettings(state);
|
const settings = getSettings(state);
|
||||||
|
const soapboxConfig = getSoapboxConfig(state);
|
||||||
const locale = settings.get('locale');
|
const locale = settings.get('locale');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -52,9 +54,9 @@ const mapStateToProps = (state) => {
|
||||||
dyslexicFont: settings.get('dyslexicFont'),
|
dyslexicFont: settings.get('dyslexicFont'),
|
||||||
demetricator: settings.get('demetricator'),
|
demetricator: settings.get('demetricator'),
|
||||||
locale: validLocale(locale) ? locale : 'en',
|
locale: validLocale(locale) ? locale : 'en',
|
||||||
themeCss: generateThemeCss(state.getIn(['soapbox', 'brandColor'])),
|
themeCss: generateThemeCss(soapboxConfig.get('brandColor')),
|
||||||
themeMode: settings.get('themeMode'),
|
themeMode: settings.get('themeMode'),
|
||||||
customCss: state.getIn(['soapbox', 'customCss']),
|
customCss: soapboxConfig.get('customCss'),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { fetchAccountIdentityProofs } from '../../actions/identity_proofs';
|
||||||
import MissingIndicator from 'soapbox/components/missing_indicator';
|
import MissingIndicator from 'soapbox/components/missing_indicator';
|
||||||
import { NavLink } from 'react-router-dom';
|
import { NavLink } from 'react-router-dom';
|
||||||
import { fetchPatronAccount } from '../../actions/patron';
|
import { fetchPatronAccount } from '../../actions/patron';
|
||||||
|
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
|
|
||||||
const emptyList = ImmutableList();
|
const emptyList = ImmutableList();
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ const mapStateToProps = (state, { params: { username }, withReplies = false }) =
|
||||||
const me = state.get('me');
|
const me = state.get('me');
|
||||||
const accounts = state.getIn(['accounts']);
|
const accounts = state.getIn(['accounts']);
|
||||||
const accountFetchError = (state.getIn(['accounts', -1, 'username'], '').toLowerCase() === username.toLowerCase());
|
const accountFetchError = (state.getIn(['accounts', -1, 'username'], '').toLowerCase() === username.toLowerCase());
|
||||||
|
const soapboxConfig = getSoapboxConfig(state);
|
||||||
|
|
||||||
let accountId = -1;
|
let accountId = -1;
|
||||||
let accountUsername = username;
|
let accountUsername = username;
|
||||||
|
@ -50,7 +52,7 @@ const mapStateToProps = (state, { params: { username }, withReplies = false }) =
|
||||||
isLoading: state.getIn(['timelines', `account:${path}`, 'isLoading']),
|
isLoading: state.getIn(['timelines', `account:${path}`, 'isLoading']),
|
||||||
hasMore: state.getIn(['timelines', `account:${path}`, 'hasMore']),
|
hasMore: state.getIn(['timelines', `account:${path}`, 'hasMore']),
|
||||||
me,
|
me,
|
||||||
patronEnabled: state.getIn(['soapbox', 'extensions', 'patron', 'enabled']),
|
patronEnabled: soapboxConfig.getIn(['extensions', 'patron', 'enabled']),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,16 @@ import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { List as ImmutableList } from 'immutable';
|
import { List as ImmutableList } from 'immutable';
|
||||||
|
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => ({
|
const mapStateToProps = (state, props) => {
|
||||||
copyright: state.getIn(['soapbox', 'copyright']),
|
const soapboxConfig = getSoapboxConfig(state);
|
||||||
navlinks: state.getIn(['soapbox', 'navlinks', 'homeFooter'], ImmutableList()),
|
|
||||||
});
|
return {
|
||||||
|
copyright: soapboxConfig.get('copyright'),
|
||||||
|
navlinks: soapboxConfig.getIn(['navlinks', 'homeFooter'], ImmutableList()),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export default @connect(mapStateToProps)
|
export default @connect(mapStateToProps)
|
||||||
class Footer extends ImmutablePureComponent {
|
class Footer extends ImmutablePureComponent {
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
|
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => ({
|
const mapStateToProps = (state, props) => ({
|
||||||
instance: state.get('instance'),
|
instance: state.get('instance'),
|
||||||
soapbox: state.get('soapbox'),
|
soapbox: getSoapboxConfig(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
class SiteBanner extends ImmutablePureComponent {
|
class SiteBanner extends ImmutablePureComponent {
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
|
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => ({
|
const mapStateToProps = (state, props) => ({
|
||||||
instance: state.get('instance'),
|
instance: state.get('instance'),
|
||||||
soapbox: state.get('soapbox'),
|
soapbox: getSoapboxConfig(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
class SiteLogo extends ImmutablePureComponent {
|
class SiteLogo extends ImmutablePureComponent {
|
||||||
|
|
|
@ -7,10 +7,11 @@ import Header from './components/header';
|
||||||
import Footer from './components/footer';
|
import Footer from './components/footer';
|
||||||
import LandingPage from '../landing_page';
|
import LandingPage from '../landing_page';
|
||||||
import AboutPage from '../about';
|
import AboutPage from '../about';
|
||||||
|
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => ({
|
const mapStateToProps = (state, props) => ({
|
||||||
instance: state.get('instance'),
|
instance: state.get('instance'),
|
||||||
soapbox: state.get('soapbox'),
|
soapbox: getSoapboxConfig(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const wave = (
|
const wave = (
|
||||||
|
|
|
@ -22,6 +22,7 @@ import {
|
||||||
} from 'immutable';
|
} from 'immutable';
|
||||||
import { updateAdminConfig } from 'soapbox/actions/admin';
|
import { updateAdminConfig } from 'soapbox/actions/admin';
|
||||||
import Icon from 'soapbox/components/icon';
|
import Icon from 'soapbox/components/icon';
|
||||||
|
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
heading: { id: 'column.soapbox_config', defaultMessage: 'Soapbox config' },
|
heading: { id: 'column.soapbox_config', defaultMessage: 'Soapbox config' },
|
||||||
|
@ -34,11 +35,9 @@ const messages = defineMessages({
|
||||||
customCssLabel: { id: 'soapbox_config.custom_css.meta_fields.url_placeholder', defaultMessage: 'URL' },
|
customCssLabel: { id: 'soapbox_config.custom_css.meta_fields.url_placeholder', defaultMessage: 'URL' },
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = state => ({
|
||||||
return {
|
soapbox: getSoapboxConfig(state),
|
||||||
soapbox: state.get('soapbox'),
|
});
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default @connect(mapStateToProps)
|
export default @connect(mapStateToProps)
|
||||||
@injectIntl
|
@injectIntl
|
||||||
|
|
|
@ -2,9 +2,10 @@ import React from 'react';
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import Icon from 'soapbox/components/icon';
|
import Icon from 'soapbox/components/icon';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
promoItems: state.getIn(['soapbox', 'promoPanel', 'items']),
|
promoItems: getSoapboxConfig(state).getIn(['promoPanel', 'items']),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default @connect(mapStateToProps)
|
export default @connect(mapStateToProps)
|
||||||
|
|
|
@ -13,6 +13,7 @@ import { openModal } from '../../../actions/modal';
|
||||||
import { openSidebar } from '../../../actions/sidebar';
|
import { openSidebar } from '../../../actions/sidebar';
|
||||||
import Icon from '../../../components/icon';
|
import Icon from '../../../components/icon';
|
||||||
import ThemeToggle from '../../ui/components/theme_toggle';
|
import ThemeToggle from '../../ui/components/theme_toggle';
|
||||||
|
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
post: { id: 'tabs_bar.post', defaultMessage: 'Post' },
|
post: { id: 'tabs_bar.post', defaultMessage: 'Post' },
|
||||||
|
@ -133,7 +134,7 @@ const mapStateToProps = state => {
|
||||||
const me = state.get('me');
|
const me = state.get('me');
|
||||||
return {
|
return {
|
||||||
account: state.getIn(['accounts', me]),
|
account: state.getIn(['accounts', me]),
|
||||||
logo: state.getIn(['soapbox', 'logo']),
|
logo: getSoapboxConfig(state).get('logo'),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,14 @@ import ComposeFormContainer from '../features/compose/containers/compose_form_co
|
||||||
import Avatar from '../components/avatar';
|
import Avatar from '../components/avatar';
|
||||||
import { getFeatures } from 'soapbox/utils/features';
|
import { getFeatures } from 'soapbox/utils/features';
|
||||||
// import GroupSidebarPanel from '../features/groups/sidebar_panel';
|
// import GroupSidebarPanel from '../features/groups/sidebar_panel';
|
||||||
|
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
|
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = state => {
|
||||||
const me = state.get('me');
|
const me = state.get('me');
|
||||||
return {
|
return {
|
||||||
me,
|
me,
|
||||||
account: state.getIn(['accounts', me]),
|
account: state.getIn(['accounts', me]),
|
||||||
hasPatron: state.getIn(['soapbox', 'extensions', 'patron', 'enabled']),
|
hasPatron: getSoapboxConfig(state).getIn(['extensions', 'patron', 'enabled']),
|
||||||
features: getFeatures(state.get('instance')),
|
features: getFeatures(state.get('instance')),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,9 +6,9 @@ import soapbox from 'soapbox/__fixtures__/soapbox.json';
|
||||||
import soapboxConfig from 'soapbox/__fixtures__/admin_api_frontend_config.json';
|
import soapboxConfig from 'soapbox/__fixtures__/admin_api_frontend_config.json';
|
||||||
|
|
||||||
describe('soapbox reducer', () => {
|
describe('soapbox reducer', () => {
|
||||||
// it('should return the initial state', () => {
|
it('should return the initial state', () => {
|
||||||
// expect(reducer(undefined, {})).toEqual(ImmutableMap());
|
expect(reducer(undefined, {})).toEqual(ImmutableMap());
|
||||||
// });
|
});
|
||||||
|
|
||||||
it('should handle SOAPBOX_CONFIG_REQUEST_SUCCESS', () => {
|
it('should handle SOAPBOX_CONFIG_REQUEST_SUCCESS', () => {
|
||||||
const state = ImmutableMap({ brandColor: '#354e91' });
|
const state = ImmutableMap({ brandColor: '#354e91' });
|
||||||
|
|
|
@ -1,26 +1,8 @@
|
||||||
import { ADMIN_CONFIG_UPDATE_SUCCESS } from '../actions/admin';
|
import { ADMIN_CONFIG_UPDATE_SUCCESS } from '../actions/admin';
|
||||||
import {
|
import { SOAPBOX_CONFIG_REQUEST_SUCCESS } from '../actions/soapbox';
|
||||||
SOAPBOX_CONFIG_REQUEST_SUCCESS,
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||||
SOAPBOX_CONFIG_REQUEST_FAIL,
|
|
||||||
} from '../actions/soapbox';
|
|
||||||
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
|
||||||
|
|
||||||
// TODO: Handle this more like getSettings()
|
const initialState = ImmutableMap();
|
||||||
const initialState = ImmutableMap({
|
|
||||||
logo: '',
|
|
||||||
banner: '',
|
|
||||||
brandColor: '#0482d8', // Azure
|
|
||||||
customCss: ImmutableList([]),
|
|
||||||
promoPanel: ImmutableMap({
|
|
||||||
items: ImmutableList([]),
|
|
||||||
}),
|
|
||||||
extensions: ImmutableMap(),
|
|
||||||
defaultSettings: ImmutableMap(),
|
|
||||||
copyright: '♥2020. Copying is an act of love. Please copy and share.',
|
|
||||||
navlinks: ImmutableMap({
|
|
||||||
homeFooter: ImmutableList(),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const updateFromAdmin = (state, config) => {
|
const updateFromAdmin = (state, config) => {
|
||||||
// TODO: Generalize this with an API similar to `Pleroma.Config` in Pleroma BE
|
// TODO: Generalize this with an API similar to `Pleroma.Config` in Pleroma BE
|
||||||
|
@ -32,9 +14,7 @@ const updateFromAdmin = (state, config) => {
|
||||||
export default function soapbox(state = initialState, action) {
|
export default function soapbox(state = initialState, action) {
|
||||||
switch(action.type) {
|
switch(action.type) {
|
||||||
case SOAPBOX_CONFIG_REQUEST_SUCCESS:
|
case SOAPBOX_CONFIG_REQUEST_SUCCESS:
|
||||||
return initialState.mergeDeep(ImmutableMap(fromJS(action.soapboxConfig)));
|
return fromJS(action.soapboxConfig);
|
||||||
case SOAPBOX_CONFIG_REQUEST_FAIL:
|
|
||||||
return initialState;
|
|
||||||
case ADMIN_CONFIG_UPDATE_SUCCESS:
|
case ADMIN_CONFIG_UPDATE_SUCCESS:
|
||||||
return updateFromAdmin(state, fromJS(action.config));
|
return updateFromAdmin(state, fromJS(action.config));
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue