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

View file

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