Merge pull request #124 from lbryio/routing
Remove references to desktop app navigation state
This commit is contained in:
commit
eaf8be6e3a
5 changed files with 438 additions and 715 deletions
937
dist/bundle.js
vendored
937
dist/bundle.js
vendored
File diff suppressed because it is too large
Load diff
18
src/index.js
18
src/index.js
|
@ -109,7 +109,6 @@ export {
|
||||||
makeSelectClaimForUri,
|
makeSelectClaimForUri,
|
||||||
makeSelectClaimIsMine,
|
makeSelectClaimIsMine,
|
||||||
makeSelectFetchingChannelClaims,
|
makeSelectFetchingChannelClaims,
|
||||||
makeSelectClaimsInChannelForCurrentPage,
|
|
||||||
makeSelectClaimsInChannelForPage,
|
makeSelectClaimsInChannelForPage,
|
||||||
makeSelectMetadataForUri,
|
makeSelectMetadataForUri,
|
||||||
makeSelectTitleForUri,
|
makeSelectTitleForUri,
|
||||||
|
@ -168,26 +167,9 @@ export {
|
||||||
selectFileListPublishedSort,
|
selectFileListPublishedSort,
|
||||||
} from 'redux/selectors/file_info';
|
} 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 { selectSearchState };
|
||||||
export {
|
export {
|
||||||
makeSelectSearchUris,
|
makeSelectSearchUris,
|
||||||
selectSearchQuery,
|
|
||||||
selectSearchValue,
|
selectSearchValue,
|
||||||
selectSearchOptions,
|
selectSearchOptions,
|
||||||
selectIsSearching,
|
selectIsSearching,
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
makeSelectSearchUris,
|
makeSelectSearchUris,
|
||||||
selectSuggestions,
|
selectSuggestions,
|
||||||
makeSelectQueryWithOptions,
|
makeSelectQueryWithOptions,
|
||||||
selectSearchQuery,
|
selectSearchValue,
|
||||||
} from 'redux/selectors/search';
|
} from 'redux/selectors/search';
|
||||||
import { batchActions } from 'util/batchActions';
|
import { batchActions } from 'util/batchActions';
|
||||||
import debounce from 'util/debounce';
|
import debounce from 'util/debounce';
|
||||||
|
@ -24,76 +24,6 @@ export const setSearchApi = (endpoint: string) => {
|
||||||
CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end;
|
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) => {
|
export const getSearchSuggestions = (value: string) => (dispatch: Dispatch, getState: GetState) => {
|
||||||
const query = value.trim();
|
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) =>
|
export const doFocusSearchInput = () => (dispatch: Dispatch) =>
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.SEARCH_FOCUS,
|
type: ACTIONS.SEARCH_FOCUS,
|
||||||
|
@ -160,15 +157,15 @@ export const doUpdateSearchOptions = (newOptions: SearchOptions) => (
|
||||||
getState: GetState
|
getState: GetState
|
||||||
) => {
|
) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const searchQuery = selectSearchQuery(state);
|
const searchValue = selectSearchValue(state);
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.UPDATE_SEARCH_OPTIONS,
|
type: ACTIONS.UPDATE_SEARCH_OPTIONS,
|
||||||
data: newOptions,
|
data: newOptions,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (searchQuery) {
|
if (searchValue) {
|
||||||
// After updating, perform a search with the new options
|
// After updating, perform a search with the new options
|
||||||
dispatch(doSearch(searchQuery));
|
dispatch(doSearch(searchValue));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { normalizeURI, buildURI, parseURI } from 'lbryURI';
|
import { normalizeURI, buildURI, parseURI } from 'lbryURI';
|
||||||
import { makeSelectCurrentParam } from 'redux/selectors/navigation';
|
|
||||||
import { selectSearchUrisByQuery } from 'redux/selectors/search';
|
import { selectSearchUrisByQuery } from 'redux/selectors/search';
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import { isClaimNsfw } from 'util/claim';
|
import { isClaimNsfw } from 'util/claim';
|
||||||
|
@ -116,24 +115,6 @@ export const makeSelectClaimsInChannelForPage = (uri, page) =>
|
||||||
return claimIds.map(claimId => byId[claimId]);
|
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 =>
|
export const makeSelectClaimsInChannelForCurrentPageState = uri =>
|
||||||
createSelector(
|
createSelector(
|
||||||
selectClaimsById,
|
selectClaimsById,
|
||||||
|
@ -264,13 +245,11 @@ export const makeSelectNsfwCountFromUris = uris =>
|
||||||
}, 0)
|
}, 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
export const makeSelectNsfwCountForChannel = uri => {
|
export const makeSelectNsfwCountForChannel = uri =>
|
||||||
const pageSelector = makeSelectCurrentParam('page');
|
createSelector(
|
||||||
|
|
||||||
return createSelector(
|
|
||||||
selectClaimsById,
|
selectClaimsById,
|
||||||
selectAllClaimsByChannel,
|
selectAllClaimsByChannel,
|
||||||
pageSelector,
|
selectCurrentChannelPage,
|
||||||
(byId, allClaims, page) => {
|
(byId, allClaims, page) => {
|
||||||
const byChannel = allClaims[uri] || {};
|
const byChannel = allClaims[uri] || {};
|
||||||
const claimIds = byChannel[page || 1];
|
const claimIds = byChannel[page || 1];
|
||||||
|
@ -286,7 +265,6 @@ export const makeSelectNsfwCountForChannel = uri => {
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
export const makeSelectRecommendedContentForUri = uri =>
|
export const makeSelectRecommendedContentForUri = uri =>
|
||||||
createSelector(
|
createSelector(
|
||||||
|
|
|
@ -3,7 +3,6 @@ import type { SearchState, SearchOptions, SearchSuggestion } from 'types/Search'
|
||||||
import { SEARCH_TYPES, SEARCH_OPTIONS } from 'constants/search';
|
import { SEARCH_TYPES, SEARCH_OPTIONS } from 'constants/search';
|
||||||
import { getSearchQueryString } from 'util/query_params';
|
import { getSearchQueryString } from 'util/query_params';
|
||||||
import { normalizeURI, parseURI } from 'lbryURI';
|
import { normalizeURI, parseURI } from 'lbryURI';
|
||||||
import { selectCurrentPage, selectCurrentParams } from 'redux/selectors/navigation';
|
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
|
|
||||||
type State = { search: SearchState };
|
type State = { search: SearchState };
|
||||||
|
@ -27,14 +26,6 @@ export const selectSuggestions: (
|
||||||
state => state.suggestions
|
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(
|
export const selectIsSearching: (state: State) => boolean = createSelector(
|
||||||
selectState,
|
selectState,
|
||||||
state => state.searching
|
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]
|
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 selectSearchBarFocused: boolean = createSelector(selectState, state => state.focused);
|
||||||
|
|
||||||
export const selectSearchSuggestions: Array<SearchSuggestion> = createSelector(
|
export const selectSearchSuggestions: Array<SearchSuggestion> = createSelector(
|
||||||
|
@ -150,7 +127,7 @@ export const makeSelectQueryWithOptions = (
|
||||||
customFrom: ?number,
|
customFrom: ?number,
|
||||||
isBackgroundSearch: boolean = false // If it's a background search, don't use the users settings
|
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 size = customSize || options[SEARCH_OPTIONS.RESULT_COUNT];
|
||||||
|
|
||||||
const queryString = getSearchQueryString(
|
const queryString = getSearchQueryString(
|
||||||
|
|
Loading…
Add table
Reference in a new issue