From 7b6276fa59cbb369ff5bacba98e00db8de9622a4 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 1 Oct 2020 15:54:29 -0500 Subject: [PATCH] Accordion: replace ExplanationBox with Accordion --- app/soapbox/features/public_timeline/index.js | 44 +++++++++--- app/soapbox/features/soapbox_config/index.js | 7 +- .../features/ui/components/accordion.js | 14 ++-- .../features/ui/components/explanation_box.js | 67 ------------------- app/styles/components/accordion.scss | 9 ++- 5 files changed, 53 insertions(+), 88 deletions(-) delete mode 100644 app/soapbox/features/ui/components/explanation_box.js diff --git a/app/soapbox/features/public_timeline/index.js b/app/soapbox/features/public_timeline/index.js index 1cf8f5ce1..9173274fb 100644 --- a/app/soapbox/features/public_timeline/index.js +++ b/app/soapbox/features/public_timeline/index.js @@ -6,18 +6,19 @@ import StatusListContainer from '../ui/containers/status_list_container'; import Column from '../../components/column'; import ColumnSettingsContainer from './containers/column_settings_container'; import HomeColumnHeader from '../../components/home_column_header'; -import ExplanationBox from '../ui/components/explanation_box'; +import Accordion from 'soapbox/features/ui/components/accordion'; import { expandPublicTimeline } from '../../actions/timelines'; import { connectPublicStream } from '../../actions/streaming'; import { Link } from 'react-router-dom'; -import { getSettings } from 'soapbox/actions/settings'; +import { changeSetting, getSettings } from 'soapbox/actions/settings'; const messages = defineMessages({ title: { id: 'column.public', defaultMessage: 'Federated timeline' }, }); const mapStateToProps = state => { - const onlyMedia = getSettings(state).getIn(['public', 'other', 'onlyMedia']); + const settings = getSettings(state); + const onlyMedia = settings.getIn(['public', 'other', 'onlyMedia']); const timelineId = 'public'; @@ -26,6 +27,7 @@ const mapStateToProps = state => { onlyMedia, hasUnread: state.getIn(['timelines', `${timelineId}${onlyMedia ? ':media' : ''}`, 'unread']) > 0, siteTitle: state.getIn(['instance', 'title']), + explanationBoxExpanded: settings.get('explanationBox'), }; }; @@ -44,6 +46,7 @@ class CommunityTimeline extends React.PureComponent { onlyMedia: PropTypes.bool, timelineId: PropTypes.string, siteTitle: PropTypes.string, + explanationBoxExpanded: PropTypes.bool, }; componentDidMount() { @@ -69,23 +72,48 @@ class CommunityTimeline extends React.PureComponent { } } + toggleExplanationBox = (setting) => { + this.props.dispatch(changeSetting(['explanationBox'], setting)); + } + handleLoadMore = maxId => { const { dispatch, onlyMedia } = this.props; dispatch(expandPublicTimeline({ maxId, onlyMedia })); } render() { - const { intl, hasUnread, onlyMedia, timelineId, siteTitle } = this.props; + const { intl, hasUnread, onlyMedia, timelineId, siteTitle, explanationBoxExpanded } = this.props; return ( - } - explanation={ }} />} - /> +
+ } + content={( + + + + ), + }} + /> + )} + expanded={explanationBoxExpanded} + onToggle={this.toggleExplanationBox} + /> +
this.setState({ jsonEditorExpanded: value }); + componentDidUpdate(prevProps, prevState) { if (prevProps.soapbox !== this.props.soapbox) { this.putConfig(this.props.soapbox); @@ -359,6 +360,8 @@ class SoapboxConfig extends ImmutablePureComponent { /> )} + expanded={this.state.jsonEditorExpanded} + onToggle={this.toggleJSONEditor} />
diff --git a/app/soapbox/features/ui/components/accordion.js b/app/soapbox/features/ui/components/accordion.js index 1f372f002..633309d10 100644 --- a/app/soapbox/features/ui/components/accordion.js +++ b/app/soapbox/features/ui/components/accordion.js @@ -13,28 +13,30 @@ export default @injectIntl class Accordion extends React.PureComponent { static propTypes = { headline: PropTypes.string.isRequired, content: PropTypes.oneOfType([PropTypes.string, PropTypes.element]), + expanded: PropTypes.bool, + onToggle: PropTypes.func, intl: PropTypes.object.isRequired, }; - state = { + static defaultProps = { expanded: false, + onToggle: () => {}, } - handleToggleAccordion = (e) => { - this.setState({ expanded: !this.state.expanded }); + handleToggle = (e) => { + this.props.onToggle(!this.props.expanded); e.preventDefault(); } render() { - const { headline, content, intl } = this.props; - const { expanded } = this.state; + const { headline, content, expanded, intl } = this.props; return (