remove references to desktop app navigation state

This commit is contained in:
Sean Yesmunt 2019-03-27 16:18:10 -04:00
parent 1f211d183d
commit 13d0cf01be
5 changed files with 438 additions and 715 deletions

937
dist/bundle.js vendored

File diff suppressed because it is too large Load diff

View file

@ -109,7 +109,6 @@ export {
makeSelectClaimForUri,
makeSelectClaimIsMine,
makeSelectFetchingChannelClaims,
makeSelectClaimsInChannelForCurrentPage,
makeSelectClaimsInChannelForPage,
makeSelectMetadataForUri,
makeSelectTitleForUri,
@ -168,26 +167,9 @@ export {
selectFileListPublishedSort,
} from 'redux/selectors/file_info';
export {
computePageFromPath,
makeSelectCurrentParam,
selectCurrentPath,
selectCurrentPage,
selectCurrentParams,
selectHeaderLinks,
selectPageTitle,
selectPathAfterAuth,
selectIsBackDisabled,
selectIsForwardDisabled,
selectHistoryIndex,
selectHistoryStack,
selectActiveHistoryEntry,
} from 'redux/selectors/navigation';
export { selectSearchState };
export {
makeSelectSearchUris,
selectSearchQuery,
selectSearchValue,
selectSearchOptions,
selectIsSearching,

View file

@ -7,7 +7,7 @@ import {
makeSelectSearchUris,
selectSuggestions,
makeSelectQueryWithOptions,
selectSearchQuery,
selectSearchValue,
} from 'redux/selectors/search';
import { batchActions } from 'util/batchActions';
import debounce from 'util/debounce';
@ -24,76 +24,6 @@ export const setSearchApi = (endpoint: string) => {
CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end;
};
export const doSearch = (
rawQuery: string, // pass in a query if you don't want to search for what's in the search bar
size: ?number, // only pass in if you don't want to use the users setting (ex: related content)
from: ?number,
isBackgroundSearch: boolean = false
) => (dispatch: Dispatch, getState: GetState) => {
const query = rawQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
if (!query) {
dispatch({
type: ACTIONS.SEARCH_FAIL,
});
return;
}
const state = getState();
const queryWithOptions = makeSelectQueryWithOptions(query, size, from, isBackgroundSearch)(state);
// If we have already searched for something, we don't need to do anything
const urisForQuery = makeSelectSearchUris(queryWithOptions)(state);
if (urisForQuery && !!urisForQuery.length) {
return;
}
dispatch({
type: ACTIONS.SEARCH_START,
});
// If the user is on the file page with a pre-populated uri and they select
// the search option without typing anything, searchQuery will be empty
// We need to populate it so the input is filled on the search page
// isBackgroundSearch means the search is happening in the background, don't update the search query
if (!state.search.searchQuery && !isBackgroundSearch) {
dispatch({
type: ACTIONS.UPDATE_SEARCH_QUERY,
data: { searchQuery: query },
});
}
fetch(`${CONNECTION_STRING}search?${queryWithOptions}`)
.then(handleFetchResponse)
.then(data => {
const uris = [];
const actions = [];
data.forEach(result => {
const uri = buildURI({
claimName: result.name,
claimId: result.claimId,
});
actions.push(doResolveUri(uri));
uris.push(uri);
});
actions.push({
type: ACTIONS.SEARCH_SUCCESS,
data: {
query: queryWithOptions,
uris,
},
});
dispatch(batchActions(...actions));
})
.catch(() => {
dispatch({
type: ACTIONS.SEARCH_FAIL,
});
});
};
export const getSearchSuggestions = (value: string) => (dispatch: Dispatch, getState: GetState) => {
const query = value.trim();
@ -145,6 +75,73 @@ export const doUpdateSearchQuery = (query: string, shouldSkipSuggestions: ?boole
}
};
export const doSearch = (
rawQuery: string, // pass in a query if you don't want to search for what's in the search bar
size: ?number, // only pass in if you don't want to use the users setting (ex: related content)
from: ?number,
isBackgroundSearch: boolean = false
) => (dispatch: Dispatch, getState: GetState) => {
const query = rawQuery.replace(/^lbry:\/\//i, '').replace(/\//, ' ');
if (!query) {
dispatch({
type: ACTIONS.SEARCH_FAIL,
});
return;
}
const state = getState();
const queryWithOptions = makeSelectQueryWithOptions(query, size, from, isBackgroundSearch)(state);
// If we have already searched for something, we don't need to do anything
const urisForQuery = makeSelectSearchUris(queryWithOptions)(state);
if (urisForQuery && !!urisForQuery.length) {
return;
}
dispatch({
type: ACTIONS.SEARCH_START,
});
// If the user is on the file page with a pre-populated uri and they select
// the search option without typing anything, searchQuery will be empty
// We need to populate it so the input is filled on the search page
// isBackgroundSearch means the search is happening in the background, don't update the search query
if (!state.search.searchQuery && !isBackgroundSearch) {
dispatch(doUpdateSearchQuery(query));
}
fetch(`${CONNECTION_STRING}search?${queryWithOptions}`)
.then(handleFetchResponse)
.then(data => {
const uris = [];
const actions = [];
data.forEach(result => {
const uri = buildURI({
claimName: result.name,
claimId: result.claimId,
});
actions.push(doResolveUri(uri));
uris.push(uri);
});
actions.push({
type: ACTIONS.SEARCH_SUCCESS,
data: {
query: queryWithOptions,
uris,
},
});
dispatch(batchActions(...actions));
})
.catch(() => {
dispatch({
type: ACTIONS.SEARCH_FAIL,
});
});
};
export const doFocusSearchInput = () => (dispatch: Dispatch) =>
dispatch({
type: ACTIONS.SEARCH_FOCUS,
@ -160,15 +157,15 @@ export const doUpdateSearchOptions = (newOptions: SearchOptions) => (
getState: GetState
) => {
const state = getState();
const searchQuery = selectSearchQuery(state);
const searchValue = selectSearchValue(state);
dispatch({
type: ACTIONS.UPDATE_SEARCH_OPTIONS,
data: newOptions,
});
if (searchQuery) {
if (searchValue) {
// After updating, perform a search with the new options
dispatch(doSearch(searchQuery));
dispatch(doSearch(searchValue));
}
};

View file

@ -1,5 +1,4 @@
import { normalizeURI, buildURI, parseURI } from 'lbryURI';
import { makeSelectCurrentParam } from 'redux/selectors/navigation';
import { selectSearchUrisByQuery } from 'redux/selectors/search';
import { createSelector } from 'reselect';
import { isClaimNsfw } from 'util/claim';
@ -116,24 +115,6 @@ export const makeSelectClaimsInChannelForPage = (uri, page) =>
return claimIds.map(claimId => byId[claimId]);
});
export const makeSelectClaimsInChannelForCurrentPage = uri => {
const pageSelector = makeSelectCurrentParam('page');
return createSelector(
selectClaimsById,
selectAllClaimsByChannel,
pageSelector,
(byId, allClaims, page) => {
const byChannel = allClaims[uri] || {};
const claimIds = byChannel[page || 1];
if (!claimIds) return claimIds;
return claimIds.map(claimId => byId[claimId]);
}
);
};
export const makeSelectClaimsInChannelForCurrentPageState = uri =>
createSelector(
selectClaimsById,
@ -264,13 +245,11 @@ export const makeSelectNsfwCountFromUris = uris =>
}, 0)
);
export const makeSelectNsfwCountForChannel = uri => {
const pageSelector = makeSelectCurrentParam('page');
return createSelector(
export const makeSelectNsfwCountForChannel = uri =>
createSelector(
selectClaimsById,
selectAllClaimsByChannel,
pageSelector,
selectCurrentChannelPage,
(byId, allClaims, page) => {
const byChannel = allClaims[uri] || {};
const claimIds = byChannel[page || 1];
@ -286,7 +265,6 @@ export const makeSelectNsfwCountForChannel = uri => {
}, 0);
}
);
};
export const makeSelectRecommendedContentForUri = uri =>
createSelector(

View file

@ -3,7 +3,6 @@ import type { SearchState, SearchOptions, SearchSuggestion } from 'types/Search'
import { SEARCH_TYPES, SEARCH_OPTIONS } from 'constants/search';
import { getSearchQueryString } from 'util/query_params';
import { normalizeURI, parseURI } from 'lbryURI';
import { selectCurrentPage, selectCurrentParams } from 'redux/selectors/navigation';
import { createSelector } from 'reselect';
type State = { search: SearchState };
@ -27,14 +26,6 @@ export const selectSuggestions: (
state => state.suggestions
);
export const selectSearchQuery: (state: State) => ?string = createSelector(
selectCurrentPage,
selectCurrentParams,
selectSearchValue,
(page: string, params: ?{ query: string }, searchValue: string) =>
page === 'search' ? params && params.query : searchValue
);
export const selectIsSearching: (state: State) => boolean = createSelector(
selectState,
state => state.searching
@ -51,20 +42,6 @@ export const makeSelectSearchUris = (query: string): ((state: State) => Array<st
byQuery => byQuery[query ? query.replace(/^lbry:\/\//i, '').replace(/\//, ' ') : query]
);
export const selectWunderBarAddress = createSelector(
selectCurrentPage,
selectSearchQuery,
selectCurrentParams,
(page: string, query: string, params: { uri: string }) => {
// only populate the wunderbar address if we are on the file/channel pages
// or show the search query
if (page === 'show') {
return params.uri;
}
return query;
}
);
export const selectSearchBarFocused: boolean = createSelector(selectState, state => state.focused);
export const selectSearchSuggestions: Array<SearchSuggestion> = createSelector(
@ -150,7 +127,7 @@ export const makeSelectQueryWithOptions = (
customFrom: ?number,
isBackgroundSearch: boolean = false // If it's a background search, don't use the users settings
) =>
createSelector(selectSearchQuery, selectSearchOptions, (query, options) => {
createSelector(selectSearchValue, selectSearchOptions, (query, options) => {
const size = customSize || options[SEARCH_OPTIONS.RESULT_COUNT];
const queryString = getSearchQueryString(