TagsSearch: tweaks to allow re-use beyond tags

- Allow 'followed' and 'unfollowed' list to be overridden via props.
- Allow labels to be overridden via props.
- Add ability to disable "Suggestions"
This commit is contained in:
infinite-persistence 2021-04-21 16:38:01 +08:00 committed by Thomas Zarebczan
parent 1008724761
commit b2c2096da5
2 changed files with 35 additions and 27 deletions

View file

@ -4,9 +4,9 @@ import { doToggleTagFollowDesktop, doAddTag, doDeleteTag } from 'redux/actions/t
import { selectUser } from 'redux/selectors/user';
import DiscoveryFirstRun from './view';
const select = state => ({
unfollowedTags: selectUnfollowedTags(state),
followedTags: selectFollowedTags(state),
const select = (state, props) => ({
unfollowedTags: props.unfollowedTags || selectUnfollowedTags(state),
followedTags: props.followedTags || selectFollowedTags(state),
user: selectUser(state),
});

View file

@ -14,11 +14,14 @@ type Props = {
doToggleTagFollowDesktop: (string) => void,
doAddTag: (string) => void,
onSelect?: (Tag) => void,
hideSuggestions?: boolean,
suggestMature?: boolean,
disableAutoFocus?: boolean,
onRemove: (Tag) => void,
placeholder?: string,
label?: string,
labelAddNew?: string,
labelSuggestions?: string,
disabled?: boolean,
limitSelect?: number,
limitShow?: number,
@ -44,10 +47,13 @@ export default function TagsSearch(props: Props) {
doAddTag,
onSelect,
onRemove,
hideSuggestions,
suggestMature,
disableAutoFocus,
placeholder,
label,
labelAddNew,
labelSuggestions,
disabled,
limitSelect = TAG_FOLLOW_MAX,
limitShow = 5,
@ -189,31 +195,33 @@ export default function TagsSearch(props: Props) {
type="text"
value={newTag}
disabled={disabled}
label={__('Add Tags')}
label={labelAddNew || __('Add Tags')}
/>
<section>
<label>{newTag.length ? __('Matching') : __('Known Tags')}</label>
<ul className="tags">
{Boolean(newTag.length) && !suggestedTags.includes(newTag) && (
<Tag
disabled={newTag !== 'mature' && maxed}
key={`entered${newTag}`}
name={newTag}
type="add"
onClick={newTag.includes('') ? (e) => handleSubmit(e) : (e) => handleTagClick(newTag)}
/>
)}
{suggestedTags.map((tag) => (
<Tag
disabled={tag !== 'mature' && maxed}
key={`suggested${tag}`}
name={tag}
type="add"
onClick={() => handleTagClick(tag)}
/>
))}
</ul>
</section>
{!hideSuggestions && (
<section>
<label>{labelSuggestions || (newTag.length ? __('Matching') : __('Known Tags'))}</label>
<ul className="tags">
{Boolean(newTag.length) && !suggestedTags.includes(newTag) && (
<Tag
disabled={newTag !== 'mature' && maxed}
key={`entered${newTag}`}
name={newTag}
type="add"
onClick={newTag.includes('') ? (e) => handleSubmit(e) : (e) => handleTagClick(newTag)}
/>
)}
{suggestedTags.map((tag) => (
<Tag
disabled={tag !== 'mature' && maxed}
key={`suggested${tag}`}
name={tag}
type="add"
onClick={() => handleTagClick(tag)}
/>
))}
</ul>
</section>
)}
</fieldset-section>
{experimentalFeature &&
onSelect && ( // onSelect ensures this does not appear on TagFollow