Accordion: replace ExplanationBox with Accordion
This commit is contained in:
parent
63fc0b4e26
commit
7b6276fa59
|
@ -6,18 +6,19 @@ import StatusListContainer from '../ui/containers/status_list_container';
|
||||||
import Column from '../../components/column';
|
import Column from '../../components/column';
|
||||||
import ColumnSettingsContainer from './containers/column_settings_container';
|
import ColumnSettingsContainer from './containers/column_settings_container';
|
||||||
import HomeColumnHeader from '../../components/home_column_header';
|
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 { expandPublicTimeline } from '../../actions/timelines';
|
||||||
import { connectPublicStream } from '../../actions/streaming';
|
import { connectPublicStream } from '../../actions/streaming';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { getSettings } from 'soapbox/actions/settings';
|
import { changeSetting, getSettings } from 'soapbox/actions/settings';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
title: { id: 'column.public', defaultMessage: 'Federated timeline' },
|
title: { id: 'column.public', defaultMessage: 'Federated timeline' },
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapStateToProps = state => {
|
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';
|
const timelineId = 'public';
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ const mapStateToProps = state => {
|
||||||
onlyMedia,
|
onlyMedia,
|
||||||
hasUnread: state.getIn(['timelines', `${timelineId}${onlyMedia ? ':media' : ''}`, 'unread']) > 0,
|
hasUnread: state.getIn(['timelines', `${timelineId}${onlyMedia ? ':media' : ''}`, 'unread']) > 0,
|
||||||
siteTitle: state.getIn(['instance', 'title']),
|
siteTitle: state.getIn(['instance', 'title']),
|
||||||
|
explanationBoxExpanded: settings.get('explanationBox'),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -44,6 +46,7 @@ class CommunityTimeline extends React.PureComponent {
|
||||||
onlyMedia: PropTypes.bool,
|
onlyMedia: PropTypes.bool,
|
||||||
timelineId: PropTypes.string,
|
timelineId: PropTypes.string,
|
||||||
siteTitle: PropTypes.string,
|
siteTitle: PropTypes.string,
|
||||||
|
explanationBoxExpanded: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
@ -69,23 +72,48 @@ class CommunityTimeline extends React.PureComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleExplanationBox = (setting) => {
|
||||||
|
this.props.dispatch(changeSetting(['explanationBox'], setting));
|
||||||
|
}
|
||||||
|
|
||||||
handleLoadMore = maxId => {
|
handleLoadMore = maxId => {
|
||||||
const { dispatch, onlyMedia } = this.props;
|
const { dispatch, onlyMedia } = this.props;
|
||||||
dispatch(expandPublicTimeline({ maxId, onlyMedia }));
|
dispatch(expandPublicTimeline({ maxId, onlyMedia }));
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { intl, hasUnread, onlyMedia, timelineId, siteTitle } = this.props;
|
const { intl, hasUnread, onlyMedia, timelineId, siteTitle, explanationBoxExpanded } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column label={intl.formatMessage(messages.title)}>
|
<Column label={intl.formatMessage(messages.title)}>
|
||||||
<HomeColumnHeader activeItem='fediverse' active={hasUnread} >
|
<HomeColumnHeader activeItem='fediverse' active={hasUnread} >
|
||||||
<ColumnSettingsContainer />
|
<ColumnSettingsContainer />
|
||||||
</HomeColumnHeader>
|
</HomeColumnHeader>
|
||||||
<ExplanationBox
|
<div className='explanation-box'>
|
||||||
title={<FormattedMessage id='fediverse_tab.explanation_box.title' defaultMessage='What is the Fediverse?' />}
|
<Accordion
|
||||||
explanation={<FormattedMessage id='fediverse_tab.explanation_box.explanation' defaultMessage='{site_title} is part of the Fediverse, a social network made up of thousands of independent social media sites (aka "servers"). The posts you see here are from 3rd-party servers. You have the freedom to engage with them, or to block any server you don't like. Pay attention to the full username after the second @ symbol to know which server a post is from. To see only {site_title} posts, visit {local}.' values={{ site_title: siteTitle, local: <Link to='/timeline/local'><FormattedMessage id='empty_column.home.local_tab' defaultMessage='the {site_title} tab' values={{ site_title: siteTitle }} /></Link> }} />}
|
headline={<FormattedMessage id='fediverse_tab.explanation_box.title' defaultMessage='What is the Fediverse?' />}
|
||||||
/>
|
content={(
|
||||||
|
<FormattedMessage
|
||||||
|
id='fediverse_tab.explanation_box.explanation'
|
||||||
|
defaultMessage='{site_title} is part of the Fediverse, a social network made up of thousands of independent social media sites (aka "servers"). The posts you see here are from 3rd-party servers. You have the freedom to engage with them, or to block any server you don't like. Pay attention to the full username after the second @ symbol to know which server a post is from. To see only {site_title} posts, visit {local}.'
|
||||||
|
values={{
|
||||||
|
site_title: siteTitle,
|
||||||
|
local: (
|
||||||
|
<Link to='/timeline/local'>
|
||||||
|
<FormattedMessage
|
||||||
|
id='empty_column.home.local_tab'
|
||||||
|
defaultMessage='the {site_title} tab'
|
||||||
|
values={{ site_title: siteTitle }}
|
||||||
|
/>
|
||||||
|
</Link>
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
expanded={explanationBoxExpanded}
|
||||||
|
onToggle={this.toggleExplanationBox}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<StatusListContainer
|
<StatusListContainer
|
||||||
scrollKey={`${timelineId}_timeline`}
|
scrollKey={`${timelineId}_timeline`}
|
||||||
timelineId={`${timelineId}${onlyMedia ? ':media' : ''}`}
|
timelineId={`${timelineId}${onlyMedia ? ':media' : ''}`}
|
||||||
|
|
|
@ -9,8 +9,6 @@ import {
|
||||||
SimpleForm,
|
SimpleForm,
|
||||||
FieldsGroup,
|
FieldsGroup,
|
||||||
TextInput,
|
TextInput,
|
||||||
Checkbox,
|
|
||||||
FileChooser,
|
|
||||||
SimpleTextarea,
|
SimpleTextarea,
|
||||||
FileChooserLogo,
|
FileChooserLogo,
|
||||||
FormPropTypes,
|
FormPropTypes,
|
||||||
|
@ -63,6 +61,7 @@ class SoapboxConfig extends ImmutablePureComponent {
|
||||||
state = {
|
state = {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
soapbox: this.props.soapbox,
|
soapbox: this.props.soapbox,
|
||||||
|
jsonEditorExpanded: false,
|
||||||
rawJSON: JSON.stringify(this.props.soapbox, null, 2),
|
rawJSON: JSON.stringify(this.props.soapbox, null, 2),
|
||||||
jsonValid: true,
|
jsonValid: true,
|
||||||
}
|
}
|
||||||
|
@ -162,6 +161,8 @@ class SoapboxConfig extends ImmutablePureComponent {
|
||||||
return defaultConfig.mergeDeep(this.state.soapbox);
|
return defaultConfig.mergeDeep(this.state.soapbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleJSONEditor = (value) => this.setState({ jsonEditorExpanded: value });
|
||||||
|
|
||||||
componentDidUpdate(prevProps, prevState) {
|
componentDidUpdate(prevProps, prevState) {
|
||||||
if (prevProps.soapbox !== this.props.soapbox) {
|
if (prevProps.soapbox !== this.props.soapbox) {
|
||||||
this.putConfig(this.props.soapbox);
|
this.putConfig(this.props.soapbox);
|
||||||
|
@ -359,6 +360,8 @@ class SoapboxConfig extends ImmutablePureComponent {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
expanded={this.state.jsonEditorExpanded}
|
||||||
|
onToggle={this.toggleJSONEditor}
|
||||||
/>
|
/>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<div className='actions'>
|
<div className='actions'>
|
||||||
|
|
|
@ -13,28 +13,30 @@ export default @injectIntl class Accordion extends React.PureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
headline: PropTypes.string.isRequired,
|
headline: PropTypes.string.isRequired,
|
||||||
content: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
content: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
||||||
|
expanded: PropTypes.bool,
|
||||||
|
onToggle: PropTypes.func,
|
||||||
intl: PropTypes.object.isRequired,
|
intl: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
state = {
|
static defaultProps = {
|
||||||
expanded: false,
|
expanded: false,
|
||||||
|
onToggle: () => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
handleToggleAccordion = (e) => {
|
handleToggle = (e) => {
|
||||||
this.setState({ expanded: !this.state.expanded });
|
this.props.onToggle(!this.props.expanded);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { headline, content, intl } = this.props;
|
const { headline, content, expanded, intl } = this.props;
|
||||||
const { expanded } = this.state;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames('accordion', { 'accordion--expanded' : expanded })}>
|
<div className={classNames('accordion', { 'accordion--expanded' : expanded })}>
|
||||||
<button
|
<button
|
||||||
type='button'
|
type='button'
|
||||||
className='accordion__title'
|
className='accordion__title'
|
||||||
onClick={this.handleToggleAccordion}
|
onClick={this.handleToggle}
|
||||||
title={intl.formatMessage(expanded ? messages.collapse : messages.expand)}
|
title={intl.formatMessage(expanded ? messages.collapse : messages.expand)}
|
||||||
>
|
>
|
||||||
{headline}
|
{headline}
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
import React from 'react';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
||||||
import { connect } from 'react-redux';
|
|
||||||
import { defineMessages, injectIntl } from 'react-intl';
|
|
||||||
import IconButton from 'soapbox/components/icon_button';
|
|
||||||
import { changeSetting, getSettings } from 'soapbox/actions/settings';
|
|
||||||
|
|
||||||
|
|
||||||
const messages = defineMessages({
|
|
||||||
collapse: { id: 'explanation_box.collapse', defaultMessage: 'Collapse explanation box' },
|
|
||||||
expand: { id: 'explanation_box.expand', defaultMessage: 'Expand explanation box' },
|
|
||||||
});
|
|
||||||
|
|
||||||
const mapStateToProps = state => {
|
|
||||||
return {
|
|
||||||
settings: getSettings(state),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
|
||||||
toggleExplanationBox(setting) {
|
|
||||||
dispatch(changeSetting(['explanationBox'], setting));
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default @connect(mapStateToProps, mapDispatchToProps)
|
|
||||||
@injectIntl
|
|
||||||
class ExplanationBox extends React.PureComponent {
|
|
||||||
|
|
||||||
static propTypes = {
|
|
||||||
title: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
|
||||||
explanation: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
|
||||||
dismissable: PropTypes.bool,
|
|
||||||
intl: PropTypes.object.isRequired,
|
|
||||||
settings: ImmutablePropTypes.map.isRequired,
|
|
||||||
toggleExplanationBox: PropTypes.func,
|
|
||||||
};
|
|
||||||
|
|
||||||
handleToggleExplanationBox = () => {
|
|
||||||
this.props.toggleExplanationBox(this.props.settings.get('explanationBox') === true ? false : true);
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { title, explanation, dismissable, settings, intl } = this.props;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='explanation-box'>
|
|
||||||
{title && <div className='explanation-box__title'>{title}
|
|
||||||
<IconButton
|
|
||||||
className='explanation_box__toggle' size={20}
|
|
||||||
title={settings.get('explanationBox') ? intl.formatMessage(messages.collapse) : intl.formatMessage(messages.expand)}
|
|
||||||
icon={settings.get('explanationBox') ? 'angle-down' : 'angle-up'}
|
|
||||||
onClick={this.handleToggleExplanationBox}
|
|
||||||
/>
|
|
||||||
</div>}
|
|
||||||
{settings.get('explanationBox') &&
|
|
||||||
<div className='explanation-box__explanation'>
|
|
||||||
{explanation}
|
|
||||||
{dismissable && <span className='explanation-box__dismiss'>Dismiss</span>}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -2,7 +2,6 @@
|
||||||
margin: 5px 20px;
|
margin: 5px 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.explanation-box,
|
|
||||||
.accordion {
|
.accordion {
|
||||||
color: var(--primary-text-color);
|
color: var(--primary-text-color);
|
||||||
padding: 15px 20px;
|
padding: 15px 20px;
|
||||||
|
@ -15,11 +14,15 @@
|
||||||
font-weight: bold !important;
|
font-weight: bold !important;
|
||||||
font-size: 16px !important;
|
font-size: 16px !important;
|
||||||
background: transparent !important;
|
background: transparent !important;
|
||||||
|
color: var(--primary-text-color) !important;
|
||||||
padding: 0 !important;
|
padding: 0 !important;
|
||||||
margin: 0 !important;
|
margin: 0 !important;
|
||||||
text-transform: none !important;
|
text-transform: none !important;
|
||||||
text-align: left !important;
|
text-align: left !important;
|
||||||
display: flex !important;
|
display: flex !important;
|
||||||
|
color: var(--primary-text-color);
|
||||||
|
border: 0;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
&::after {
|
&::after {
|
||||||
content: '';
|
content: '';
|
||||||
|
@ -48,10 +51,6 @@
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__explanation {
|
|
||||||
margin-top: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: var(--brand-color--hicontrast);
|
color: var(--brand-color--hicontrast);
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
|
|
Loading…
Reference in New Issue