From 4be73132982fec0a38420811ae28a4ffd2ea09c7 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Tue, 18 Dec 2018 17:56:08 +0100 Subject: [Glitch] Allow joining several hashtags in a single column Port 4c03e05a4e1a237f8a414a0861c03abe3269dbc8 to glitch-soc This introduces new requirements in the API: `/api/v1/timelines/tag/:tag` now accepts new params: `any`, `all` and `none` It now returns status matching tag :tag or any of the :any, provided that they also include all tags in `all` and none of `none`. --- .../hashtag_timeline/components/column_settings.js | 102 +++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 app/javascript/flavours/glitch/features/hashtag_timeline/components/column_settings.js (limited to 'app/javascript/flavours/glitch/features/hashtag_timeline/components/column_settings.js') diff --git a/app/javascript/flavours/glitch/features/hashtag_timeline/components/column_settings.js b/app/javascript/flavours/glitch/features/hashtag_timeline/components/column_settings.js new file mode 100644 index 000000000..82936c838 --- /dev/null +++ b/app/javascript/flavours/glitch/features/hashtag_timeline/components/column_settings.js @@ -0,0 +1,102 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import ImmutablePropTypes from 'react-immutable-proptypes'; +import { injectIntl, FormattedMessage } from 'react-intl'; +import Toggle from 'react-toggle'; +import AsyncSelect from 'react-select/lib/Async'; + +@injectIntl +export default class ColumnSettings extends React.PureComponent { + + static propTypes = { + settings: ImmutablePropTypes.map.isRequired, + onChange: PropTypes.func.isRequired, + onLoad: PropTypes.func.isRequired, + intl: PropTypes.object.isRequired, + }; + + state = { + open: this.hasTags(), + }; + + hasTags () { + return ['all', 'any', 'none'].map(mode => this.tags(mode).length > 0).includes(true); + } + + tags (mode) { + let tags = this.props.settings.getIn(['tags', mode]) || []; + if (tags.toJSON) { + return tags.toJSON(); + } else { + return tags; + } + }; + + onSelect = (mode) => { + return (value) => { + this.props.onChange(['tags', mode], value); + }; + }; + + onToggle = () => { + if (this.state.open && this.hasTags()) { + this.props.onChange('tags', {}); + } + this.setState({ open: !this.state.open }); + }; + + modeSelect (mode) { + return ( +
+ {this.modeLabel(mode)} + +
+ ); + } + + modeLabel (mode) { + switch(mode) { + case 'any': return ; + case 'all': return ; + case 'none': return ; + } + return ''; + }; + + render () { + return ( +
+
+
+ + + + +
+
+ {this.state.open && +
+ {this.modeSelect('any')} + {this.modeSelect('all')} + {this.modeSelect('none')} +
+ } +
+ ); + } + +} -- cgit