Merge pull request #165 from lbryio/multi-claim-search
support multiple simultaneous claim_search requests
This commit is contained in:
commit
cd23c12fb7
8 changed files with 217 additions and 5 deletions
dist
src
102
dist/bundle.es.js
vendored
102
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_STARTED = 'CLAIM_SEARCH_STARTED';
|
||||||
const CLAIM_SEARCH_COMPLETED = 'CLAIM_SEARCH_COMPLETED';
|
const CLAIM_SEARCH_COMPLETED = 'CLAIM_SEARCH_COMPLETED';
|
||||||
const CLAIM_SEARCH_FAILED = 'CLAIM_SEARCH_FAILED';
|
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
|
// Comments
|
||||||
const COMMENT_LIST_STARTED = 'COMMENT_LIST_STARTED';
|
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_STARTED: CLAIM_SEARCH_STARTED,
|
||||||
CLAIM_SEARCH_COMPLETED: CLAIM_SEARCH_COMPLETED,
|
CLAIM_SEARCH_COMPLETED: CLAIM_SEARCH_COMPLETED,
|
||||||
CLAIM_SEARCH_FAILED: CLAIM_SEARCH_FAILED,
|
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_STARTED: COMMENT_LIST_STARTED,
|
||||||
COMMENT_LIST_COMPLETED: COMMENT_LIST_COMPLETED,
|
COMMENT_LIST_COMPLETED: COMMENT_LIST_COMPLETED,
|
||||||
COMMENT_LIST_FAILED: COMMENT_LIST_FAILED,
|
COMMENT_LIST_FAILED: COMMENT_LIST_FAILED,
|
||||||
|
@ -1242,6 +1248,10 @@ const isClaimNsfw = claim => {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const createNormalizedTagKey = tags => {
|
||||||
|
return tags ? tags.sort().join(',') : '';
|
||||||
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
const selectState$1 = state => state.claims || {};
|
const selectState$1 = state => state.claims || {};
|
||||||
|
@ -1388,7 +1398,7 @@ const makeSelectContentTypeForUri = uri => reselect.createSelector(makeSelectCla
|
||||||
|
|
||||||
const makeSelectThumbnailForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => {
|
const makeSelectThumbnailForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => {
|
||||||
const thumbnail = claim && claim.value && claim.value.thumbnail;
|
const thumbnail = claim && claim.value && claim.value.thumbnail;
|
||||||
return thumbnail ? thumbnail.url : undefined;
|
return thumbnail && thumbnail.url && thumbnail.url.trim().length > 0 ? thumbnail.url : undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
const makeSelectCoverForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => {
|
const makeSelectCoverForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => {
|
||||||
|
@ -1543,6 +1553,14 @@ const selectLastClaimSearchUris = reselect.createSelector(selectState$1, state =
|
||||||
|
|
||||||
const makeSelectShortUrlForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => claim && claim.short_url);
|
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[createNormalizedTagKey(tags)]);
|
||||||
|
|
||||||
|
const makeSelectClaimSearchUrisForTags = tags => reselect.createSelector(selectClaimSearchUrisByTags, byTags => byTags[createNormalizedTagKey(tags)]);
|
||||||
|
|
||||||
const selectState$2 = state => state.wallet || {};
|
const selectState$2 = state => state.wallet || {};
|
||||||
|
|
||||||
const selectWalletState = selectState$2;
|
const selectWalletState = selectState$2;
|
||||||
|
@ -2385,6 +2403,44 @@ function doClaimSearch(options = {}) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tags can be one or many (comma separated)
|
||||||
|
function doClaimSearchByTags(tags, amount = 10, options = {}) {
|
||||||
|
return dispatch => {
|
||||||
|
const tagList = createNormalizedTagKey(tags);
|
||||||
|
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,
|
||||||
|
any_tags: tags
|
||||||
|
}, options)).then(success, failure);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const selectState$3 = state => state.fileInfo || {};
|
const selectState$3 = state => state.fileInfo || {};
|
||||||
|
|
||||||
const selectFileInfosByOutpoint = reselect.createSelector(selectState$3, state => state.byOutpoint || {});
|
const selectFileInfosByOutpoint = reselect.createSelector(selectState$3, state => state.byOutpoint || {});
|
||||||
|
@ -3381,6 +3437,8 @@ const defaultState = {
|
||||||
abandoningById: {},
|
abandoningById: {},
|
||||||
pendingById: {},
|
pendingById: {},
|
||||||
fetchingClaimSearch: false,
|
fetchingClaimSearch: false,
|
||||||
|
claimSearchUrisByTags: {},
|
||||||
|
fetchingClaimSearchByTags: {},
|
||||||
lastClaimSearchUris: []
|
lastClaimSearchUris: []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3636,6 +3694,41 @@ 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 { append, tags, uris } = action.data;
|
||||||
|
|
||||||
|
if (action.data.append) {
|
||||||
|
// todo: check for duplicate uris when concatenating?
|
||||||
|
claimSearchUrisByTags[tags] = claimSearchUrisByTags[tags] && claimSearchUrisByTags[tags].length ? claimSearchUrisByTags[tags].concat(uris) : uris;
|
||||||
|
} else {
|
||||||
|
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) {
|
function claimsReducer(state = defaultState, action) {
|
||||||
const handler = reducers[action.type];
|
const handler = reducers[action.type];
|
||||||
if (handler) return handler(state, action);
|
if (handler) return handler(state, action);
|
||||||
|
@ -4669,7 +4762,7 @@ const selectKnownTagsByName = reselect.createSelector(selectState$9, state => st
|
||||||
|
|
||||||
const selectFollowedTagsList = reselect.createSelector(selectState$9, state => state.followedTags);
|
const selectFollowedTagsList = reselect.createSelector(selectState$9, state => state.followedTags);
|
||||||
|
|
||||||
const selectFollowedTags = reselect.createSelector(selectFollowedTagsList, followedTags => followedTags.map(tag => ({ name: tag })).sort((a, b) => a.name.localeCompare(b.name)));
|
const selectFollowedTags = reselect.createSelector(selectFollowedTagsList, followedTags => followedTags.map(tag => ({ name: tag.toLowerCase() })).sort((a, b) => a.name.localeCompare(b.name)));
|
||||||
|
|
||||||
const selectUnfollowedTags = reselect.createSelector(selectKnownTagsByName, selectFollowedTagsList, (tagsByName, followedTags) => {
|
const selectUnfollowedTags = reselect.createSelector(selectKnownTagsByName, selectFollowedTagsList, (tagsByName, followedTags) => {
|
||||||
const followedTagsSet = new Set(followedTags);
|
const followedTagsSet = new Set(followedTags);
|
||||||
|
@ -4713,6 +4806,7 @@ exports.doBlurSearchInput = doBlurSearchInput;
|
||||||
exports.doCheckAddressIsMine = doCheckAddressIsMine;
|
exports.doCheckAddressIsMine = doCheckAddressIsMine;
|
||||||
exports.doCheckPendingPublishes = doCheckPendingPublishes;
|
exports.doCheckPendingPublishes = doCheckPendingPublishes;
|
||||||
exports.doClaimSearch = doClaimSearch;
|
exports.doClaimSearch = doClaimSearch;
|
||||||
|
exports.doClaimSearchByTags = doClaimSearchByTags;
|
||||||
exports.doClearPublish = doClearPublish;
|
exports.doClearPublish = doClearPublish;
|
||||||
exports.doCommentCreate = doCommentCreate;
|
exports.doCommentCreate = doCommentCreate;
|
||||||
exports.doCommentList = doCommentList;
|
exports.doCommentList = doCommentList;
|
||||||
|
@ -4774,6 +4868,7 @@ exports.makeSelectClaimForUri = makeSelectClaimForUri;
|
||||||
exports.makeSelectClaimIsMine = makeSelectClaimIsMine;
|
exports.makeSelectClaimIsMine = makeSelectClaimIsMine;
|
||||||
exports.makeSelectClaimIsNsfw = makeSelectClaimIsNsfw;
|
exports.makeSelectClaimIsNsfw = makeSelectClaimIsNsfw;
|
||||||
exports.makeSelectClaimIsPending = makeSelectClaimIsPending;
|
exports.makeSelectClaimIsPending = makeSelectClaimIsPending;
|
||||||
|
exports.makeSelectClaimSearchUrisForTags = makeSelectClaimSearchUrisForTags;
|
||||||
exports.makeSelectClaimsInChannelForCurrentPageState = makeSelectClaimsInChannelForCurrentPageState;
|
exports.makeSelectClaimsInChannelForCurrentPageState = makeSelectClaimsInChannelForCurrentPageState;
|
||||||
exports.makeSelectClaimsInChannelForPage = makeSelectClaimsInChannelForPage;
|
exports.makeSelectClaimsInChannelForPage = makeSelectClaimsInChannelForPage;
|
||||||
exports.makeSelectCommentsForUri = makeSelectCommentsForUri;
|
exports.makeSelectCommentsForUri = makeSelectCommentsForUri;
|
||||||
|
@ -4783,6 +4878,7 @@ exports.makeSelectCoverForUri = makeSelectCoverForUri;
|
||||||
exports.makeSelectDateForUri = makeSelectDateForUri;
|
exports.makeSelectDateForUri = makeSelectDateForUri;
|
||||||
exports.makeSelectDownloadingForUri = makeSelectDownloadingForUri;
|
exports.makeSelectDownloadingForUri = makeSelectDownloadingForUri;
|
||||||
exports.makeSelectFetchingChannelClaims = makeSelectFetchingChannelClaims;
|
exports.makeSelectFetchingChannelClaims = makeSelectFetchingChannelClaims;
|
||||||
|
exports.makeSelectFetchingClaimSearchForTags = makeSelectFetchingClaimSearchForTags;
|
||||||
exports.makeSelectFileInfoForUri = makeSelectFileInfoForUri;
|
exports.makeSelectFileInfoForUri = makeSelectFileInfoForUri;
|
||||||
exports.makeSelectFirstRecommendedFileForUri = makeSelectFirstRecommendedFileForUri;
|
exports.makeSelectFirstRecommendedFileForUri = makeSelectFirstRecommendedFileForUri;
|
||||||
exports.makeSelectIsUriResolving = makeSelectIsUriResolving;
|
exports.makeSelectIsUriResolving = makeSelectIsUriResolving;
|
||||||
|
@ -4818,6 +4914,7 @@ exports.selectAllMyClaimsByOutpoint = selectAllMyClaimsByOutpoint;
|
||||||
exports.selectBalance = selectBalance;
|
exports.selectBalance = selectBalance;
|
||||||
exports.selectBlocks = selectBlocks;
|
exports.selectBlocks = selectBlocks;
|
||||||
exports.selectChannelClaimCounts = selectChannelClaimCounts;
|
exports.selectChannelClaimCounts = selectChannelClaimCounts;
|
||||||
|
exports.selectClaimSearchUrisByTags = selectClaimSearchUrisByTags;
|
||||||
exports.selectClaimsById = selectClaimsById;
|
exports.selectClaimsById = selectClaimsById;
|
||||||
exports.selectClaimsByUri = selectClaimsByUri;
|
exports.selectClaimsByUri = selectClaimsByUri;
|
||||||
exports.selectCurrentChannelPage = selectCurrentChannelPage;
|
exports.selectCurrentChannelPage = selectCurrentChannelPage;
|
||||||
|
@ -4831,6 +4928,7 @@ exports.selectDraftTransactionError = selectDraftTransactionError;
|
||||||
exports.selectError = selectError;
|
exports.selectError = selectError;
|
||||||
exports.selectFailedPurchaseUris = selectFailedPurchaseUris;
|
exports.selectFailedPurchaseUris = selectFailedPurchaseUris;
|
||||||
exports.selectFetchingClaimSearch = selectFetchingClaimSearch;
|
exports.selectFetchingClaimSearch = selectFetchingClaimSearch;
|
||||||
|
exports.selectFetchingClaimSearchByTags = selectFetchingClaimSearchByTags;
|
||||||
exports.selectFetchingMyChannels = selectFetchingMyChannels;
|
exports.selectFetchingMyChannels = selectFetchingMyChannels;
|
||||||
exports.selectFileInfosByOutpoint = selectFileInfosByOutpoint;
|
exports.selectFileInfosByOutpoint = selectFileInfosByOutpoint;
|
||||||
exports.selectFileInfosDownloaded = selectFileInfosDownloaded;
|
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_STARTED = 'CLAIM_SEARCH_STARTED';
|
||||||
export const CLAIM_SEARCH_COMPLETED = 'CLAIM_SEARCH_COMPLETED';
|
export const CLAIM_SEARCH_COMPLETED = 'CLAIM_SEARCH_COMPLETED';
|
||||||
export const CLAIM_SEARCH_FAILED = 'CLAIM_SEARCH_FAILED';
|
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
|
// Comments
|
||||||
export const COMMENT_LIST_STARTED = 'COMMENT_LIST_STARTED';
|
export const COMMENT_LIST_STARTED = 'COMMENT_LIST_STARTED';
|
||||||
|
|
|
@ -55,6 +55,7 @@ export {
|
||||||
doCreateChannel,
|
doCreateChannel,
|
||||||
doUpdateChannel,
|
doUpdateChannel,
|
||||||
doClaimSearch,
|
doClaimSearch,
|
||||||
|
doClaimSearchByTags,
|
||||||
} from 'redux/actions/claims';
|
} from 'redux/actions/claims';
|
||||||
|
|
||||||
export { doDeletePurchasedUri, doPurchaseUri, doFileGet } from 'redux/actions/file';
|
export { doDeletePurchasedUri, doPurchaseUri, doFileGet } from 'redux/actions/file';
|
||||||
|
@ -193,6 +194,10 @@ export {
|
||||||
selectCurrentChannelPage,
|
selectCurrentChannelPage,
|
||||||
selectFetchingClaimSearch,
|
selectFetchingClaimSearch,
|
||||||
selectLastClaimSearchUris,
|
selectLastClaimSearchUris,
|
||||||
|
selectFetchingClaimSearchByTags,
|
||||||
|
selectClaimSearchUrisByTags,
|
||||||
|
makeSelectFetchingClaimSearchForTags,
|
||||||
|
makeSelectClaimSearchUrisForTags,
|
||||||
} from 'redux/selectors/claims';
|
} from 'redux/selectors/claims';
|
||||||
|
|
||||||
export { makeSelectCommentsForUri } from 'redux/selectors/comments';
|
export { makeSelectCommentsForUri } from 'redux/selectors/comments';
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { doFetchTransactions } from 'redux/actions/wallet';
|
||||||
import { selectSupportsByOutpoint } from 'redux/selectors/wallet';
|
import { selectSupportsByOutpoint } from 'redux/selectors/wallet';
|
||||||
import { creditsToString } from 'util/formatCredits';
|
import { creditsToString } from 'util/formatCredits';
|
||||||
import { batchActions } from 'util/batchActions';
|
import { batchActions } from 'util/batchActions';
|
||||||
|
import { createNormalizedTagKey } from 'util/claim';
|
||||||
|
|
||||||
export function doResolveUris(uris: Array<string>, returnCachedClaims: boolean = false) {
|
export function doResolveUris(uris: Array<string>, returnCachedClaims: boolean = false) {
|
||||||
return (dispatch: Dispatch, getState: GetState) => {
|
return (dispatch: Dispatch, getState: GetState) => {
|
||||||
|
@ -345,3 +346,42 @@ export function doClaimSearch(options: { page_size?: number, page?: number } = {
|
||||||
}).then(success, failure);
|
}).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 = createNormalizedTagKey(tags);
|
||||||
|
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,
|
||||||
|
any_tags: tags,
|
||||||
|
...options,
|
||||||
|
}).then(success, failure);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ type State = {
|
||||||
fetchingChannelClaims: { [string]: number },
|
fetchingChannelClaims: { [string]: number },
|
||||||
fetchingMyChannels: boolean,
|
fetchingMyChannels: boolean,
|
||||||
lastClaimSearchUris: Array<string>,
|
lastClaimSearchUris: Array<string>,
|
||||||
|
fetchingClaimSearchByTags: { [string]: boolean },
|
||||||
|
claimSearchUrisByTags: { [string]: { all: Array<string> } },
|
||||||
claimsByChannel: {
|
claimsByChannel: {
|
||||||
[string]: {
|
[string]: {
|
||||||
all: Array<string>,
|
all: Array<string>,
|
||||||
|
@ -45,6 +47,8 @@ const defaultState = {
|
||||||
abandoningById: {},
|
abandoningById: {},
|
||||||
pendingById: {},
|
pendingById: {},
|
||||||
fetchingClaimSearch: false,
|
fetchingClaimSearch: false,
|
||||||
|
claimSearchUrisByTags: {},
|
||||||
|
fetchingClaimSearchByTags: {},
|
||||||
lastClaimSearchUris: [],
|
lastClaimSearchUris: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -312,6 +316,42 @@ 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 { append, tags, uris } = action.data;
|
||||||
|
|
||||||
|
if (action.data.append) {
|
||||||
|
// todo: check for duplicate uris when concatenating?
|
||||||
|
claimSearchUrisByTags[tags] = claimSearchUrisByTags[tags] && claimSearchUrisByTags[tags].length ?
|
||||||
|
claimSearchUrisByTags[tags].concat(uris) : uris;
|
||||||
|
} else {
|
||||||
|
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) {
|
export function claimsReducer(state: State = defaultState, action: any) {
|
||||||
const handler = reducers[action.type];
|
const handler = reducers[action.type];
|
||||||
if (handler) return handler(state, action);
|
if (handler) return handler(state, action);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import { normalizeURI, buildURI, parseURI } from 'lbryURI';
|
import { normalizeURI, buildURI, parseURI } from 'lbryURI';
|
||||||
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, createNormalizedTagKey } from 'util/claim';
|
||||||
import { getSearchQueryString } from 'util/query_params';
|
import { getSearchQueryString } from 'util/query_params';
|
||||||
|
|
||||||
const selectState = state => state.claims || {};
|
const selectState = state => state.claims || {};
|
||||||
|
@ -253,7 +253,7 @@ export const makeSelectThumbnailForUri = (uri: string) =>
|
||||||
makeSelectClaimForUri(uri),
|
makeSelectClaimForUri(uri),
|
||||||
claim => {
|
claim => {
|
||||||
const thumbnail = claim && claim.value && claim.value.thumbnail;
|
const thumbnail = claim && claim.value && claim.value.thumbnail;
|
||||||
return thumbnail ? thumbnail.url : undefined;
|
return thumbnail && thumbnail.url && thumbnail.url.trim().length > 0 ? thumbnail.url : undefined;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -509,3 +509,25 @@ export const makeSelectShortUrlForUri = (uri: string) =>
|
||||||
makeSelectClaimForUri(uri),
|
makeSelectClaimForUri(uri),
|
||||||
claim => claim && claim.short_url
|
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: Array<string>) =>
|
||||||
|
createSelector(
|
||||||
|
selectFetchingClaimSearchByTags,
|
||||||
|
byTags => byTags[createNormalizedTagKey(tags)]
|
||||||
|
);
|
||||||
|
|
||||||
|
export const makeSelectClaimSearchUrisForTags = (tags: Array<string>) =>
|
||||||
|
createSelector(
|
||||||
|
selectClaimSearchUrisByTags,
|
||||||
|
byTags => byTags[createNormalizedTagKey(tags)]
|
||||||
|
);
|
||||||
|
|
|
@ -16,7 +16,7 @@ export const selectFollowedTagsList = createSelector(
|
||||||
export const selectFollowedTags = createSelector(
|
export const selectFollowedTags = createSelector(
|
||||||
selectFollowedTagsList,
|
selectFollowedTagsList,
|
||||||
(followedTags: Array<string>): Array<Tag> =>
|
(followedTags: Array<string>): Array<Tag> =>
|
||||||
followedTags.map(tag => ({ name: tag })).sort((a, b) => a.name.localeCompare(b.name))
|
followedTags.map(tag => ({ name: tag.toLowerCase() })).sort((a, b) => a.name.localeCompare(b.name))
|
||||||
);
|
);
|
||||||
|
|
||||||
export const selectUnfollowedTags = createSelector(
|
export const selectUnfollowedTags = createSelector(
|
||||||
|
|
|
@ -22,3 +22,7 @@ export const isClaimNsfw = (claim: Claim): boolean => {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const createNormalizedTagKey = (tags: Array<string>): string => {
|
||||||
|
return tags ? tags.sort().join(',') : '';
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue