RC #72

Merged
akinwale merged 5 commits from rc into master 2019-10-30 10:35:43 +01:00
2 changed files with 38 additions and 8 deletions
Showing only changes of commit e496388b8f - Show all commits

View file

@ -1,8 +1,10 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import {
doClaimSearch,
doSearch, doSearch,
doUpdateSearchQuery, doUpdateSearchQuery,
makeSelectSearchUris, makeSelectSearchUris,
selectClaimSearchByQuery,
selectIsSearching, selectIsSearching,
selectSearchValue, selectSearchValue,
makeSelectQueryWithOptions, makeSelectQueryWithOptions,
@ -13,9 +15,10 @@ import { selectCurrentRoute } from 'redux/selectors/drawer';
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
import SearchPage from './view'; import SearchPage from './view';
const numSearchResults = 50; const numSearchResults = 25;
const select = state => ({ const select = state => ({
claimSearchByQuery: selectClaimSearchByQuery(state),
currentRoute: selectCurrentRoute(state), currentRoute: selectCurrentRoute(state),
isSearching: selectIsSearching(state), isSearching: selectIsSearching(state),
query: selectSearchValue(state), query: selectSearchValue(state),
@ -25,6 +28,7 @@ const select = state => ({
const perform = dispatch => ({ const perform = dispatch => ({
search: query => dispatch(doSearch(query, numSearchResults)), search: query => dispatch(doSearch(query, numSearchResults)),
claimSearch: options => dispatch(doClaimSearch(options)),
updateSearchQuery: query => dispatch(doUpdateSearchQuery(query)), updateSearchQuery: query => dispatch(doUpdateSearchQuery(query)),
pushDrawerStack: () => dispatch(doPushDrawerStack(Constants.DRAWER_ROUTE_SEARCH)), pushDrawerStack: () => dispatch(doPushDrawerStack(Constants.DRAWER_ROUTE_SEARCH)),
setPlayerVisible: () => dispatch(doSetPlayerVisible(false)), setPlayerVisible: () => dispatch(doSetPlayerVisible(false)),

View file

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { Lbry, parseURI, normalizeURI, isURIValid } from 'lbry-redux'; import { Lbry, createNormalizedClaimSearchKey, parseURI, normalizeURI, isURIValid } from 'lbry-redux';
import { import {
ActivityIndicator, ActivityIndicator,
Button, Button,
@ -23,6 +23,9 @@ class SearchPage extends React.PureComponent {
state = { state = {
currentQuery: null, currentQuery: null,
currentUri: null, currentUri: null,
showTagResult: false,
claimSearchRun: false,
claimSearchOptions: null,
}; };
static navigationOptions = { static navigationOptions = {
@ -52,6 +55,9 @@ class SearchPage extends React.PureComponent {
this.setState({ this.setState({
currentQuery: searchQuery, currentQuery: searchQuery,
currentUri: isURIValid(searchQuery) ? normalizeURI(searchQuery) : null, currentUri: isURIValid(searchQuery) ? normalizeURI(searchQuery) : null,
claimSearchOptions: null,
claimSearchRun: false,
showTagResult: false,
}); });
search(searchQuery); search(searchQuery);
} }
@ -89,7 +95,12 @@ class SearchPage extends React.PureComponent {
handleSearchSubmitted = keywords => { handleSearchSubmitted = keywords => {
const { search } = this.props; const { search } = this.props;
this.setState({ currentUri: isURIValid(keywords) ? normalizeURI(keywords) : null }); this.setState({
currentUri: isURIValid(keywords) ? normalizeURI(keywords) : null,
claimSearchOptions: null,
claimSearchRun: false,
showTagResult: false,
});
search(keywords); search(keywords);
}; };
@ -105,13 +116,27 @@ class SearchPage extends React.PureComponent {
); );
}; };
listHeaderComponent = () => { listHeaderComponent = showTagResult => {
const { navigation } = this.props; const { navigation, claimSearch, claimSearchByQuery } = this.props;
const { currentUri } = this.state; const { currentUri } = this.state;
const query = this.getSearchQuery(); const query = this.getSearchQuery();
// TODO: Do a claim_search to see if the tag has any content const canBeTag = query && query.trim().length > 0 && isURIValid(query);
const showTagResult = query && query.trim().length > 0 && isURIValid(query); if (canBeTag && !this.state.claimSearchRun) {
const options = {
any_tags: [query],
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 ( return (
<View> <View>
<FileListItem uri={currentUri} featuredResult style={searchStyle.featuredResultItem} navigation={navigation} /> <FileListItem uri={currentUri} featuredResult style={searchStyle.featuredResultItem} navigation={navigation} />
@ -144,6 +169,7 @@ class SearchPage extends React.PureComponent {
)} )}
<FlatList <FlatList
extraData={this.state}
style={searchStyle.scrollContainer} style={searchStyle.scrollContainer}
contentContainerStyle={searchStyle.scrollPadding} contentContainerStyle={searchStyle.scrollPadding}
keyboardShouldPersistTaps={'handled'} keyboardShouldPersistTaps={'handled'}
@ -153,7 +179,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() : null} ListHeaderComponent={this.state.currentUri ? this.listHeaderComponent(this.state.showTagResult) : null}
renderItem={({ item }) => ( renderItem={({ item }) => (
<FileListItem key={item} uri={item} style={searchStyle.resultItem} navigation={navigation} /> <FileListItem key={item} uri={item} style={searchStyle.resultItem} navigation={navigation} />
)} )}