support multiple simultaneous claim_search requests
This commit is contained in:
parent
0ff6364a40
commit
b59fdfa1d8
6 changed files with 192 additions and 0 deletions
89
dist/bundle.es.js
vendored
89
dist/bundle.es.js
vendored
|
@ -117,6 +117,9 @@ const CLEAR_CONTENT_HISTORY_ALL = 'CLEAR_CONTENT_HISTORY_ALL';
|
|||
const CLAIM_SEARCH_STARTED = 'CLAIM_SEARCH_STARTED';
|
||||
const CLAIM_SEARCH_COMPLETED = 'CLAIM_SEARCH_COMPLETED';
|
||||
const CLAIM_SEARCH_FAILED = 'CLAIM_SEARCH_FAILED';
|
||||
const CLAIM_SEARCH_BY_TAGS_STARTED = 'CLAIM_SEARCH_BY_TAGS_STARTED';
|
||||
const CLAIM_SEARCH_BY_TAGS_COMPLETED = 'CLAIM_SEARCH_BY_TAGS_COMPLETED';
|
||||
const CLAIM_SEARCH_BY_TAGS_FAILED = 'CLAIM_SEARCH_BY_TAGS_FAILED';
|
||||
|
||||
// Comments
|
||||
const COMMENT_LIST_STARTED = 'COMMENT_LIST_STARTED';
|
||||
|
@ -345,6 +348,9 @@ var action_types = /*#__PURE__*/Object.freeze({
|
|||
CLAIM_SEARCH_STARTED: CLAIM_SEARCH_STARTED,
|
||||
CLAIM_SEARCH_COMPLETED: CLAIM_SEARCH_COMPLETED,
|
||||
CLAIM_SEARCH_FAILED: CLAIM_SEARCH_FAILED,
|
||||
CLAIM_SEARCH_BY_TAGS_STARTED: CLAIM_SEARCH_BY_TAGS_STARTED,
|
||||
CLAIM_SEARCH_BY_TAGS_COMPLETED: CLAIM_SEARCH_BY_TAGS_COMPLETED,
|
||||
CLAIM_SEARCH_BY_TAGS_FAILED: CLAIM_SEARCH_BY_TAGS_FAILED,
|
||||
COMMENT_LIST_STARTED: COMMENT_LIST_STARTED,
|
||||
COMMENT_LIST_COMPLETED: COMMENT_LIST_COMPLETED,
|
||||
COMMENT_LIST_FAILED: COMMENT_LIST_FAILED,
|
||||
|
@ -1511,6 +1517,14 @@ const selectLastClaimSearchUris = reselect.createSelector(selectState$1, state =
|
|||
|
||||
const makeSelectShortUrlForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => claim && claim.short_url);
|
||||
|
||||
const selectFetchingClaimSearchByTags = reselect.createSelector(selectState$1, state => state.fetchingClaimSearchByTags);
|
||||
|
||||
const selectClaimSearchUrisByTags = reselect.createSelector(selectState$1, state => state.claimSearchUrisByTags);
|
||||
|
||||
const makeSelectFetchingClaimSearchForTags = tags => reselect.createSelector(selectFetchingClaimSearchByTags, byTags => byTags[tags]);
|
||||
|
||||
const makeSelectClaimSearchUrisForTags = tags => reselect.createSelector(selectClaimSearchUrisByTags, byTags => byTags[tags]);
|
||||
|
||||
const selectState$2 = state => state.wallet || {};
|
||||
|
||||
const selectWalletState = selectState$2;
|
||||
|
@ -2336,6 +2350,43 @@ function doClaimSearch(amount = 20, options = {}) {
|
|||
};
|
||||
}
|
||||
|
||||
// tags can be one or many (comma separated)
|
||||
function doClaimSearchByTags(tags, amount = 10, options = {}) {
|
||||
return dispatch => {
|
||||
const tagList = tags.join(',');
|
||||
dispatch({
|
||||
type: CLAIM_SEARCH_BY_TAGS_STARTED,
|
||||
data: { tags: tagList }
|
||||
});
|
||||
|
||||
const success = data => {
|
||||
const resolveInfo = {};
|
||||
const uris = [];
|
||||
data.items.forEach(stream => {
|
||||
resolveInfo[stream.permanent_url] = { stream };
|
||||
uris.push(stream.permanent_url);
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: CLAIM_SEARCH_BY_TAGS_COMPLETED,
|
||||
data: { tags: tagList, resolveInfo, uris, append: options.page && options.page !== 1 }
|
||||
});
|
||||
};
|
||||
|
||||
const failure = err => {
|
||||
dispatch({
|
||||
type: CLAIM_SEARCH_BY_TAGS_FAILED,
|
||||
data: { tags: tagList },
|
||||
error: err
|
||||
});
|
||||
};
|
||||
|
||||
lbryProxy.claim_search(_extends$3({
|
||||
page_size: amount
|
||||
}, options)).then(success, failure);
|
||||
};
|
||||
}
|
||||
|
||||
const selectState$3 = state => state.fileInfo || {};
|
||||
|
||||
const selectFileInfosByOutpoint = reselect.createSelector(selectState$3, state => state.byOutpoint || {});
|
||||
|
@ -3332,6 +3383,8 @@ const defaultState = {
|
|||
abandoningById: {},
|
||||
pendingById: {},
|
||||
fetchingClaimSearch: false,
|
||||
claimSearchUrisByTags: [],
|
||||
fetchingClaimSearchByTags: [],
|
||||
lastClaimSearchUris: []
|
||||
};
|
||||
|
||||
|
@ -3587,6 +3640,37 @@ reducers[CLAIM_SEARCH_FAILED] = state => {
|
|||
});
|
||||
};
|
||||
|
||||
reducers[CLAIM_SEARCH_BY_TAGS_STARTED] = (state, action) => {
|
||||
const fetchingClaimSearchByTags = Object.assign({}, state.fetchingClaimSearchByTags);
|
||||
fetchingClaimSearchByTags[action.data.tags] = true;
|
||||
|
||||
return Object.assign({}, state, {
|
||||
fetchingClaimSearchByTags
|
||||
});
|
||||
};
|
||||
reducers[CLAIM_SEARCH_BY_TAGS_COMPLETED] = (state, action) => {
|
||||
const fetchingClaimSearchByTags = Object.assign({}, state.fetchingClaimSearchByTags);
|
||||
const claimSearchUrisByTags = Object.assign({}, state.claimSearchUrisByTags);
|
||||
const { tags, uris } = action.data;
|
||||
|
||||
// TODO: append?
|
||||
claimSearchUrisByTags[tags] = uris;
|
||||
fetchingClaimSearchByTags[tags] = false; // or delete the key instead?
|
||||
|
||||
return Object.assign({}, state, {
|
||||
claimSearchUrisByTags,
|
||||
fetchingClaimSearchByTags
|
||||
});
|
||||
};
|
||||
reducers[CLAIM_SEARCH_BY_TAGS_FAILED] = (state, action) => {
|
||||
const fetchingClaimSearchByTags = Object.assign({}, state.fetchingClaimSearchByTags);
|
||||
fetchingClaimSearchByTags[action.data.tags] = false;
|
||||
|
||||
return Object.assign({}, state, {
|
||||
fetchingClaimSearchByTags
|
||||
});
|
||||
};
|
||||
|
||||
function claimsReducer(state = defaultState, action) {
|
||||
const handler = reducers[action.type];
|
||||
if (handler) return handler(state, action);
|
||||
|
@ -4664,6 +4748,7 @@ exports.doBlurSearchInput = doBlurSearchInput;
|
|||
exports.doCheckAddressIsMine = doCheckAddressIsMine;
|
||||
exports.doCheckPendingPublishes = doCheckPendingPublishes;
|
||||
exports.doClaimSearch = doClaimSearch;
|
||||
exports.doClaimSearchByTags = doClaimSearchByTags;
|
||||
exports.doClearPublish = doClearPublish;
|
||||
exports.doCommentCreate = doCommentCreate;
|
||||
exports.doCommentList = doCommentList;
|
||||
|
@ -4725,6 +4810,7 @@ exports.makeSelectClaimForUri = makeSelectClaimForUri;
|
|||
exports.makeSelectClaimIsMine = makeSelectClaimIsMine;
|
||||
exports.makeSelectClaimIsNsfw = makeSelectClaimIsNsfw;
|
||||
exports.makeSelectClaimIsPending = makeSelectClaimIsPending;
|
||||
exports.makeSelectClaimSearchUrisForTags = makeSelectClaimSearchUrisForTags;
|
||||
exports.makeSelectClaimsInChannelForCurrentPageState = makeSelectClaimsInChannelForCurrentPageState;
|
||||
exports.makeSelectClaimsInChannelForPage = makeSelectClaimsInChannelForPage;
|
||||
exports.makeSelectCommentsForUri = makeSelectCommentsForUri;
|
||||
|
@ -4734,6 +4820,7 @@ exports.makeSelectCoverForUri = makeSelectCoverForUri;
|
|||
exports.makeSelectDateForUri = makeSelectDateForUri;
|
||||
exports.makeSelectDownloadingForUri = makeSelectDownloadingForUri;
|
||||
exports.makeSelectFetchingChannelClaims = makeSelectFetchingChannelClaims;
|
||||
exports.makeSelectFetchingClaimSearchForTags = makeSelectFetchingClaimSearchForTags;
|
||||
exports.makeSelectFileInfoForUri = makeSelectFileInfoForUri;
|
||||
exports.makeSelectFirstRecommendedFileForUri = makeSelectFirstRecommendedFileForUri;
|
||||
exports.makeSelectIsUriResolving = makeSelectIsUriResolving;
|
||||
|
@ -4769,6 +4856,7 @@ exports.selectAllMyClaimsByOutpoint = selectAllMyClaimsByOutpoint;
|
|||
exports.selectBalance = selectBalance;
|
||||
exports.selectBlocks = selectBlocks;
|
||||
exports.selectChannelClaimCounts = selectChannelClaimCounts;
|
||||
exports.selectClaimSearchUrisByTags = selectClaimSearchUrisByTags;
|
||||
exports.selectClaimsById = selectClaimsById;
|
||||
exports.selectClaimsByUri = selectClaimsByUri;
|
||||
exports.selectCurrentChannelPage = selectCurrentChannelPage;
|
||||
|
@ -4782,6 +4870,7 @@ exports.selectDraftTransactionError = selectDraftTransactionError;
|
|||
exports.selectError = selectError;
|
||||
exports.selectFailedPurchaseUris = selectFailedPurchaseUris;
|
||||
exports.selectFetchingClaimSearch = selectFetchingClaimSearch;
|
||||
exports.selectFetchingClaimSearchByTags = selectFetchingClaimSearchByTags;
|
||||
exports.selectFetchingMyChannels = selectFetchingMyChannels;
|
||||
exports.selectFileInfosByOutpoint = selectFileInfosByOutpoint;
|
||||
exports.selectFileInfosDownloaded = selectFileInfosDownloaded;
|
||||
|
|
|
@ -94,6 +94,9 @@ export const CLEAR_CONTENT_HISTORY_ALL = 'CLEAR_CONTENT_HISTORY_ALL';
|
|||
export const CLAIM_SEARCH_STARTED = 'CLAIM_SEARCH_STARTED';
|
||||
export const CLAIM_SEARCH_COMPLETED = 'CLAIM_SEARCH_COMPLETED';
|
||||
export const CLAIM_SEARCH_FAILED = 'CLAIM_SEARCH_FAILED';
|
||||
export const CLAIM_SEARCH_BY_TAGS_STARTED = 'CLAIM_SEARCH_BY_TAGS_STARTED';
|
||||
export const CLAIM_SEARCH_BY_TAGS_COMPLETED = 'CLAIM_SEARCH_BY_TAGS_COMPLETED';
|
||||
export const CLAIM_SEARCH_BY_TAGS_FAILED = 'CLAIM_SEARCH_BY_TAGS_FAILED';
|
||||
|
||||
// Comments
|
||||
export const COMMENT_LIST_STARTED = 'COMMENT_LIST_STARTED';
|
||||
|
|
|
@ -55,6 +55,7 @@ export {
|
|||
doCreateChannel,
|
||||
doUpdateChannel,
|
||||
doClaimSearch,
|
||||
doClaimSearchByTags,
|
||||
} from 'redux/actions/claims';
|
||||
|
||||
export { doDeletePurchasedUri, doPurchaseUri, doFileGet } from 'redux/actions/file';
|
||||
|
@ -193,6 +194,10 @@ export {
|
|||
selectCurrentChannelPage,
|
||||
selectFetchingClaimSearch,
|
||||
selectLastClaimSearchUris,
|
||||
selectFetchingClaimSearchByTags,
|
||||
selectClaimSearchUrisByTags,
|
||||
makeSelectFetchingClaimSearchForTags,
|
||||
makeSelectClaimSearchUrisForTags,
|
||||
} from 'redux/selectors/claims';
|
||||
|
||||
export { makeSelectCommentsForUri } from 'redux/selectors/comments';
|
||||
|
|
|
@ -332,3 +332,41 @@ export function doClaimSearch(amount: number = 20, options: { page?: number } =
|
|||
}).then(success, failure);
|
||||
};
|
||||
}
|
||||
|
||||
// tags can be one or many (comma separated)
|
||||
export function doClaimSearchByTags(tags: Array<string>, amount: number = 10, options: { page?: number } = {}) {
|
||||
return (dispatch: Dispatch) => {
|
||||
const tagList = tags.join(',');
|
||||
dispatch({
|
||||
type: ACTIONS.CLAIM_SEARCH_BY_TAGS_STARTED,
|
||||
data: { tags: tagList },
|
||||
});
|
||||
|
||||
const success = (data: ClaimSearchResponse) => {
|
||||
const resolveInfo = {};
|
||||
const uris = [];
|
||||
data.items.forEach((stream: Claim) => {
|
||||
resolveInfo[stream.permanent_url] = { stream };
|
||||
uris.push(stream.permanent_url);
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: ACTIONS.CLAIM_SEARCH_BY_TAGS_COMPLETED,
|
||||
data: { tags: tagList, resolveInfo, uris, append: options.page && options.page !== 1 },
|
||||
});
|
||||
};
|
||||
|
||||
const failure = err => {
|
||||
dispatch({
|
||||
type: ACTIONS.CLAIM_SEARCH_BY_TAGS_FAILED,
|
||||
data: { tags: tagList },
|
||||
error: err,
|
||||
});
|
||||
};
|
||||
|
||||
Lbry.claim_search({
|
||||
page_size: amount,
|
||||
...options,
|
||||
}).then(success, failure);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ type State = {
|
|||
fetchingChannelClaims: { [string]: number },
|
||||
fetchingMyChannels: boolean,
|
||||
lastClaimSearchUris: Array<string>,
|
||||
fetchingClaimSearchByTags: { [string]: boolean },
|
||||
claimSearchUrisByTags: { [string]: { all: Array<string> } },
|
||||
claimsByChannel: {
|
||||
[string]: {
|
||||
all: Array<string>,
|
||||
|
@ -45,6 +47,8 @@ const defaultState = {
|
|||
abandoningById: {},
|
||||
pendingById: {},
|
||||
fetchingClaimSearch: false,
|
||||
claimSearchUrisByTags: [],
|
||||
fetchingClaimSearchByTags: [],
|
||||
lastClaimSearchUris: [],
|
||||
};
|
||||
|
||||
|
@ -312,6 +316,37 @@ reducers[ACTIONS.CLAIM_SEARCH_FAILED] = (state: State): State => {
|
|||
});
|
||||
};
|
||||
|
||||
reducers[ACTIONS.CLAIM_SEARCH_BY_TAGS_STARTED] = (state: State, action: any): State => {
|
||||
const fetchingClaimSearchByTags = Object.assign({}, state.fetchingClaimSearchByTags);
|
||||
fetchingClaimSearchByTags[action.data.tags] = true;
|
||||
|
||||
return Object.assign({}, state, {
|
||||
fetchingClaimSearchByTags
|
||||
});
|
||||
};
|
||||
reducers[ACTIONS.CLAIM_SEARCH_BY_TAGS_COMPLETED] = (state: State, action: any): State => {
|
||||
const fetchingClaimSearchByTags = Object.assign({}, state.fetchingClaimSearchByTags);
|
||||
const claimSearchUrisByTags = Object.assign({}, state.claimSearchUrisByTags);
|
||||
const { tags, uris } = action.data;
|
||||
|
||||
// TODO: append?
|
||||
claimSearchUrisByTags[tags] = uris;
|
||||
fetchingClaimSearchByTags[tags] = false; // or delete the key instead?
|
||||
|
||||
return Object.assign({}, state, {
|
||||
claimSearchUrisByTags,
|
||||
fetchingClaimSearchByTags,
|
||||
});
|
||||
};
|
||||
reducers[ACTIONS.CLAIM_SEARCH_BY_TAGS_FAILED] = (state: State, action: any): State => {
|
||||
const fetchingClaimSearchByTags = Object.assign({}, state.fetchingClaimSearchByTags);
|
||||
fetchingClaimSearchByTags[action.data.tags] = false;
|
||||
|
||||
return Object.assign({}, state, {
|
||||
fetchingClaimSearchByTags,
|
||||
});
|
||||
};
|
||||
|
||||
export function claimsReducer(state: State = defaultState, action: any) {
|
||||
const handler = reducers[action.type];
|
||||
if (handler) return handler(state, action);
|
||||
|
|
|
@ -484,3 +484,25 @@ export const makeSelectShortUrlForUri = (uri: string) =>
|
|||
makeSelectClaimForUri(uri),
|
||||
claim => claim && claim.short_url
|
||||
);
|
||||
|
||||
export const selectFetchingClaimSearchByTags = createSelector(
|
||||
selectState,
|
||||
state => state.fetchingClaimSearchByTags
|
||||
);
|
||||
|
||||
export const selectClaimSearchUrisByTags = createSelector(
|
||||
selectState,
|
||||
state => state.claimSearchUrisByTags
|
||||
);
|
||||
|
||||
export const makeSelectFetchingClaimSearchForTags = (tags: string) =>
|
||||
createSelector(
|
||||
selectFetchingClaimSearchByTags,
|
||||
byTags => byTags[tags]
|
||||
);
|
||||
|
||||
export const makeSelectClaimSearchUrisForTags = (tags: string) =>
|
||||
createSelector(
|
||||
selectClaimSearchUrisByTags,
|
||||
byTags => byTags[tags]
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue