From e402a0376a161a5d593885da17d7079ceda15081 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Mon, 11 Mar 2019 12:09:08 +0100 Subject: [PATCH] implement direct search and show featured claim result (#468) --- app/src/component/fileListItem/view.js | 11 +++++-- app/src/component/uriBar/view.js | 18 ++++++++++-- app/src/page/search/view.js | 40 +++++++++++++++++++------- app/src/styles/fileList.js | 10 +++++++ app/src/styles/search.js | 17 +++++++++-- 5 files changed, 78 insertions(+), 18 deletions(-) diff --git a/app/src/component/fileListItem/view.js b/app/src/component/fileListItem/view.js index 00f89914..2db2fd9b 100644 --- a/app/src/component/fileListItem/view.js +++ b/app/src/component/fileListItem/view.js @@ -51,6 +51,7 @@ class FileListItem extends React.PureComponent { claim, fileInfo, metadata, + featuredResult, isResolvingUri, isDownloaded, style, @@ -72,6 +73,10 @@ class FileListItem extends React.PureComponent { fullChannelUri = channelClaimId ? `${channel}#${channelClaimId}` : channel; } + if (featuredResult && !isResolvingUri && !claim && !title && !name) { + return null; + } + return ( @@ -81,15 +86,17 @@ class FileListItem extends React.PureComponent { title={(title || name)} thumbnail={metadata ? metadata.thumbnail : null} /> + {featuredResult && {uri}} + {!title && !name && !channel && isResolving && ( {(!title && !name) && {uri}} {(!title && !name) && - + } )} - {(title || name) && {this.formatTitle(title) || this.formatTitle(name)}} + {(title || name) && {this.formatTitle(title) || this.formatTitle(name)}} {channel && { navigateToUri(navigation, normalizeURI(fullChannelUri)); diff --git a/app/src/component/uriBar/view.js b/app/src/component/uriBar/view.js index 2313203d..4cea8a3a 100644 --- a/app/src/component/uriBar/view.js +++ b/app/src/component/uriBar/view.js @@ -32,17 +32,29 @@ class UriBar extends React.PureComponent { changeTextTimeout: null, currentValue: null, inputText: null, - focused: false + focused: false, + // TODO: Add a setting to enable / disable direct search? + directSearch: true }; } handleChangeText = text => { const newValue = text ? text : ''; clearTimeout(this.state.changeTextTimeout); - const { updateSearchQuery } = this.props; + const { updateSearchQuery, onSearchSubmitted, navigation } = this.props; let timeout = setTimeout(() => { updateSearchQuery(text); + + if (!text.startsWith('lbry://')) { + // not a URI input, so this is a search, perform a direct search + if (onSearchSubmitted) { + onSearchSubmitted(text); + } else { + navigation.navigate({ routeName: 'Search', key: 'searchPage', params: { searchQuery: text }}); + } + } + }, UriBar.INPUT_TIMEOUT); this.setState({ inputText: newValue, currentValue: newValue, changeTextTimeout: timeout }); } @@ -141,7 +153,7 @@ class UriBar extends React.PureComponent { } }}/> - {this.state.focused && ( + {(this.state.focused && !this.state.directSearch) && ( 0) { + this.setState({ currentUri: (isURIValid(searchQuery)) ? normalizeURI(searchQuery) : null }) search(searchQuery); } } + handleSearchSubmitted = (keywords) => { + const { search } = this.props; + this.setState({ currentUri: (isURIValid(keywords)) ? normalizeURI(keywords) : null }); + search(keywords); + } + render() { - const { isSearching, navigation, query, search, uris } = this.props; + const { isSearching, navigation, query, uris } = this.props; const { searchQuery } = navigation.state.params; return ( search(keywords)} /> + onSearchSubmitted={this.handleSearchSubmitted} /> {!isSearching && (!uris || uris.length === 0) && No results to display.} + {this.state.currentUri && + navigateToUri(navigation, this.state.currentUri)} + />} {!isSearching && uris && uris.length ? ( uris.map(uri =>