add tag to wunderbar autocomplete

This commit is contained in:
Sean Yesmunt 2019-07-11 14:16:39 -04:00
parent da861ca669
commit 075f745ddd
4 changed files with 27 additions and 9 deletions

View file

@ -253,6 +253,12 @@ export const icons = {
<path d="M7 11V7a5 5 0 0 1 9.9-1" /> <path d="M7 11V7a5 5 0 0 1 9.9-1" />
</g> </g>
), ),
[ICONS.TAG]: buildIcon(
<g>
<path d="M20.59 13.41l-7.17 7.17a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82z" />
<line x1="7" y1="7" x2="7" y2="7" />
</g>
),
[ICONS.SUPPORT]: buildIcon( [ICONS.SUPPORT]: buildIcon(
<g> <g>
<polyline points="23 6 13.5 15.5 8.5 10.5 1 18" /> <polyline points="23 6 13.5 15.5 8.5 10.5 1 18" />

View file

@ -3,10 +3,11 @@ import * as PAGES from 'constants/pages';
import * as ICONS from 'constants/icons'; import * as ICONS from 'constants/icons';
import React from 'react'; import React from 'react';
import classnames from 'classnames'; import classnames from 'classnames';
import { normalizeURI, SEARCH_TYPES, isURIValid, buildURI } from 'lbry-redux'; import { normalizeURI, SEARCH_TYPES, isURIValid } from 'lbry-redux';
import { withRouter } from 'react-router';
import Icon from 'component/common/icon'; import Icon from 'component/common/icon';
import { parseQueryParams } from 'util/query-params';
import Autocomplete from './internal/autocomplete'; import Autocomplete from './internal/autocomplete';
import Tag from 'component/tag';
const L_KEY_CODE = 76; const L_KEY_CODE = 76;
const ESC_KEY_CODE = 27; const ESC_KEY_CODE = 27;
@ -22,6 +23,7 @@ type Props = {
doBlur: () => void, doBlur: () => void,
focused: boolean, focused: boolean,
doShowSnackBar: string => void, doShowSnackBar: string => void,
history: { push: string => void },
}; };
type State = { type State = {
@ -51,10 +53,12 @@ class WunderBar extends React.PureComponent<Props, State> {
getSuggestionIcon = (type: string) => { getSuggestionIcon = (type: string) => {
switch (type) { switch (type) {
case 'file': case SEARCH_TYPES.FILE:
return ICONS.FILE; return ICONS.FILE;
case 'channel': case SEARCH_TYPES.CHANNEL:
return ICONS.CHANNEL; return ICONS.CHANNEL;
case SEARCH_TYPES.TAG:
return ICONS.TAG;
default: default:
return ICONS.SEARCH; return ICONS.SEARCH;
} }
@ -90,7 +94,7 @@ class WunderBar extends React.PureComponent<Props, State> {
} }
handleSubmit(value: string, suggestion?: { value: string, type: string }) { handleSubmit(value: string, suggestion?: { value: string, type: string }) {
const { onSubmit, onSearch, doShowSnackBar } = this.props; const { onSubmit, onSearch, doShowSnackBar, history } = this.props;
const query = value.trim(); const query = value.trim();
const showSnackError = () => { const showSnackError = () => {
@ -99,8 +103,10 @@ class WunderBar extends React.PureComponent<Props, State> {
// User selected a suggestion // User selected a suggestion
if (suggestion) { if (suggestion) {
if (suggestion.type === 'search') { if (suggestion.type === SEARCH_TYPES.SEARCH) {
onSearch(query); onSearch(query);
} else if (suggestion.type === SEARCH_TYPES.TAG) {
history.push(`/$/${PAGES.TAGS}?t=${suggestion.value}`);
} else if (isURIValid(query)) { } else if (isURIValid(query)) {
const uri = normalizeURI(query); const uri = normalizeURI(query);
onSubmit(uri); onSubmit(uri);
@ -157,18 +163,22 @@ class WunderBar extends React.PureComponent<Props, State> {
)} )}
renderItem={({ value, type }, isHighlighted) => ( renderItem={({ value, type }, isHighlighted) => (
<div <div
key={value} // Use value + type for key because there might be suggestions with same value but different type
key={`${value}-${type}`}
className={classnames('wunderbar__suggestion', { className={classnames('wunderbar__suggestion', {
'wunderbar__active-suggestion': isHighlighted, 'wunderbar__active-suggestion': isHighlighted,
})} })}
> >
<Icon icon={this.getSuggestionIcon(type)} /> <Icon icon={this.getSuggestionIcon(type)} />
<span className="wunderbar__suggestion-label">{value}</span> <span className="wunderbar__suggestion-label">
{type === SEARCH_TYPES.TAG ? <Tag name={value} /> : value}
</span>
{isHighlighted && ( {isHighlighted && (
<span className="wunderbar__suggestion-label--action"> <span className="wunderbar__suggestion-label--action">
{type === SEARCH_TYPES.SEARCH && __('Search')} {type === SEARCH_TYPES.SEARCH && __('Search')}
{type === SEARCH_TYPES.CHANNEL && __('View channel')} {type === SEARCH_TYPES.CHANNEL && __('View channel')}
{type === SEARCH_TYPES.FILE && __('View file')} {type === SEARCH_TYPES.FILE && __('View file')}
{type === SEARCH_TYPES.TAG && __('View Tag')}
</span> </span>
)} )}
</div> </div>
@ -179,4 +189,4 @@ class WunderBar extends React.PureComponent<Props, State> {
} }
} }
export default WunderBar; export default withRouter(WunderBar);

View file

@ -69,4 +69,5 @@ export const MUSIC_EQUALIZER = 'Sliders';
export const LIGHT = 'Sun'; export const LIGHT = 'Sun';
export const DARK = 'Moon'; export const DARK = 'Moon';
export const LIBRARY = 'Folder'; export const LIBRARY = 'Folder';
export const TAG = 'Tag';
export const SUPPORT = 'TrendingUp'; export const SUPPORT = 'TrendingUp';

View file

@ -72,6 +72,7 @@
box-shadow: 0 1px 5px rgba($lbry-black, 0.15); box-shadow: 0 1px 5px rgba($lbry-black, 0.15);
min-width: 100%; min-width: 100%;
overflow: hidden; overflow: hidden;
font-size: 14px;
[data-mode='dark'] & { [data-mode='dark'] & {
background-color: $lbry-gray-5; background-color: $lbry-gray-5;