handle all options for claim_search cache queries
This commit is contained in:
parent
8910693fe1
commit
a1ae63d0b6
7 changed files with 120 additions and 283 deletions
dist
src
176
dist/bundle.es.js
vendored
176
dist/bundle.es.js
vendored
|
@ -1228,6 +1228,8 @@ function doDismissError() {
|
||||||
|
|
||||||
var _extends$2 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
var _extends$2 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
||||||
|
|
||||||
|
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
||||||
|
|
||||||
const matureTagMap = MATURE_TAGS.reduce((acc, tag) => _extends$2({}, acc, { [tag]: true }), {});
|
const matureTagMap = MATURE_TAGS.reduce((acc, tag) => _extends$2({}, acc, { [tag]: true }), {});
|
||||||
|
|
||||||
const isClaimNsfw = claim => {
|
const isClaimNsfw = claim => {
|
||||||
|
@ -1250,9 +1252,13 @@ const isClaimNsfw = claim => {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const createNormalizedTagKey = tags => {
|
function createNormalizedClaimSearchKey(options) {
|
||||||
return tags ? tags.sort().join(',') : '';
|
// Ignore page because we don't care what the last page searched was, we want everything
|
||||||
};
|
// Ignore release_time because that will change depending on when you call claim_search ex: release_time: ">12344567"
|
||||||
|
const rest = _objectWithoutProperties(options, ['page', 'release_time']);
|
||||||
|
const query = JSON.stringify(rest);
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
|
@ -1551,19 +1557,17 @@ const makeSelectTagsForUri = uri => reselect.createSelector(makeSelectMetadataFo
|
||||||
return metadata && metadata.tags || [];
|
return metadata && metadata.tags || [];
|
||||||
});
|
});
|
||||||
|
|
||||||
const selectFetchingClaimSearch = reselect.createSelector(selectState$1, state => state.fetchingClaimSearch);
|
const selectfetchingClaimSearchByQuery = reselect.createSelector(selectState$1, state => state.fetchingClaimSearchByQuery || {});
|
||||||
|
|
||||||
const selectClaimSearchByQuery = reselect.createSelector(selectState$1, state => state.claimSearchSearchByQuery || {});
|
const selectFetchingClaimSearch = reselect.createSelector(selectfetchingClaimSearchByQuery, fetchingClaimSearchByQuery => Boolean(Object.keys(fetchingClaimSearchByQuery).length));
|
||||||
|
|
||||||
|
const selectClaimSearchByQuery = reselect.createSelector(selectState$1, state => state.claimSearchByQuery || {});
|
||||||
|
|
||||||
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 makeSelectFetchingClaimSearchForTags = tags => reselect.createSelector(selectfetchingClaimSearchByQuery, byQuery => byQuery[createNormalizedClaimSearchKey({ any_tags: tags })]);
|
||||||
|
|
||||||
const selectClaimSearchUrisByTags = reselect.createSelector(selectState$1, state => state.claimSearchUrisByTags);
|
const makeSelectClaimSearchUrisForTags = tags => reselect.createSelector(selectClaimSearchByQuery, byQuery => byQuery[createNormalizedClaimSearchKey({ any_tags: tags })]);
|
||||||
|
|
||||||
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 || {};
|
||||||
|
|
||||||
|
@ -2094,17 +2098,6 @@ function batchActions(...actions) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
|
||||||
|
|
||||||
//
|
|
||||||
function buildClaimSearchCacheQuery(options) {
|
|
||||||
// Ignore page because we don't care what the last page searched was, we want everything
|
|
||||||
// Ignore release_time because that will change depending on when you call claim_search ex: release_time: ">12344567"
|
|
||||||
const rest = _objectWithoutProperties(options, ["page", "release_time"]);
|
|
||||||
const query = JSON.stringify(rest);
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
|
||||||
var _extends$3 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
var _extends$3 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
||||||
|
|
||||||
function doResolveUris(uris, returnCachedClaims = false) {
|
function doResolveUris(uris, returnCachedClaims = false) {
|
||||||
|
@ -2387,12 +2380,14 @@ function doFetchChannelListMine() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function doClaimSearch(options = {}) {
|
function doClaimSearch(options = {
|
||||||
const query = buildClaimSearchCacheQuery(options);
|
page_size: 10
|
||||||
|
}) {
|
||||||
|
const query = createNormalizedClaimSearchKey(options);
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: CLAIM_SEARCH_STARTED
|
type: CLAIM_SEARCH_STARTED,
|
||||||
|
data: { query: query }
|
||||||
});
|
});
|
||||||
|
|
||||||
const success = data => {
|
const success = data => {
|
||||||
|
@ -2405,56 +2400,19 @@ function doClaimSearch(options = {}) {
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: CLAIM_SEARCH_COMPLETED,
|
type: CLAIM_SEARCH_COMPLETED,
|
||||||
data: { resolveInfo, uris, query, append: options.page && options.page !== 1 }
|
data: { query, resolveInfo, uris, append: options.page && options.page !== 1 }
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const failure = err => {
|
const failure = err => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: CLAIM_SEARCH_FAILED,
|
type: CLAIM_SEARCH_FAILED,
|
||||||
|
data: { query },
|
||||||
error: err
|
error: err
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
lbryProxy.claim_search(_extends$3({}, options)).then(success, failure);
|
lbryProxy.claim_search(options).then(success, failure);
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3491,10 +3449,8 @@ const defaultState = {
|
||||||
abandoningById: {},
|
abandoningById: {},
|
||||||
pendingById: {},
|
pendingById: {},
|
||||||
claimSearchError: false,
|
claimSearchError: false,
|
||||||
fetchingClaimSearch: false,
|
claimSearchByQuery: {},
|
||||||
claimSearchUrisByTags: {},
|
fetchingClaimSearchByQuery: {}
|
||||||
fetchingClaimSearchByTags: {},
|
|
||||||
lastClaimSearchUris: []
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function handleClaimAction(state, action) {
|
function handleClaimAction(state, action) {
|
||||||
|
@ -3723,71 +3679,41 @@ reducers[RESOLVE_URIS_STARTED] = (state, action) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
reducers[CLAIM_SEARCH_STARTED] = state => {
|
reducers[CLAIM_SEARCH_STARTED] = (state, action) => {
|
||||||
|
const fetchingClaimSearchByQuery = Object.assign({}, state.fetchingClaimSearchByQuery);
|
||||||
|
fetchingClaimSearchByQuery[action.data.query] = true;
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
fetchingClaimSearch: true,
|
fetchingClaimSearchByQuery
|
||||||
claimSearchError: false
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
reducers[CLAIM_SEARCH_COMPLETED] = (state, action) => {
|
reducers[CLAIM_SEARCH_COMPLETED] = (state, action) => {
|
||||||
const { claimSearchSearchByQuery } = state;
|
const fetchingClaimSearchByQuery = Object.assign({}, state.fetchingClaimSearchByQuery);
|
||||||
const { uris, query, append } = action.data;
|
const claimSearchByQuery = Object.assign({}, state.claimSearchByQuery);
|
||||||
|
const { append, query, uris } = action.data;
|
||||||
|
|
||||||
let newClaimSearch = _extends$5({}, claimSearchSearchByQuery);
|
if (append) {
|
||||||
if (!uris) {
|
|
||||||
newClaimSearch[query] = null;
|
|
||||||
} else if (append && newClaimSearch[query]) {
|
|
||||||
newClaimSearch[query] = newClaimSearch[query].concat(uris);
|
|
||||||
} else {
|
|
||||||
newClaimSearch[query] = uris;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _extends$5({}, handleClaimAction(state, action), {
|
|
||||||
fetchingClaimSearch: false,
|
|
||||||
claimSearchSearchByQuery: newClaimSearch
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
reducers[CLAIM_SEARCH_FAILED] = state => {
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
fetchingClaimSearch: false,
|
|
||||||
claimSearchError: true
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
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?
|
// todo: check for duplicate uris when concatenating?
|
||||||
claimSearchUrisByTags[tags] = claimSearchUrisByTags[tags] && claimSearchUrisByTags[tags].length ? claimSearchUrisByTags[tags].concat(uris) : uris;
|
claimSearchByQuery[query] = claimSearchByQuery[query] && claimSearchByQuery[query].length ? claimSearchByQuery[query].concat(uris) : uris;
|
||||||
} else {
|
} else {
|
||||||
claimSearchUrisByTags[tags] = uris;
|
claimSearchByQuery[query] = uris;
|
||||||
}
|
}
|
||||||
fetchingClaimSearchByTags[tags] = false; // or delete the key instead?
|
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
delete fetchingClaimSearchByQuery[query];
|
||||||
claimSearchUrisByTags,
|
|
||||||
fetchingClaimSearchByTags
|
return Object.assign({}, state, _extends$5({}, handleClaimAction(state, action), {
|
||||||
});
|
claimSearchByQuery,
|
||||||
|
fetchingClaimSearchByQuery
|
||||||
|
}));
|
||||||
};
|
};
|
||||||
reducers[CLAIM_SEARCH_BY_TAGS_FAILED] = (state, action) => {
|
|
||||||
const fetchingClaimSearchByTags = Object.assign({}, state.fetchingClaimSearchByTags);
|
reducers[CLAIM_SEARCH_FAILED] = (state, action) => {
|
||||||
fetchingClaimSearchByTags[action.data.tags] = false;
|
const fetchingClaimSearchByQuery = Object.assign({}, state.fetchingClaimSearchByQuery);
|
||||||
|
fetchingClaimSearchByQuery[action.data.tags] = false;
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
fetchingClaimSearchByTags
|
fetchingClaimSearchByQuery
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4784,12 +4710,12 @@ exports.SORT_OPTIONS = sort_options;
|
||||||
exports.THUMBNAIL_STATUSES = thumbnail_upload_statuses;
|
exports.THUMBNAIL_STATUSES = thumbnail_upload_statuses;
|
||||||
exports.TRANSACTIONS = transaction_types;
|
exports.TRANSACTIONS = transaction_types;
|
||||||
exports.batchActions = batchActions;
|
exports.batchActions = batchActions;
|
||||||
exports.buildClaimSearchCacheQuery = buildClaimSearchCacheQuery;
|
|
||||||
exports.buildURI = buildURI;
|
exports.buildURI = buildURI;
|
||||||
exports.claimsReducer = claimsReducer;
|
exports.claimsReducer = claimsReducer;
|
||||||
exports.commentReducer = commentReducer;
|
exports.commentReducer = commentReducer;
|
||||||
exports.contentReducer = contentReducer;
|
exports.contentReducer = contentReducer;
|
||||||
exports.convertToShareLink = convertToShareLink;
|
exports.convertToShareLink = convertToShareLink;
|
||||||
|
exports.createNormalizedClaimSearchKey = createNormalizedClaimSearchKey;
|
||||||
exports.creditsToString = creditsToString;
|
exports.creditsToString = creditsToString;
|
||||||
exports.doAbandonClaim = doAbandonClaim;
|
exports.doAbandonClaim = doAbandonClaim;
|
||||||
exports.doAddTag = doAddTag;
|
exports.doAddTag = doAddTag;
|
||||||
|
@ -4798,7 +4724,6 @@ 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;
|
||||||
|
@ -4908,7 +4833,6 @@ exports.selectBalance = selectBalance;
|
||||||
exports.selectBlocks = selectBlocks;
|
exports.selectBlocks = selectBlocks;
|
||||||
exports.selectChannelClaimCounts = selectChannelClaimCounts;
|
exports.selectChannelClaimCounts = selectChannelClaimCounts;
|
||||||
exports.selectClaimSearchByQuery = selectClaimSearchByQuery;
|
exports.selectClaimSearchByQuery = selectClaimSearchByQuery;
|
||||||
exports.selectClaimSearchUrisByTags = selectClaimSearchUrisByTags;
|
|
||||||
exports.selectClaimsById = selectClaimsById;
|
exports.selectClaimsById = selectClaimsById;
|
||||||
exports.selectClaimsByUri = selectClaimsByUri;
|
exports.selectClaimsByUri = selectClaimsByUri;
|
||||||
exports.selectCurrentChannelPage = selectCurrentChannelPage;
|
exports.selectCurrentChannelPage = selectCurrentChannelPage;
|
||||||
|
@ -4922,7 +4846,6 @@ 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;
|
||||||
|
@ -4986,6 +4909,7 @@ exports.selectWalletState = selectWalletState;
|
||||||
exports.selectWalletUnlockPending = selectWalletUnlockPending;
|
exports.selectWalletUnlockPending = selectWalletUnlockPending;
|
||||||
exports.selectWalletUnlockResult = selectWalletUnlockResult;
|
exports.selectWalletUnlockResult = selectWalletUnlockResult;
|
||||||
exports.selectWalletUnlockSucceeded = selectWalletUnlockSucceeded;
|
exports.selectWalletUnlockSucceeded = selectWalletUnlockSucceeded;
|
||||||
|
exports.selectfetchingClaimSearchByQuery = selectfetchingClaimSearchByQuery;
|
||||||
exports.setSearchApi = setSearchApi;
|
exports.setSearchApi = setSearchApi;
|
||||||
exports.tagsReducer = tagsReducer;
|
exports.tagsReducer = tagsReducer;
|
||||||
exports.toQueryString = toQueryString;
|
exports.toQueryString = toQueryString;
|
||||||
|
|
|
@ -55,7 +55,6 @@ 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';
|
||||||
|
@ -116,8 +115,7 @@ export { doCommentList, doCommentCreate } from 'redux/actions/comments';
|
||||||
export { batchActions } from 'util/batch-actions';
|
export { batchActions } from 'util/batch-actions';
|
||||||
export { parseQueryParams, toQueryString } from 'util/query-params';
|
export { parseQueryParams, toQueryString } from 'util/query-params';
|
||||||
export { formatCredits, formatFullPrice, creditsToString } from 'util/format-credits';
|
export { formatCredits, formatFullPrice, creditsToString } from 'util/format-credits';
|
||||||
export { isClaimNsfw } from 'util/claim';
|
export { isClaimNsfw, createNormalizedClaimSearchKey } from 'util/claim';
|
||||||
export { buildClaimSearchCacheQuery } from 'util/claim-search';
|
|
||||||
|
|
||||||
// reducers
|
// reducers
|
||||||
export { claimsReducer } from 'redux/reducers/claims';
|
export { claimsReducer } from 'redux/reducers/claims';
|
||||||
|
@ -194,11 +192,10 @@ export {
|
||||||
selectChannelClaimCounts,
|
selectChannelClaimCounts,
|
||||||
selectCurrentChannelPage,
|
selectCurrentChannelPage,
|
||||||
selectFetchingClaimSearch,
|
selectFetchingClaimSearch,
|
||||||
selectFetchingClaimSearchByTags,
|
selectfetchingClaimSearchByQuery,
|
||||||
selectClaimSearchUrisByTags,
|
selectClaimSearchByQuery,
|
||||||
makeSelectFetchingClaimSearchForTags,
|
makeSelectFetchingClaimSearchForTags,
|
||||||
makeSelectClaimSearchUrisForTags,
|
makeSelectClaimSearchUrisForTags,
|
||||||
selectClaimSearchByQuery,
|
|
||||||
} from 'redux/selectors/claims';
|
} from 'redux/selectors/claims';
|
||||||
|
|
||||||
export { makeSelectCommentsForUri } from 'redux/selectors/comments';
|
export { makeSelectCommentsForUri } from 'redux/selectors/comments';
|
||||||
|
|
|
@ -8,8 +8,7 @@ import { doFetchTransactions } from 'redux/actions/wallet';
|
||||||
import { selectSupportsByOutpoint } from 'redux/selectors/wallet';
|
import { selectSupportsByOutpoint } from 'redux/selectors/wallet';
|
||||||
import { creditsToString } from 'util/format-credits';
|
import { creditsToString } from 'util/format-credits';
|
||||||
import { batchActions } from 'util/batch-actions';
|
import { batchActions } from 'util/batch-actions';
|
||||||
import { createNormalizedTagKey } from 'util/claim';
|
import { createNormalizedClaimSearchKey } from 'util/claim';
|
||||||
import { buildClaimSearchCacheQuery } from 'util/claim-search';
|
|
||||||
|
|
||||||
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) => {
|
||||||
|
@ -315,12 +314,16 @@ export function doFetchChannelListMine() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doClaimSearch(options: { page?: number, release_time?: string } = {}) {
|
export function doClaimSearch(
|
||||||
const query = buildClaimSearchCacheQuery(options);
|
options: { tags?: Array<string>, page?: number, page_size?: number, release_time?: string } = {
|
||||||
|
page_size: 10,
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
const query = createNormalizedClaimSearchKey(options);
|
||||||
return (dispatch: Dispatch) => {
|
return (dispatch: Dispatch) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.CLAIM_SEARCH_STARTED,
|
type: ACTIONS.CLAIM_SEARCH_STARTED,
|
||||||
|
data: { query: query },
|
||||||
});
|
});
|
||||||
|
|
||||||
const success = (data: ClaimSearchResponse) => {
|
const success = (data: ClaimSearchResponse) => {
|
||||||
|
@ -333,62 +336,18 @@ export function doClaimSearch(options: { page?: number, release_time?: string }
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.CLAIM_SEARCH_COMPLETED,
|
type: ACTIONS.CLAIM_SEARCH_COMPLETED,
|
||||||
data: { resolveInfo, uris, query, append: options.page && options.page !== 1 },
|
data: { query, resolveInfo, uris, append: options.page && options.page !== 1 },
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const failure = err => {
|
const failure = err => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.CLAIM_SEARCH_FAILED,
|
type: ACTIONS.CLAIM_SEARCH_FAILED,
|
||||||
|
data: { query },
|
||||||
error: err,
|
error: err,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Lbry.claim_search({
|
Lbry.claim_search(options).then(success, failure);
|
||||||
...options,
|
|
||||||
}).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);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,8 @@ type State = {
|
||||||
abandoningById: { [string]: boolean },
|
abandoningById: { [string]: boolean },
|
||||||
fetchingChannelClaims: { [string]: number },
|
fetchingChannelClaims: { [string]: number },
|
||||||
fetchingMyChannels: boolean,
|
fetchingMyChannels: boolean,
|
||||||
lastClaimSearchUris: Array<string>,
|
fetchingClaimSearchByQuery: { [string]: boolean },
|
||||||
fetchingClaimSearchByTags: { [string]: boolean },
|
claimSearchByQuery: { [string]: Array<string> },
|
||||||
claimSearchUrisByTags: { [string]: { all: Array<string> } },
|
|
||||||
claimsByChannel: {
|
claimsByChannel: {
|
||||||
[string]: {
|
[string]: {
|
||||||
all: Array<string>,
|
all: Array<string>,
|
||||||
|
@ -47,10 +46,8 @@ const defaultState = {
|
||||||
abandoningById: {},
|
abandoningById: {},
|
||||||
pendingById: {},
|
pendingById: {},
|
||||||
claimSearchError: false,
|
claimSearchError: false,
|
||||||
fetchingClaimSearch: false,
|
claimSearchByQuery: {},
|
||||||
claimSearchUrisByTags: {},
|
fetchingClaimSearchByQuery: {},
|
||||||
fetchingClaimSearchByTags: {},
|
|
||||||
lastClaimSearchUris: [],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function handleClaimAction(state: State, action: any): State {
|
function handleClaimAction(state: State, action: any): State {
|
||||||
|
@ -290,75 +287,45 @@ reducers[ACTIONS.RESOLVE_URIS_STARTED] = (state: State, action: any): State => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
reducers[ACTIONS.CLAIM_SEARCH_STARTED] = (state: State): State => {
|
reducers[ACTIONS.CLAIM_SEARCH_STARTED] = (state: State, action: any): State => {
|
||||||
|
const fetchingClaimSearchByQuery = Object.assign({}, state.fetchingClaimSearchByQuery);
|
||||||
|
fetchingClaimSearchByQuery[action.data.query] = true;
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
fetchingClaimSearch: true,
|
fetchingClaimSearchByQuery,
|
||||||
claimSearchError: false,
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
reducers[ACTIONS.CLAIM_SEARCH_COMPLETED] = (state: State, action: any): State => {
|
reducers[ACTIONS.CLAIM_SEARCH_COMPLETED] = (state: State, action: any): State => {
|
||||||
const { claimSearchSearchByQuery } = state;
|
const fetchingClaimSearchByQuery = Object.assign({}, state.fetchingClaimSearchByQuery);
|
||||||
const { uris, query, append } = action.data;
|
const claimSearchByQuery = Object.assign({}, state.claimSearchByQuery);
|
||||||
|
const { append, query, uris } = action.data;
|
||||||
|
|
||||||
let newClaimSearch = { ...claimSearchSearchByQuery };
|
if (append) {
|
||||||
if (!uris) {
|
|
||||||
newClaimSearch[query] = null;
|
|
||||||
} else if (append && newClaimSearch[query]) {
|
|
||||||
newClaimSearch[query] = newClaimSearch[query].concat(uris);
|
|
||||||
} else {
|
|
||||||
newClaimSearch[query] = uris;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...handleClaimAction(state, action),
|
|
||||||
fetchingClaimSearch: false,
|
|
||||||
claimSearchSearchByQuery: newClaimSearch,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
reducers[ACTIONS.CLAIM_SEARCH_FAILED] = (state: State): State => {
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
fetchingClaimSearch: false,
|
|
||||||
claimSearchError: true,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
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?
|
// todo: check for duplicate uris when concatenating?
|
||||||
claimSearchUrisByTags[tags] =
|
claimSearchByQuery[query] =
|
||||||
claimSearchUrisByTags[tags] && claimSearchUrisByTags[tags].length
|
claimSearchByQuery[query] && claimSearchByQuery[query].length
|
||||||
? claimSearchUrisByTags[tags].concat(uris)
|
? claimSearchByQuery[query].concat(uris)
|
||||||
: uris;
|
: uris;
|
||||||
} else {
|
} else {
|
||||||
claimSearchUrisByTags[tags] = uris;
|
claimSearchByQuery[query] = uris;
|
||||||
}
|
}
|
||||||
fetchingClaimSearchByTags[tags] = false; // or delete the key instead?
|
|
||||||
|
delete fetchingClaimSearchByQuery[query];
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
claimSearchUrisByTags,
|
...handleClaimAction(state, action),
|
||||||
fetchingClaimSearchByTags,
|
claimSearchByQuery,
|
||||||
|
fetchingClaimSearchByQuery,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
reducers[ACTIONS.CLAIM_SEARCH_BY_TAGS_FAILED] = (state: State, action: any): State => {
|
|
||||||
const fetchingClaimSearchByTags = Object.assign({}, state.fetchingClaimSearchByTags);
|
reducers[ACTIONS.CLAIM_SEARCH_FAILED] = (state: State, action: any): State => {
|
||||||
fetchingClaimSearchByTags[action.data.tags] = false;
|
const fetchingClaimSearchByQuery = Object.assign({}, state.fetchingClaimSearchByQuery);
|
||||||
|
fetchingClaimSearchByQuery[action.data.tags] = false;
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
fetchingClaimSearchByTags,
|
fetchingClaimSearchByQuery,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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, createNormalizedTagKey } from 'util/claim';
|
import { isClaimNsfw, createNormalizedClaimSearchKey } 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 || {};
|
||||||
|
@ -223,8 +223,8 @@ export const makeSelectDateForUri = (uri: string) =>
|
||||||
(claim.value.release_time
|
(claim.value.release_time
|
||||||
? claim.value.release_time * 1000
|
? claim.value.release_time * 1000
|
||||||
: claim.meta.creation_timestamp
|
: claim.meta.creation_timestamp
|
||||||
? claim.meta.creation_timestamp * 1000
|
? claim.meta.creation_timestamp * 1000
|
||||||
: null);
|
: null);
|
||||||
if (!timestamp) {
|
if (!timestamp) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -498,40 +498,34 @@ export const makeSelectTagsForUri = (uri: string) =>
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export const selectFetchingClaimSearch = createSelector(
|
export const selectfetchingClaimSearchByQuery = createSelector(
|
||||||
selectState,
|
selectState,
|
||||||
state => state.fetchingClaimSearch
|
state => state.fetchingClaimSearchByQuery || {}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const selectFetchingClaimSearch = createSelector(
|
||||||
|
selectfetchingClaimSearchByQuery,
|
||||||
|
fetchingClaimSearchByQuery => Boolean(Object.keys(fetchingClaimSearchByQuery).length)
|
||||||
);
|
);
|
||||||
|
|
||||||
export const selectClaimSearchByQuery = createSelector(
|
export const selectClaimSearchByQuery = createSelector(
|
||||||
selectState,
|
selectState,
|
||||||
state => state.claimSearchSearchByQuery || {}
|
state => state.claimSearchByQuery || {}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const makeSelectClaimSearchUrisByOptions = (options: {}) =>
|
||||||
|
createSelector(
|
||||||
|
selectClaimSearchByQuery,
|
||||||
|
byQuery => {
|
||||||
|
// We don't care what options are passed to this selector. Just forward them.
|
||||||
|
// $FlowFixMe
|
||||||
|
const query = createNormalizedClaimSearchKey(options);
|
||||||
|
return byQuery[query];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
export const makeSelectShortUrlForUri = (uri: string) =>
|
export const makeSelectShortUrlForUri = (uri: string) =>
|
||||||
createSelector(
|
createSelector(
|
||||||
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)]
|
|
||||||
);
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
// @flow
|
|
||||||
export function buildClaimSearchCacheQuery(options: { page?: number, release_time?: string }) {
|
|
||||||
// Ignore page because we don't care what the last page searched was, we want everything
|
|
||||||
// Ignore release_time because that will change depending on when you call claim_search ex: release_time: ">12344567"
|
|
||||||
const { page: optionToIgnoreForQuery, release_time: anotherToIgnore, ...rest } = options;
|
|
||||||
const query = JSON.stringify(rest);
|
|
||||||
return query;
|
|
||||||
}
|
|
|
@ -23,6 +23,10 @@ export const isClaimNsfw = (claim: Claim): boolean => {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createNormalizedTagKey = (tags: Array<string>): string => {
|
export function createNormalizedClaimSearchKey(options: { page?: number, release_time?: string }) {
|
||||||
return tags ? tags.sort().join(',') : '';
|
// Ignore page because we don't care what the last page searched was, we want everything
|
||||||
};
|
// Ignore release_time because that will change depending on when you call claim_search ex: release_time: ">12344567"
|
||||||
|
const { page: optionToIgnoreForQuery, release_time: anotherToIgnore, ...rest } = options;
|
||||||
|
const query = JSON.stringify(rest);
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue