From 82b01a6c9f13ab63818da3bfb8ee9cfcfda0cdd6 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Tue, 18 Dec 2018 18:52:37 +0100 Subject: [Glitch] Put "Media Only" option in column settings instead of content area headline Port 4f42238c294f92dbd87db3d83f9514344fcd1f8a to glitch-soc --- .../components/column_settings.js | 6 +++ .../components/section_headline.js | 59 ---------------------- .../containers/column_settings_container.js | 30 +++++++---- .../glitch/features/community_timeline/index.js | 41 ++++++--------- .../direct_timeline/components/column_settings.js | 35 +++++++++++++ .../containers/column_settings_container.js | 2 +- .../containers/column_settings_container.js | 31 ++++++++---- .../glitch/features/public_timeline/index.js | 44 ++++++++-------- 8 files changed, 120 insertions(+), 128 deletions(-) delete mode 100644 app/javascript/flavours/glitch/features/community_timeline/components/section_headline.js create mode 100644 app/javascript/flavours/glitch/features/direct_timeline/components/column_settings.js (limited to 'app/javascript/flavours/glitch/features') diff --git a/app/javascript/flavours/glitch/features/community_timeline/components/column_settings.js b/app/javascript/flavours/glitch/features/community_timeline/components/column_settings.js index aad5f3976..96db003ce 100644 --- a/app/javascript/flavours/glitch/features/community_timeline/components/column_settings.js +++ b/app/javascript/flavours/glitch/features/community_timeline/components/column_settings.js @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import SettingText from 'flavours/glitch/components/setting_text'; +import SettingToggle from 'flavours/glitch/features/notifications/components/setting_toggle'; const messages = defineMessages({ filter_regex: { id: 'home.column_settings.filter_regex', defaultMessage: 'Filter out by regular expressions' }, @@ -16,6 +17,7 @@ export default class ColumnSettings extends React.PureComponent { settings: ImmutablePropTypes.map.isRequired, onChange: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, + columnId: PropTypes.string, }; render () { @@ -23,6 +25,10 @@ export default class ColumnSettings extends React.PureComponent { return (
+
+ } /> +
+
diff --git a/app/javascript/flavours/glitch/features/community_timeline/components/section_headline.js b/app/javascript/flavours/glitch/features/community_timeline/components/section_headline.js deleted file mode 100644 index 8c0c68cdc..000000000 --- a/app/javascript/flavours/glitch/features/community_timeline/components/section_headline.js +++ /dev/null @@ -1,59 +0,0 @@ -import PropTypes from 'prop-types'; -import React, { Component, Fragment } from 'react'; -import { FormattedMessage } from 'react-intl'; -import { NavLink } from 'react-router-dom'; - -export default class SectionHeadline extends Component { - - static propTypes = { - timelineId: PropTypes.string.isRequired, - to: PropTypes.string.isRequired, - pinned: PropTypes.bool.isRequired, - onlyMedia: PropTypes.bool.isRequired, - onClick: PropTypes.func, - }; - - shouldComponentUpdate (nextProps) { - return ( - this.props.onlyMedia !== nextProps.onlyMedia || - this.props.pinned !== nextProps.pinned || - this.props.to !== nextProps.to || - this.props.timelineId !== nextProps.timelineId - ); - } - - handleClick = e => { - const { onClick } = this.props; - - if (typeof onClick === 'function') { - e.preventDefault(); - - onClick.call(this, e); - } - } - - render () { - const { timelineId, to, pinned, onlyMedia } = this.props; - - return ( -
- {pinned ? ( - - - - - - - - - ) : ( - - - - - )} -
- ); - } - -} diff --git a/app/javascript/flavours/glitch/features/community_timeline/containers/column_settings_container.js b/app/javascript/flavours/glitch/features/community_timeline/containers/column_settings_container.js index 39387abb9..16a963dde 100644 --- a/app/javascript/flavours/glitch/features/community_timeline/containers/column_settings_container.js +++ b/app/javascript/flavours/glitch/features/community_timeline/containers/column_settings_container.js @@ -2,16 +2,26 @@ import { connect } from 'react-redux'; import ColumnSettings from '../components/column_settings'; import { changeSetting } from 'flavours/glitch/actions/settings'; -const mapStateToProps = state => ({ - settings: state.getIn(['settings', 'community']), -}); +const mapStateToProps = (state, { columnId }) => { + const uuid = columnId; + const columns = state.getIn(['settings', 'columns']); + const index = columns.findIndex(c => c.get('uuid') === uuid); -const mapDispatchToProps = dispatch => ({ - - onChange (path, checked) { - dispatch(changeSetting(['community', ...path], checked)); - }, - -}); + return { + settings: (uuid && index >= 0) ? columns.get(index).get('params') : state.getIn(['settings', 'community']), + }; +}; + +const mapDispatchToProps = (dispatch, { columnId }) => { + return { + onChange (key, checked) { + if (columnId) { + dispatch(changeColumnParams(columnId, key, checked)); + } else { + dispatch(changeSetting(['community', ...key], checked)); + } + }, + }; +}; export default connect(mapStateToProps, mapDispatchToProps)(ColumnSettings); diff --git a/app/javascript/flavours/glitch/features/community_timeline/index.js b/app/javascript/flavours/glitch/features/community_timeline/index.js index dc52aef88..2c0fbff36 100644 --- a/app/javascript/flavours/glitch/features/community_timeline/index.js +++ b/app/javascript/flavours/glitch/features/community_timeline/index.js @@ -6,18 +6,24 @@ import StatusListContainer from 'flavours/glitch/features/ui/containers/status_l import Column from 'flavours/glitch/components/column'; import ColumnHeader from 'flavours/glitch/components/column_header'; import { expandCommunityTimeline } from 'flavours/glitch/actions/timelines'; -import { addColumn, removeColumn, moveColumn, changeColumnParams } from 'flavours/glitch/actions/columns'; +import { addColumn, removeColumn, moveColumn } from 'flavours/glitch/actions/columns'; import ColumnSettingsContainer from './containers/column_settings_container'; -import SectionHeadline from './components/section_headline'; import { connectCommunityStream } from 'flavours/glitch/actions/streaming'; const messages = defineMessages({ title: { id: 'column.community', defaultMessage: 'Local timeline' }, }); -const mapStateToProps = (state, { onlyMedia }) => ({ - hasUnread: state.getIn(['timelines', `community${onlyMedia ? ':media' : ''}`, 'unread']) > 0, -}); +const mapStateToProps = (state, { onlyMedia, columnId }) => { + const uuid = columnId; + const columns = state.getIn(['settings', 'columns']); + const index = columns.findIndex(c => c.get('uuid') === uuid); + + return { + hasUnread: state.getIn(['timelines', `community${onlyMedia ? ':media' : ''}`, 'unread']) > 0, + onlyMedia: (columnId && index >= 0) ? columns.get(index).getIn(['params', 'other', 'onlyMedia']) : state.getIn(['settings', 'community', 'other', 'onlyMedia']), + }; +}; @connect(mapStateToProps) @injectIntl @@ -27,6 +33,10 @@ export default class CommunityTimeline extends React.PureComponent { onlyMedia: false, }; + static contextTypes = { + router: PropTypes.object, + }; + static propTypes = { dispatch: PropTypes.func.isRequired, columnId: PropTypes.string, @@ -93,27 +103,10 @@ export default class CommunityTimeline extends React.PureComponent { return !(location.state && location.state.mastodonModalOpen) } - handleHeadlineLinkClick = e => { - const { columnId, dispatch } = this.props; - const onlyMedia = /\/media$/.test(e.currentTarget.href); - - dispatch(changeColumnParams(columnId, { other: { onlyMedia } })); - } - render () { const { intl, hasUnread, columnId, multiColumn, onlyMedia } = this.props; const pinned = !!columnId; - const headline = ( - - ); - return ( - + + + +
+ +
+
+ ); + } + +} diff --git a/app/javascript/flavours/glitch/features/direct_timeline/containers/column_settings_container.js b/app/javascript/flavours/glitch/features/direct_timeline/containers/column_settings_container.js index 7292af264..6385d30a4 100644 --- a/app/javascript/flavours/glitch/features/direct_timeline/containers/column_settings_container.js +++ b/app/javascript/flavours/glitch/features/direct_timeline/containers/column_settings_container.js @@ -1,5 +1,5 @@ import { connect } from 'react-redux'; -import ColumnSettings from 'flavours/glitch/features/community_timeline/components/column_settings'; +import ColumnSettings from '../components/column_settings'; import { changeSetting } from 'flavours/glitch/actions/settings'; const mapStateToProps = state => ({ diff --git a/app/javascript/flavours/glitch/features/public_timeline/containers/column_settings_container.js b/app/javascript/flavours/glitch/features/public_timeline/containers/column_settings_container.js index f042adbe6..ec4d74737 100644 --- a/app/javascript/flavours/glitch/features/public_timeline/containers/column_settings_container.js +++ b/app/javascript/flavours/glitch/features/public_timeline/containers/column_settings_container.js @@ -1,17 +1,28 @@ import { connect } from 'react-redux'; import ColumnSettings from 'flavours/glitch/features/community_timeline/components/column_settings'; import { changeSetting } from 'flavours/glitch/actions/settings'; +import { changeColumnParams } from 'flavours/glitch/actions/columns'; + +const mapStateToProps = (state, { columnId }) => { + const uuid = columnId; + const columns = state.getIn(['settings', 'columns']); + const index = columns.findIndex(c => c.get('uuid') === uuid); -const mapStateToProps = state => ({ - settings: state.getIn(['settings', 'public']), -}); + return { + settings: (uuid && index >= 0) ? columns.get(index).get('params') : state.getIn(['settings', 'public']), + }; +}; -const mapDispatchToProps = dispatch => ({ - - onChange (path, checked) { - dispatch(changeSetting(['public', ...path], checked)); - }, - -}); +const mapDispatchToProps = (dispatch, { columnId }) => { + return { + onChange (key, checked) { + if (columnId) { + dispatch(changeColumnParams(columnId, key, checked)); + } else { + dispatch(changeSetting(['public', ...key], checked)); + } + }, + }; +}; export default connect(mapStateToProps, mapDispatchToProps)(ColumnSettings); diff --git a/app/javascript/flavours/glitch/features/public_timeline/index.js b/app/javascript/flavours/glitch/features/public_timeline/index.js index 345d5efc3..ec552fb5d 100644 --- a/app/javascript/flavours/glitch/features/public_timeline/index.js +++ b/app/javascript/flavours/glitch/features/public_timeline/index.js @@ -6,18 +6,24 @@ import StatusListContainer from 'flavours/glitch/features/ui/containers/status_l import Column from 'flavours/glitch/components/column'; import ColumnHeader from 'flavours/glitch/components/column_header'; import { expandPublicTimeline } from 'flavours/glitch/actions/timelines'; -import { addColumn, removeColumn, moveColumn, changeColumnParams } from 'flavours/glitch/actions/columns'; +import { addColumn, removeColumn, moveColumn } from 'flavours/glitch/actions/columns'; import ColumnSettingsContainer from './containers/column_settings_container'; -import SectionHeadline from '../community_timeline/components/section_headline'; import { connectPublicStream } from 'flavours/glitch/actions/streaming'; const messages = defineMessages({ title: { id: 'column.public', defaultMessage: 'Federated timeline' }, }); -const mapStateToProps = (state, { onlyMedia }) => ({ - hasUnread: state.getIn(['timelines', `public${onlyMedia ? ':media' : ''}`, 'unread']) > 0, -}); +const mapStateToProps = (state, { onlyMedia, columnId }) => { + const uuid = columnId; + const columns = state.getIn(['settings', 'columns']); + const index = columns.findIndex(c => c.get('uuid') === uuid); + + return { + hasUnread: state.getIn(['timelines', `public${onlyMedia ? ':media' : ''}`, 'unread']) > 0, + onlyMedia: (columnId && index >= 0) ? columns.get(index).getIn(['params', 'other', 'onlyMedia']) : state.getIn(['settings', 'public', 'other', 'onlyMedia']), + }; +}; @connect(mapStateToProps) @injectIntl @@ -27,6 +33,10 @@ export default class PublicTimeline extends React.PureComponent { onlyMedia: false, }; + static contextTypes = { + router: PropTypes.object, + }; + static propTypes = { dispatch: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, @@ -93,27 +103,17 @@ export default class PublicTimeline extends React.PureComponent { return !(location.state && location.state.mastodonModalOpen) } - handleHeadlineLinkClick = e => { - const { columnId, dispatch } = this.props; - const onlyMedia = /\/media$/.test(e.currentTarget.href); - - dispatch(changeColumnParams(columnId, { other: { onlyMedia } })); + handleSettingChanged = (key, checked) => { + const { columnId } = this.props; + if (!columnId && key[0] === 'other' && key[1] === 'onlyMedia') { + this.context.router.history.replace(`/timelines/public${checked ? '/media' : ''}`); + } } render () { const { intl, columnId, hasUnread, multiColumn, onlyMedia } = this.props; const pinned = !!columnId; - const headline = ( - - ); - return ( - +