From 6e0b1934d4b8a24fce0440c64f605f2125ab7f0d Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Fri, 25 May 2018 12:34:12 +0100 Subject: [PATCH] Added claim actions. Added claim_list_by_channel call to lbry.js --- dist/bundle.js | 92 +++++++++++++++++++++++++++++++++-- src/index.js | 3 ++ src/lbry.js | 3 ++ src/redux/actions/claims.js | 45 +++++++++++++++++ src/redux/selectors/claims.js | 10 ++++ 5 files changed, 150 insertions(+), 3 deletions(-) diff --git a/dist/bundle.js b/dist/bundle.js index a2d923b..55930e5 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -89,8 +89,8 @@ return /******/ (function(modules) { // webpackBootstrap Object.defineProperty(exports, "__esModule", { value: true }); -exports.selectBlocks = exports.selectDraftTransactionError = exports.selectDraftTransactionAddress = exports.selectDraftTransactionAmount = exports.selectDraftTransaction = exports.selectGettingNewAddress = exports.selectReceiveAddress = exports.selectIsSendingSupport = exports.selectIsFetchingTransactions = exports.selectHasTransactions = exports.selectRecentTransactions = exports.selectTransactionItems = exports.selectTransactionsById = exports.selectBalance = exports.makeSelectBlockDate = exports.selectSearchBarFocused = exports.selectWunderBarAddress = exports.selectSearchUrisByQuery = exports.selectIsSearching = exports.selectSearchValue = exports.selectSearchQuery = exports.makeSelectSearchUris = exports.selectSearchState = exports.selectNavLinks = exports.selectActiveHistoryEntry = exports.selectHistoryStack = exports.selectHistoryIndex = exports.selectIsForwardDisabled = exports.selectIsBackDisabled = exports.selectPathAfterAuth = exports.selectPageTitle = exports.selectHeaderLinks = exports.selectCurrentParams = exports.selectCurrentPage = exports.selectCurrentPath = exports.makeSelectCurrentParam = exports.computePageFromPath = exports.selectSearchDownloadUris = exports.selectTotalDownloadProgress = exports.selectDownloadingFileInfos = exports.selectFileInfosDownloaded = exports.selectUrisLoading = undefined; -exports.selectDownloadingByOutpoint = exports.selectIsFetchingFileListDownloadedOrPublished = exports.selectIsFetchingFileList = exports.selectFileInfosByOutpoint = exports.makeSelectLoadingForUri = exports.makeSelectDownloadingForUri = exports.makeSelectFileInfoForUri = exports.selectFetchingCostInfo = exports.selectCostForCurrentPageUri = exports.selectAllCostInfoByUri = exports.makeSelectCostInfoForUri = exports.makeSelectFetchingCostInfoForUri = exports.selectRewardContentClaimIds = exports.selectChannelClaimCounts = exports.selectPlayingUri = exports.selectFetchingFeaturedUris = exports.selectFeaturedUris = exports.selectResolvingUris = exports.selectMyChannelClaims = exports.selectFetchingMyChannels = exports.selectMyClaimsOutpoints = exports.selectAllMyClaimsByOutpoint = exports.selectMyClaimsWithoutChannels = exports.selectMyClaims = exports.selectPendingClaims = exports.selectIsFetchingClaimListMine = exports.selectAllFetchingChannelClaims = exports.selectMyActiveClaims = exports.selectAbandoningIds = exports.selectMyClaimsRaw = exports.selectAllClaimsByChannel = exports.selectClaimsByUri = exports.selectClaimsById = exports.makeSelectTotalPagesForChannel = exports.makeSelectTotalItemsForChannel = exports.makeSelectIsUriResolving = exports.makeSelectContentTypeForUri = exports.makeSelectTitleForUri = exports.makeSelectMetadataForUri = exports.makeSelectClaimsInChannelForCurrentPage = exports.makeSelectFetchingChannelClaims = exports.makeSelectClaimIsMine = exports.makeSelectClaimForUri = exports.selectSnack = exports.selectNotificationProps = exports.selectNotification = exports.selectBlackListedOutpoints = exports.blacklistReducer = exports.walletReducer = exports.searchReducer = exports.notificationsReducer = exports.fileInfoReducer = exports.costInfoReducer = exports.claimsReducer = exports.formatFullPrice = exports.formatCredits = exports.toQueryString = exports.parseQueryParams = exports.batchActions = exports.doSendSupport = exports.doSetDraftTransactionAddress = exports.doSetDraftTransactionAmount = exports.doSendDraftTransaction = exports.doCheckAddressIsMine = exports.doGetNewAddress = exports.doFetchBlock = exports.doFetchTransactions = exports.doBalanceSubscribe = exports.doUpdateBalance = exports.doBlackListedOutpointsSubscribe = exports.doBlurSearchInput = exports.doFocusSearchInput = exports.doUpdateSearchQuery = exports.doSearch = exports.doFetchFileInfosAndPublishedClaims = exports.doFileList = exports.doFetchFileInfo = exports.doFetchCostInfoForUri = exports.doFetchRewardedContent = exports.doFetchFeaturedUris = exports.doResolveUri = exports.doResolveUris = exports.doAbandonClaim = exports.doFetchClaimListMine = exports.doHideNotification = exports.doNotify = exports.isNameValid = exports.isURIClaimable = exports.isURIValid = exports.normalizeURI = exports.buildURI = exports.parseURI = exports.regexAddress = exports.regexInvalidURI = exports.Lbryapi = exports.Lbry = exports.MODALS = exports.SETTINGS = exports.ACTIONS = exports.Notification = undefined; +exports.selectBlocks = exports.selectDraftTransactionError = exports.selectDraftTransactionAddress = exports.selectDraftTransactionAmount = exports.selectDraftTransaction = exports.selectGettingNewAddress = exports.selectReceiveAddress = exports.selectIsSendingSupport = exports.selectIsFetchingTransactions = exports.selectHasTransactions = exports.selectRecentTransactions = exports.selectTransactionItems = exports.selectTransactionsById = exports.selectBalance = exports.makeSelectBlockDate = exports.selectSearchBarFocused = exports.selectWunderBarAddress = exports.selectSearchUrisByQuery = exports.selectIsSearching = exports.selectSearchValue = exports.selectSearchQuery = exports.makeSelectSearchUris = exports.selectSearchState = exports.selectNavLinks = exports.selectActiveHistoryEntry = exports.selectHistoryStack = exports.selectHistoryIndex = exports.selectIsForwardDisabled = exports.selectIsBackDisabled = exports.selectPathAfterAuth = exports.selectPageTitle = exports.selectHeaderLinks = exports.selectCurrentParams = exports.selectCurrentPage = exports.selectCurrentPath = exports.makeSelectCurrentParam = exports.computePageFromPath = exports.selectSearchDownloadUris = exports.selectTotalDownloadProgress = exports.selectDownloadingFileInfos = exports.selectFileInfosDownloaded = exports.selectUrisLoading = exports.selectDownloadingByOutpoint = exports.selectIsFetchingFileListDownloadedOrPublished = exports.selectIsFetchingFileList = undefined; +exports.selectFileInfosByOutpoint = exports.makeSelectLoadingForUri = exports.makeSelectDownloadingForUri = exports.makeSelectFileInfoForUri = exports.selectFetchingCostInfo = exports.selectCostForCurrentPageUri = exports.selectAllCostInfoByUri = exports.makeSelectCostInfoForUri = exports.makeSelectFetchingCostInfoForUri = exports.selectRewardContentClaimIds = exports.selectChannelClaimCounts = exports.selectPlayingUri = exports.selectFetchingFeaturedUris = exports.selectFeaturedUris = exports.selectResolvingUris = exports.selectMyChannelClaims = exports.selectFetchingMyChannels = exports.selectMyClaimsOutpoints = exports.selectAllMyClaimsByOutpoint = exports.selectMyClaimsWithoutChannels = exports.selectMyClaims = exports.selectPendingClaims = exports.selectIsFetchingClaimListMine = exports.selectAllFetchingChannelClaims = exports.selectMyActiveClaims = exports.selectAbandoningIds = exports.selectMyClaimsRaw = exports.selectAllClaimsByChannel = exports.selectClaimsByUri = exports.selectClaimsById = exports.makeSelectTotalPagesForChannel = exports.makeSelectTotalItemsForChannel = exports.makeSelectIsUriResolving = exports.makeSelectContentTypeForUri = exports.makeSelectTitleForUri = exports.makeSelectMetadataForUri = exports.makeSelectClaimsInChannelForPage = exports.makeSelectClaimsInChannelForCurrentPage = exports.makeSelectFetchingChannelClaims = exports.makeSelectClaimIsMine = exports.makeSelectClaimForUri = exports.selectSnack = exports.selectNotificationProps = exports.selectNotification = exports.selectBlackListedOutpoints = exports.blacklistReducer = exports.walletReducer = exports.searchReducer = exports.notificationsReducer = exports.fileInfoReducer = exports.costInfoReducer = exports.claimsReducer = exports.formatFullPrice = exports.formatCredits = exports.toQueryString = exports.parseQueryParams = exports.batchActions = exports.doSendSupport = exports.doSetDraftTransactionAddress = exports.doSetDraftTransactionAmount = exports.doSendDraftTransaction = exports.doCheckAddressIsMine = exports.doGetNewAddress = exports.doFetchBlock = exports.doFetchTransactions = exports.doBalanceSubscribe = exports.doUpdateBalance = exports.doBlackListedOutpointsSubscribe = exports.doBlurSearchInput = exports.doFocusSearchInput = exports.doUpdateSearchQuery = exports.doSearch = exports.doFetchFileInfosAndPublishedClaims = exports.doFileList = exports.doFetchFileInfo = exports.doFetchCostInfoForUri = exports.doFetchRewardedContent = exports.doFetchFeaturedUris = exports.doResolveUri = exports.doResolveUris = exports.doAbandonClaim = exports.doFetchClaimListMine = exports.doFetchClaimCountByChannel = exports.doFetchClaimsByChannel = exports.doHideNotification = exports.doNotify = exports.isNameValid = exports.isURIClaimable = exports.isURIValid = exports.normalizeURI = exports.buildURI = exports.parseURI = exports.regexAddress = exports.regexInvalidURI = exports.Lbryapi = exports.Lbry = exports.MODALS = exports.SETTINGS = exports.ACTIONS = exports.Notification = undefined; var _Notification = __webpack_require__(1); @@ -169,6 +169,18 @@ Object.defineProperty(exports, 'doHideNotification', { var _claims = __webpack_require__(5); +Object.defineProperty(exports, 'doFetchClaimsByChannel', { + enumerable: true, + get: function get() { + return _claims.doFetchClaimsByChannel; + } +}); +Object.defineProperty(exports, 'doFetchClaimCountByChannel', { + enumerable: true, + get: function get() { + return _claims.doFetchClaimCountByChannel; + } +}); Object.defineProperty(exports, 'doFetchClaimListMine', { enumerable: true, get: function get() { @@ -493,6 +505,12 @@ Object.defineProperty(exports, 'makeSelectClaimsInChannelForCurrentPage', { return _claims3.makeSelectClaimsInChannelForCurrentPage; } }); +Object.defineProperty(exports, 'makeSelectClaimsInChannelForPage', { + enumerable: true, + get: function get() { + return _claims3.makeSelectClaimsInChannelForPage; + } +}); Object.defineProperty(exports, 'makeSelectMetadataForUri', { enumerable: true, get: function get() { @@ -1560,6 +1578,8 @@ exports.doFetchClaimListMine = doFetchClaimListMine; exports.doAbandonClaim = doAbandonClaim; exports.doFetchFeaturedUris = doFetchFeaturedUris; exports.doFetchRewardedContent = doFetchRewardedContent; +exports.doFetchClaimsByChannel = doFetchClaimsByChannel; +exports.doFetchClaimCountByChannel = doFetchClaimCountByChannel; var _action_types = __webpack_require__(4); @@ -1774,6 +1794,53 @@ function doFetchRewardedContent() { }; } +function doFetchClaimsByChannel(uri, page) { + return function (dispatch, getState) { + dispatch({ + type: ACTIONS.FETCH_CHANNEL_CLAIMS_STARTED, + data: { uri: uri, page: page } + }); + + _lbry2.default.claim_list_by_channel({ uri: uri, page: page || 1 }).then(function (result) { + var claimResult = result[uri] || {}; + var claimsInChannel = claimResult.claims_in_channel, + returnedPage = claimResult.returned_page; + + + dispatch({ + type: ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED, + data: { + uri: uri, + claims: claimsInChannel || [], + page: returnedPage || undefined + } + }); + }); + }; +} + +function doFetchClaimCountByChannel(uri) { + return function (dispatch) { + dispatch({ + type: ACTIONS.FETCH_CHANNEL_CLAIM_COUNT_STARTED, + data: { uri: uri } + }); + + _lbry2.default.claim_list_by_channel({ uri: uri }).then(function (result) { + var claimResult = result[uri]; + var totalClaims = claimResult ? claimResult.claims_in_channel : 0; + + dispatch({ + type: ACTIONS.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED, + data: { + uri: uri, + totalClaims: totalClaims + } + }); + }); + }; +} + /***/ }), /* 6 */ /***/ (function(module, exports, __webpack_require__) { @@ -1859,6 +1926,12 @@ Lbry.file_set_status = function () { return daemonCallWithResult('file_set_status', params); }; +// claims +Lbry.claim_list_by_channel = function () { + var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return daemonCallWithResult('claim_list_by_channel', params); +}; + // wallet Lbry.wallet_balance = function () { var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; @@ -2712,7 +2785,7 @@ var objectKeys = Object.keys || function (obj) { Object.defineProperty(exports, "__esModule", { value: true }); -exports.selectRewardContentClaimIds = exports.makeSelectTotalPagesForChannel = exports.makeSelectTotalItemsForChannel = exports.selectChannelClaimCounts = exports.selectPlayingUri = exports.selectFetchingFeaturedUris = exports.selectFeaturedUris = exports.makeSelectIsUriResolving = exports.selectResolvingUris = exports.selectMyChannelClaims = exports.selectFetchingMyChannels = exports.selectMyClaimsOutpoints = exports.selectAllMyClaimsByOutpoint = exports.selectMyClaimsWithoutChannels = exports.selectMyClaims = exports.selectPendingClaims = exports.selectIsFetchingClaimListMine = exports.makeSelectContentTypeForUri = exports.makeSelectTitleForUri = exports.makeSelectMetadataForUri = exports.makeSelectClaimsInChannelForCurrentPage = exports.makeSelectFetchingChannelClaims = exports.selectAllFetchingChannelClaims = exports.makeSelectClaimIsMine = exports.selectMyActiveClaims = exports.selectAbandoningIds = exports.selectMyClaimsRaw = exports.makeSelectClaimForUri = exports.selectAllClaimsByChannel = exports.selectClaimsByUri = exports.selectClaimsById = undefined; +exports.selectRewardContentClaimIds = exports.makeSelectTotalPagesForChannel = exports.makeSelectTotalItemsForChannel = exports.selectChannelClaimCounts = exports.selectPlayingUri = exports.selectFetchingFeaturedUris = exports.selectFeaturedUris = exports.makeSelectIsUriResolving = exports.selectResolvingUris = exports.selectMyChannelClaims = exports.selectFetchingMyChannels = exports.selectMyClaimsOutpoints = exports.selectAllMyClaimsByOutpoint = exports.selectMyClaimsWithoutChannels = exports.selectMyClaims = exports.selectPendingClaims = exports.selectIsFetchingClaimListMine = exports.makeSelectContentTypeForUri = exports.makeSelectTitleForUri = exports.makeSelectMetadataForUri = exports.makeSelectClaimsInChannelForCurrentPage = exports.makeSelectClaimsInChannelForPage = exports.makeSelectFetchingChannelClaims = exports.selectAllFetchingChannelClaims = exports.makeSelectClaimIsMine = exports.selectMyActiveClaims = exports.selectAbandoningIds = exports.selectMyClaimsRaw = exports.makeSelectClaimForUri = exports.selectAllClaimsByChannel = exports.selectClaimsByUri = exports.selectClaimsById = undefined; var _lbryURI = __webpack_require__(2); @@ -2793,6 +2866,19 @@ var makeSelectFetchingChannelClaims = exports.makeSelectFetchingChannelClaims = }); }; +var makeSelectClaimsInChannelForPage = exports.makeSelectClaimsInChannelForPage = function makeSelectClaimsInChannelForPage(uri, page) { + return (0, _reselect.createSelector)(selectClaimsById, selectAllClaimsByChannel, function (byId, allClaims) { + var byChannel = allClaims[uri] || {}; + var claimIds = byChannel[page || 1]; + + if (!claimIds) return claimIds; + + return claimIds.map(function (claimId) { + return byId[claimId]; + }); + }); +}; + var makeSelectClaimsInChannelForCurrentPage = exports.makeSelectClaimsInChannelForCurrentPage = function makeSelectClaimsInChannelForCurrentPage(uri) { var pageSelector = (0, _navigation.makeSelectCurrentParam)('page'); diff --git a/src/index.js b/src/index.js index c6f8ab7..be4160d 100644 --- a/src/index.js +++ b/src/index.js @@ -28,6 +28,8 @@ export { export { doNotify, doHideNotification } from 'redux/actions/notifications'; export { + doFetchClaimsByChannel, + doFetchClaimCountByChannel, doFetchClaimListMine, doAbandonClaim, doResolveUris, @@ -94,6 +96,7 @@ export { makeSelectClaimIsMine, makeSelectFetchingChannelClaims, makeSelectClaimsInChannelForCurrentPage, + makeSelectClaimsInChannelForPage, makeSelectMetadataForUri, makeSelectTitleForUri, makeSelectContentTypeForUri, diff --git a/src/lbry.js b/src/lbry.js index 8cbb84e..8f64a20 100644 --- a/src/lbry.js +++ b/src/lbry.js @@ -67,6 +67,9 @@ Lbry.version = () => daemonCallWithResult('version', {}); Lbry.file_delete = (params = {}) => daemonCallWithResult('file_delete', params); Lbry.file_set_status = (params = {}) => daemonCallWithResult('file_set_status', params); +// claims +Lbry.claim_list_by_channel = (params = {}) => daemonCallWithResult('claim_list_by_channel', params); + // wallet Lbry.wallet_balance = (params = {}) => daemonCallWithResult('wallet_balance', params); Lbry.wallet_is_address_mine = (params = {}) => diff --git a/src/redux/actions/claims.js b/src/redux/actions/claims.js index 8fa939b..8a3ee7f 100644 --- a/src/redux/actions/claims.js +++ b/src/redux/actions/claims.js @@ -186,3 +186,48 @@ export function doFetchRewardedContent() { Lbryapi.call('reward', 'list_featured').then(success, failure); }; } + +export function doFetchClaimsByChannel(uri, page) { + return dispatch => { + dispatch({ + type: ACTIONS.FETCH_CHANNEL_CLAIMS_STARTED, + data: { uri, page }, + }); + + Lbry.claim_list_by_channel({ uri, page: page || 1 }).then(result => { + const claimResult = result[uri] || {}; + const { claims_in_channel: claimsInChannel, returned_page: returnedPage } = claimResult; + + dispatch({ + type: ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED, + data: { + uri, + claims: claimsInChannel || [], + page: returnedPage || undefined, + }, + }); + }); + }; +} + +export function doFetchClaimCountByChannel(uri) { + return dispatch => { + dispatch({ + type: ACTIONS.FETCH_CHANNEL_CLAIM_COUNT_STARTED, + data: { uri }, + }); + + Lbry.claim_list_by_channel({ uri }).then(result => { + const claimResult = result[uri]; + const totalClaims = claimResult ? claimResult.claims_in_channel : 0; + + dispatch({ + type: ACTIONS.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED, + data: { + uri, + totalClaims, + }, + }); + }); + }; +} diff --git a/src/redux/selectors/claims.js b/src/redux/selectors/claims.js index 489eabb..526e657 100644 --- a/src/redux/selectors/claims.js +++ b/src/redux/selectors/claims.js @@ -70,6 +70,16 @@ export const selectAllFetchingChannelClaims = createSelector( export const makeSelectFetchingChannelClaims = uri => createSelector(selectAllFetchingChannelClaims, fetching => fetching && fetching[uri]); +export const makeSelectClaimsInChannelForPage = (uri, page) => + createSelector(selectClaimsById, selectAllClaimsByChannel, (byId, allClaims) => { + const byChannel = allClaims[uri] || {}; + const claimIds = byChannel[page || 1]; + + if (!claimIds) return claimIds; + + return claimIds.map(claimId => byId[claimId]); + }); + export const makeSelectClaimsInChannelForCurrentPage = uri => { const pageSelector = makeSelectCurrentParam('page'); -- 2.45.2