diff --git a/app/controllers/api/v1/lists/tags_controller.rb b/app/controllers/api/v1/lists/tags_controller.rb index 6d71ee0d13ef42..3dd77aa416b10d 100644 --- a/app/controllers/api/v1/lists/tags_controller.rb +++ b/app/controllers/api/v1/lists/tags_controller.rb @@ -44,13 +44,13 @@ def load_tags end def list_tags - names = tag_ids.select{|t| t !=~ /\A[0-9]+\Z/} - ids = tag_ids.select{|t| t =~ /\A[0-9]+\Z/} - existing_by_name = Tag.where(name: names.map{|n| Tag.normalize(n)}).select(:id, :name) - ids.push(*existing_by_name.map {|t| t.id}) - not_existing_by_name = names.select{|n| !existing_by_name.any? {|e| e.name == Tag.normalize(n)}} + names = tag_ids.reject { |t| t =~ /\A[0-9]+\Z/ } + ids = tag_ids.select { |t| t =~ /\A[0-9]+\Z/ } + existing_by_name = Tag.where(name: names.map { |n| Tag.normalize(n) }).select(:id, :name) + ids.push(*existing_by_name.map { |t| t.id }) + not_existing_by_name = names.reject { |n| existing_by_name.any? { |e| e.name == Tag.normalize(n) }} created = Tag.find_or_create_by_names(not_existing_by_name) - ids.push(*created.map {|t| t.id}) + ids.push(*created.map(&:id) Tag.find(ids) end diff --git a/app/javascript/flavours/glitch/actions/importer/index.js b/app/javascript/flavours/glitch/actions/importer/index.js index 46be1107a22b45..6b1b0b35141ec8 100644 --- a/app/javascript/flavours/glitch/actions/importer/index.js +++ b/app/javascript/flavours/glitch/actions/importer/index.js @@ -55,7 +55,7 @@ export function importFetchedAccounts(accounts) { } export function importFetchedTags(tags) { - return (dispatch, getState) => { + return (dispatch) => { const uniqueTags = []; function processTag(tag) { pushUnique(uniqueTags, tag); diff --git a/app/javascript/flavours/glitch/features/list_editor/components/add_tag.jsx b/app/javascript/flavours/glitch/features/list_editor/components/add_tag.jsx index 490cf3668658de..1bd4a9e965ced8 100644 --- a/app/javascript/flavours/glitch/features/list_editor/components/add_tag.jsx +++ b/app/javascript/flavours/glitch/features/list_editor/components/add_tag.jsx @@ -11,8 +11,7 @@ import CancelIcon from '@/material-icons/400-24px/cancel.svg?react'; import TagIcon from '@/material-icons/400-24px/tag.svg?react'; import { Icon } from 'flavours/glitch/components/icon'; -import { changeListSuggestions } from '../../../actions/lists'; -import { addToListEditor } from '../../../actions/lists'; +import { addToListEditor, changeListSuggestions } from '../../../actions/lists'; const messages = defineMessages({ addtag: { id: 'lists.addtag', defaultMessage: 'Enter a tag you\'d like to follow' }, @@ -33,6 +32,7 @@ class AddTag extends PureComponent { intl: PropTypes.object.isRequired, value: PropTypes.string.isRequired, onSubmit: PropTypes.func.isRequired, + onChange: PropTypes.func.isRequired, }; handleChange = e => { diff --git a/app/javascript/flavours/glitch/features/list_editor/components/tag.jsx b/app/javascript/flavours/glitch/features/list_editor/components/tag.jsx index 5a8761c5e76461..d7d808a52f37cd 100644 --- a/app/javascript/flavours/glitch/features/list_editor/components/tag.jsx +++ b/app/javascript/flavours/glitch/features/list_editor/components/tag.jsx @@ -5,8 +5,8 @@ import { defineMessages, injectIntl } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { connect } from 'react-redux'; -import TagIcon from '@/material-icons/400-24px/tag.svg?react'; import CloseIcon from '@/material-icons/400-24px/close.svg?react'; +import TagIcon from '@/material-icons/400-24px/tag.svg?react'; import { Icon } from 'flavours/glitch/components/icon'; import { removeFromListEditor, addToListEditor } from '../../../actions/lists'; @@ -18,12 +18,10 @@ const messages = defineMessages({ }); const makeMapStateToProps = () => { - const mapStateToProps = (state, { tag, added }) => { - return { - tag: tag, - added: typeof added === 'undefined' ? state.getIn(['listEditor', 'tags', 'items']).includes(tag) : added, - } - }; + const mapStateToProps = (state, { tag, added }) => ({ + tag: tag, + added: typeof added === 'undefined' ? state.getIn(['listEditor', 'tags', 'items']).includes(tag) : added, + }); return mapStateToProps; }; diff --git a/app/javascript/flavours/glitch/features/list_editor/index.jsx b/app/javascript/flavours/glitch/features/list_editor/index.jsx index cfe947306675ad..5b58e69a145f7c 100644 --- a/app/javascript/flavours/glitch/features/list_editor/index.jsx +++ b/app/javascript/flavours/glitch/features/list_editor/index.jsx @@ -1,6 +1,6 @@ import PropTypes from 'prop-types'; -import { injectIntl } from 'react-intl'; +import { defineMessages, injectIntl } from 'react-intl'; import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; @@ -12,10 +12,15 @@ import { setupListEditor, clearListSuggestions, resetListEditor } from '../../ac import Motion from '../ui/util/optional_motion'; import Account from './components/account'; -import Tag from './components/tag'; +import AddTag from './components/add_tag'; import EditListForm from './components/edit_list_form'; import Search from './components/search'; -import AddTag from './components/add_tag'; +import Tag from './components/tag'; + +const messages = defineMessages({ + account_tab: { id: 'lists.account_tab', defaultMessage: 'Accounts' }, + tag_tab: { id: 'lists.tag_tab', defaultMessage: 'Tags' }, +}); const mapStateToProps = state => ({ tags: state.getIn(['listEditor', 'tags', 'items']), @@ -35,6 +40,7 @@ class ListEditor extends ImmutablePureComponent { }; static propTypes = { + intl: PropTypes.object.isRequired, listId: PropTypes.string.isRequired, onClose: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, @@ -46,31 +52,39 @@ class ListEditor extends ImmutablePureComponent { searchAccountIds: ImmutablePropTypes.list.isRequired, }; - componentDidMount () { + componentDidMount() { const { onInitialize, listId } = this.props; onInitialize(listId); } - componentWillUnmount () { + componentWillUnmount() { const { onReset } = this.props; onReset(); } + switchToAccounts() { + this.switchToTab('accounts'); + } + + switchToTags() { + this.switchToTab('tags'); + } + switchToTab(tab) { this.setState({ ...this.state, currentTab: tab }); } - render () { - const { accountIds, tags, searchAccountIds, onClear } = this.props; + render() { + const { accountIds, tags, searchAccountIds, onClear, intl } = this.props; const showSearch = searchAccountIds.size > 0; return (