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 { selectUser } from 'redux/selectors/user';
import DiscoveryFirstRun from './view'; import DiscoveryFirstRun from './view';
const select = state => ({ const select = (state, props) => ({
unfollowedTags: selectUnfollowedTags(state), unfollowedTags: props.unfollowedTags || selectUnfollowedTags(state),
followedTags: selectFollowedTags(state), followedTags: props.followedTags || selectFollowedTags(state),
user: selectUser(state), user: selectUser(state),
}); });

View file

@ -14,11 +14,14 @@ type Props = {
doToggleTagFollowDesktop: (string) => void, doToggleTagFollowDesktop: (string) => void,
doAddTag: (string) => void, doAddTag: (string) => void,
onSelect?: (Tag) => void, onSelect?: (Tag) => void,
hideSuggestions?: boolean,
suggestMature?: boolean, suggestMature?: boolean,
disableAutoFocus?: boolean, disableAutoFocus?: boolean,
onRemove: (Tag) => void, onRemove: (Tag) => void,
placeholder?: string, placeholder?: string,
label?: string, label?: string,
labelAddNew?: string,
labelSuggestions?: string,
disabled?: boolean, disabled?: boolean,
limitSelect?: number, limitSelect?: number,
limitShow?: number, limitShow?: number,
@ -44,10 +47,13 @@ export default function TagsSearch(props: Props) {
doAddTag, doAddTag,
onSelect, onSelect,
onRemove, onRemove,
hideSuggestions,
suggestMature, suggestMature,
disableAutoFocus, disableAutoFocus,
placeholder, placeholder,
label, label,
labelAddNew,
labelSuggestions,
disabled, disabled,
limitSelect = TAG_FOLLOW_MAX, limitSelect = TAG_FOLLOW_MAX,
limitShow = 5, limitShow = 5,
@ -189,10 +195,11 @@ export default function TagsSearch(props: Props) {
type="text" type="text"
value={newTag} value={newTag}
disabled={disabled} disabled={disabled}
label={__('Add Tags')} label={labelAddNew || __('Add Tags')}
/> />
{!hideSuggestions && (
<section> <section>
<label>{newTag.length ? __('Matching') : __('Known Tags')}</label> <label>{labelSuggestions || (newTag.length ? __('Matching') : __('Known Tags'))}</label>
<ul className="tags"> <ul className="tags">
{Boolean(newTag.length) && !suggestedTags.includes(newTag) && ( {Boolean(newTag.length) && !suggestedTags.includes(newTag) && (
<Tag <Tag
@ -214,6 +221,7 @@ export default function TagsSearch(props: Props) {
))} ))}
</ul> </ul>
</section> </section>
)}
</fieldset-section> </fieldset-section>
{experimentalFeature && {experimentalFeature &&
onSelect && ( // onSelect ensures this does not appear on TagFollow onSelect && ( // onSelect ensures this does not appear on TagFollow