From c8eb29a7d912658f1614a24a577bce1514edb15b Mon Sep 17 00:00:00 2001 From: Curtis ROck Date: Thu, 23 Jul 2020 09:14:28 -0500 Subject: [PATCH] edited features/configuration --- app/soapbox/features/configuration/index.js | 81 +++++++++++++++++---- 1 file changed, 67 insertions(+), 14 deletions(-) diff --git a/app/soapbox/features/configuration/index.js b/app/soapbox/features/configuration/index.js index ead5873c7..a9c4b0c8b 100644 --- a/app/soapbox/features/configuration/index.js +++ b/app/soapbox/features/configuration/index.js @@ -38,19 +38,19 @@ const mapStateToProps = state => { console.log(soapbox); console.log(generateThemeCss(soapbox.get('brandColor'))); console.log(soapbox.get('logo')); - console.log(soapbox.get('promoPanel')); - console.log(soapbox.get('extensions')); - console.log(soapbox.get('defaultSettings')); + console.log(soapbox.getIn(['promoPanel', 'items'])); + console.log(soapbox.getIn(['extensions', 'patron'])); + console.log(soapbox.getIn(['defaultSettings', 'autoPlayGif'])); console.log(soapbox.get('copyright')); - console.log(soapbox.get('navLinks')); + console.log(soapbox.getIn(['navlinks', 'homeFooter'])); return { themeCss: generateThemeCss(soapbox.get('brandColor')), logo: soapbox.get('logo'), - promoPanel: soapbox.get('promoPanel'), - patronEnabled: soapbox.get('extensions'), - autoPlayGif: soapbox.get('defaultSettings'), + promoPanel: soapbox.getIn(['promoPanel', 'items']), + patronEnabled: soapbox.getIn(['extensions', 'patron']), + autoPlayGif: soapbox.getIn(['defaultSettings', 'autoPlayGif']), copyright: soapbox.get('copyright'), - homeFooter: soapbox.get('navLinks'), + homeFooter: soapbox.getIn(['navlinks', 'homeFooter']), }; }; @@ -64,11 +64,11 @@ class ConfigSoapbox extends ImmutablePureComponent { intl: PropTypes.object.isRequired, themeCss: PropTypes.string, logo: PropTypes.string, - promoPanel: ImmutablePropTypes.map, - patronEnabled: PropTypes.object, - autoPlayGif: PropTypes.object, + promoPanel: ImmutablePropTypes.list, + patronEnabled: PropTypes.bool, + autoPlayGif: PropTypes.bool, copyright: PropTypes.string, - homeFooter: ImmutablePropTypes.map, + homeFooter: ImmutablePropTypes.list, }; state = { @@ -76,6 +76,17 @@ class ConfigSoapbox extends ImmutablePureComponent { // promoPanel: normalizeFields(Array.from({ length: MAX_FIELDS })), } + constructor(props) { + super(props); + const initialState = props.withMutations(map => { + map.merge(map.get('source')); + map.delete('source'); + map.set('fields', normalizeFields(map.get('fields'))); + unescapeParams(map, ['display_name', 'note']); + }); + this.state = initialState.toObject(); + } + // makePreviewLogo = () => { // const { logo } = this.props; // return logo.merge(ImmutableMap({ @@ -95,6 +106,16 @@ class ConfigSoapbox extends ImmutablePureComponent { return params; } + getHomeFooterParams = () => { + let params = ImmutableMap(); + this.state.homeFooter.forEach((f, i) => + params = params + .set(`home_footer_attributes[${i}][name]`, f.get('name')) + .set(`home_footer_attributes[${i}][value]`, f.get('value')) + ); + return params; + } + getParams = () => { const { state } = this; return Object.assign({ @@ -104,14 +125,16 @@ class ConfigSoapbox extends ImmutablePureComponent { displayMode: state.displayMode, copyright: state.copyright, homeFooter: state.homeFooter, - }, this.getPromoPanelParams().toJS()); + }, + this.getHomeFooterParams().toJS(), + this.getPromoPanelParams().toJS()); } getFormdata = () => { const data = this.getParams(); let formData = new FormData(); for (let key in data) { - const shouldAppend = Boolean(data[key] || key.startsWith('promo_panel_attributes')); + const shouldAppend = Boolean(data[key] || key.startsWith('promo_panel_attributes') || key.startsWith('home_footer_attributes')); if (shouldAppend) formData.append(key, data[key] || ''); } return formData; @@ -144,6 +167,14 @@ class ConfigSoapbox extends ImmutablePureComponent { }; } + handleHomeFooterChange = (i, key) => { + return (e) => { + this.setState({ + homeFooter: this.state.homeFooter.setIn([i, key], e.target.value), + }); + }; + } + handleFileChange = e => { const { name } = e.target; const [file] = e.target.files || []; @@ -233,6 +264,28 @@ class ConfigSoapbox extends ImmutablePureComponent { )) } +
+ + + + + { + this.state.homeFooter.map((field, i) => ( +
+ + +
+ )) + } +