update tag result if the search keyword is updated

This commit is contained in:
Akinwale Ariwodola 2020-01-06 23:01:27 +01:00
parent 91eb18ec9b
commit 673d6dc0f5
2 changed files with 17 additions and 21 deletions

View file

@ -58,8 +58,6 @@ class UriBar extends React.PureComponent {
clearTimeout(this.changeTextTimeout); clearTimeout(this.changeTextTimeout);
const { updateSearchQuery, onSearchSubmitted, showUriBarSuggestions, navigation } = this.props; const { updateSearchQuery, onSearchSubmitted, showUriBarSuggestions, navigation } = this.props;
updateSearchQuery(text);
this.changeTextTimeout = -1; this.changeTextTimeout = -1;
if (!showUriBarSuggestions) { if (!showUriBarSuggestions) {
this.changeTextTimeout = setTimeout(() => { this.changeTextTimeout = setTimeout(() => {
@ -70,6 +68,7 @@ class UriBar extends React.PureComponent {
if (!text.startsWith('lbry://')) { if (!text.startsWith('lbry://')) {
// not a URI input, so this is a search, perform a direct search // not a URI input, so this is a search, perform a direct search
updateSearchQuery(text);
if (onSearchSubmitted) { if (onSearchSubmitted) {
onSearchSubmitted(text); onSearchSubmitted(text);
} else { } else {
@ -77,6 +76,8 @@ class UriBar extends React.PureComponent {
} }
} }
}, UriBar.INPUT_TIMEOUT); }, UriBar.INPUT_TIMEOUT);
} else {
updateSearchQuery(text);
} }
this.setState({ inputText: newValue, currentValue: newValue }); this.setState({ inputText: newValue, currentValue: newValue });
}; };

View file

@ -28,6 +28,7 @@ class SearchPage extends React.PureComponent {
claimSearchRun: false, claimSearchRun: false,
claimSearchOptions: null, claimSearchOptions: null,
resultsResolved: false, resultsResolved: false,
tagResultDisplayed: false,
}; };
static navigationOptions = { static navigationOptions = {
@ -61,6 +62,7 @@ class SearchPage extends React.PureComponent {
claimSearchRun: false, claimSearchRun: false,
showTagResult: false, showTagResult: false,
resultsResolved: false, resultsResolved: false,
tagResultDisplayed: false,
}); });
search(searchQuery); search(searchQuery);
} }
@ -84,6 +86,7 @@ class SearchPage extends React.PureComponent {
currentQuery: query, currentQuery: query,
currentUri: isURIValid(query) ? normalizeURI(query) : null, currentUri: isURIValid(query) ? normalizeURI(query) : null,
resultsResolved: false, resultsResolved: false,
tagResultDisplayed: false,
}); });
search(query); search(query);
} }
@ -111,14 +114,12 @@ class SearchPage extends React.PureComponent {
} */ } */
componentDidUpdate() { componentDidUpdate() {
/* const { isSearching, resolveUris, uris } = this.props; const { claimSearchByQuery } = this.props;
if (!isSearching && !this.state.resultsResolved) { if (this.state.claimSearchRun && this.state.claimSearchOptions && !this.state.tagResultDisplayed) {
this.setState({ resultsResolved: true }, () => { const claimSearchKey = createNormalizedClaimSearchKey(this.state.claimSearchOptions);
if (uris && uris.length > 0) { const claimSearchUris = claimSearchByQuery[claimSearchKey];
resolveUris(uris); this.setState({ showTagResult: claimSearchUris && claimSearchUris.length > 0, tagResultDisplayed: true });
} }
});
} */
} }
getSearchQuery() { getSearchQuery() {
@ -137,6 +138,7 @@ class SearchPage extends React.PureComponent {
claimSearchRun: false, claimSearchRun: false,
showTagResult: false, showTagResult: false,
resultsResolved: false, resultsResolved: false,
tagResultDisplayed: false,
}); });
search(keywords); search(keywords);
}; };
@ -152,27 +154,20 @@ class SearchPage extends React.PureComponent {
); );
}; };
listHeaderComponent = showTagResult => { listHeaderComponent = (showTagResult, query) => {
const { navigation, claimSearch, claimSearchByQuery } = this.props; const { navigation, claimSearch } = this.props;
const { currentUri } = this.state; const { currentUri } = this.state;
const query = this.getSearchQuery();
const canBeTag = query && query.trim().length > 0 && isURIValid(query); const canBeTag = query && query.trim().length > 0 && isURIValid(query);
if (canBeTag && !this.state.claimSearchRun) { if (canBeTag && !this.state.claimSearchRun) {
const options = { const options = {
any_tags: [query], any_tags: [query.toLowerCase()],
page: 1, page: 1,
no_totals: true, no_totals: true,
}; };
this.setState({ claimSearchOptions: options, claimSearchRun: true }, () => claimSearch(options)); this.setState({ claimSearchOptions: options, claimSearchRun: true }, () => claimSearch(options));
} }
/* if (this.state.claimSearchRun && this.state.claimSearchOptions) {
const claimSearchKey = createNormalizedClaimSearchKey(this.state.claimSearchOptions);
const claimSearchUris = claimSearchByQuery[claimSearchKey];
this.setState({ showTagResult: claimSearchUris && claimSearchUris.length > 0 });
} */
return ( return (
<View> <View>
<FileListItem uri={currentUri} featuredResult style={searchStyle.featuredResultItem} navigation={navigation} /> <FileListItem uri={currentUri} featuredResult style={searchStyle.featuredResultItem} navigation={navigation} />
@ -216,7 +211,7 @@ class SearchPage extends React.PureComponent {
maxToRenderPerBatch={20} maxToRenderPerBatch={20}
removeClippedSubviews removeClippedSubviews
ListEmptyComponent={!isSearching ? this.listEmptyComponent() : null} ListEmptyComponent={!isSearching ? this.listEmptyComponent() : null}
ListHeaderComponent={this.state.currentUri ? this.listHeaderComponent(this.state.showTagResult) : null} ListHeaderComponent={this.listHeaderComponent(this.state.showTagResult, this.state.currentQuery)}
renderItem={({ item }) => ( renderItem={({ item }) => (
<FileResultItem key={item.claimId} result={item} style={searchStyle.resultItem} navigation={navigation} /> <FileResultItem key={item.claimId} result={item} style={searchStyle.resultItem} navigation={navigation} />
)} )}