diff --git a/app/soapbox/features/forms/index.js b/app/soapbox/features/forms/index.js index e6e296818..090914ef8 100644 --- a/app/soapbox/features/forms/index.js +++ b/app/soapbox/features/forms/index.js @@ -362,3 +362,11 @@ export const FileChooserLogo = props => ( FileChooserLogo.defaultProps = { accept: ['image/svg', 'image/png'], }; + +export const FileChooserCSV = props => ( + +); + +FileChooserCSV.defaultProps = { + accept: ['.csv'], +}; diff --git a/app/soapbox/features/import_follows/index.js b/app/soapbox/features/import_follows/index.js index 1ca095ed5..c16d60c7b 100644 --- a/app/soapbox/features/import_follows/index.js +++ b/app/soapbox/features/import_follows/index.js @@ -1,50 +1,27 @@ import React from 'react'; -import { connect } from 'react-redux'; +// import { connect } from 'react-redux'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import PropTypes from 'prop-types'; -// import ImmutablePropTypes from 'react-immutable-proptypes'; import Column from '../ui/components/column'; import { SimpleForm, FieldsGroup, - // TextInput, - // Checkbox, - FileChooser, - // SimpleTextarea, - // ColorWithPicker, - // FileChooserLogo, + FileChooserCSV, } from 'soapbox/features/forms'; -// import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'; import { importFollows } from 'soapbox/actions/import_follows'; -// import Icon from 'soapbox/components/icon'; -// import { defaultConfig } from 'soapbox/actions/soapbox'; import { uploadMedia } from 'soapbox/actions/media'; const messages = defineMessages({ heading: { id: 'column.import_follows', defaultMessage: 'Import follows' }, - // copyrightFooterLabel: { id: 'soapbox_config.copyright_footer.meta_fields.label_placeholder', defaultMessage: 'Copyright footer' }, - // promoItemIcon: { id: 'soapbox_config.promo_panel.meta_fields.icon_placeholder', defaultMessage: 'Icon' }, - // promoItemLabel: { id: 'soapbox_config.promo_panel.meta_fields.label_placeholder', defaultMessage: 'Label' }, - // promoItemURL: { id: 'soapbox_config.promo_panel.meta_fields.url_placeholder', defaultMessage: 'URL' }, - // homeFooterItemLabel: { id: 'soapbox_config.home_footer.meta_fields.label_placeholder', defaultMessage: 'Label' }, - // homeFooterItemURL: { id: 'soapbox_config.home_footer.meta_fields.url_placeholder', defaultMessage: 'URL' }, - // customCssLabel: { id: 'soapbox_config.custom_css.meta_fields.url_placeholder', defaultMessage: 'URL' }, - // rawJSONLabel: { id: 'soapbox_config.raw_json_label', defaultMessage: 'Raw JSON data' }, - // rawJSONHint: { id: 'soapbox_config.raw_json_hint', defaultMessage: 'Advanced: Edit the settings data directly.' }, }); -// const templates = { -// promoPanelItem: ImmutableMap({ icon: '', text: '', url: '' }), -// footerItem: ImmutableMap({ title: '', url: '' }), -// }; +// const mapStateToProps = state => ({ +// follows: state.get('follows'), +// }); -const mapStateToProps = state => ({ - follows: state.get('follows'), -}); - -export default @connect(mapStateToProps) -@injectIntl +// export default @connect(mapStateToProps) +export default @injectIntl class ImportFollows extends ImmutablePureComponent { static propTypes = { @@ -56,31 +33,19 @@ class ImportFollows extends ImmutablePureComponent { state = { isLoading: false, follows: this.props.follows, - // rawJSON: JSON.stringify(this.props.soapbox, null, 2), - // jsonValid: true, } setConfig = (value) => { - // const { follows } = this.state; - // const config = soapbox.setIn(path, value); this.setState({ follows: value }); }; - putConfig = config => { - this.setState({ soapbox: config, jsonValid: true }); - }; + // putConfig = config => { + // this.setState({ soapbox: config, jsonValid: true }); + // }; getParams = () => { - const { soapbox } = this.state; - return { - configs: [{ - group: ':pleroma', - key: ':frontend_configurations', - value: [{ - tuple: [':soapbox_fe', soapbox.toJS()], - }], - }], - }; + const { follows } = this.state; + return { follows: follows.toJS() }; } handleSubmit = (event) => { @@ -94,89 +59,35 @@ class ImportFollows extends ImmutablePureComponent { event.preventDefault(); } - handleChange = (path, getValue) => { + handleChange = (getValue) => { return e => { - this.setConfig(path, getValue(e)); + this.setConfig(getValue(e)); }; }; + // handleUpload = (event) => { + // const { dispatch } = this.props; + // dispatch(importFollows(event.target.files[0])).then(() => { + // this.setState({ isLoading: false }); + // }).catch((error) => { + // this.setState({ isLoading: false }); + // }); + // this.setState({ isLoading: true }); + // event.preventDefault(); + // } + handleFileChange = path => { return e => { const data = new FormData(); data.append('file', e.target.files[0]); this.props.dispatch(uploadMedia(data)).then(({ data }) => { - this.handleChange(path, e => data.url)(e); + this.handleChange(e => data.url)(e); }).catch(() => {}); }; }; - handleAddItem = (path, template) => { - return e => { - this.setConfig( - path, - this.getSoapboxConfig().getIn(path, ImmutableList()).push(template), - ); - }; - }; - - handleDeleteItem = path => { - return e => { - const soapbox = this.state.soapbox.deleteIn(path); - this.setState({ soapbox }); - }; - }; - - handleItemChange = (path, key, field, template) => { - return this.handleChange( - path, (e) => - template - .merge(field) - .set(key, e.target.value) - ); - }; - - handlePromoItemChange = (index, key, field) => { - return this.handleItemChange( - ['promoPanel', 'items', index], key, field, templates.promoPanelItem - ); - }; - - handleHomeFooterItemChange = (index, key, field) => { - return this.handleItemChange( - ['navlinks', 'homeFooter', index], key, field, templates.footerItem - ); - }; - - handleEditJSON = e => { - this.setState({ rawJSON: e.target.value }); - } - - getSoapboxConfig = () => { - return defaultConfig.mergeDeep(this.state.soapbox); - } - - componentDidUpdate(prevProps, prevState) { - if (prevProps.soapbox !== this.props.soapbox) { - this.putConfig(this.props.soapbox); - } - - if (prevState.soapbox !== this.state.soapbox) { - this.setState({ rawJSON: JSON.stringify(this.state.soapbox, null, 2) }); - } - - if (prevState.rawJSON !== this.state.rawJSON) { - try { - const data = fromJS(JSON.parse(this.state.rawJSON)); - this.putConfig(data); - } catch { - this.setState({ jsonValid: false }); - } - } - } - render() { const { intl } = this.props; - const soapbox = this.getSoapboxConfig(); return ( @@ -184,160 +95,16 @@ class ImportFollows extends ImmutablePureComponent { - - - - } - name='banner' - hint={} - onChange={this.handleFileChange(['banner'])} + } + name='follows' + hint={} + onChange={this.handleFileChange('follows')} /> - - - } - value={soapbox.get('brandColor')} - onChange={this.handleChange(['brandColor'], (e) => e.hex)} - /> - - - - } - hint={} - name='patron' - checked={soapbox.getIn(['extensions', 'patron', 'enabled'])} - onChange={this.handleChange( - ['extensions', 'patron', 'enabled'], (e) => e.checked, - )} - /> - - - e.target.value)} - /> - - - - - - - - - - Soapbox Icons List }} /> - - { - soapbox.getIn(['promoPanel', 'items']).map((field, i) => ( - - - - - - - )) - } - - - - - - - - - - - - - { - soapbox.getIn(['navlinks', 'homeFooter']).map((field, i) => ( - - - - - - )) - } - - - - - - - - - - - - - - { - soapbox.get('customCss').map((field, i) => ( - - e.target.value)} - /> - - - )) - } - - - - - - - - - - - - -