feat: add sub counts

This commit is contained in:
Thomas Zarebczan 2019-09-24 22:30:53 -04:00
parent d250096a6f
commit 4a1647a41e
7 changed files with 175 additions and 9 deletions

60
dist/bundle.es.js vendored
View file

@ -72,11 +72,14 @@ const FETCH_FILTERED_CONTENT_FAILED = 'FETCH_FILTERED_CONTENT_FAILED';
const FILTERED_CONTENT_SUBSCRIBE = 'FILTERED_CONTENT_SUBSCRIBE'; // Cost Info const FILTERED_CONTENT_SUBSCRIBE = 'FILTERED_CONTENT_SUBSCRIBE'; // Cost Info
const FETCH_COST_INFO_STARTED = 'FETCH_COST_INFO_STARTED'; const FETCH_COST_INFO_STARTED = 'FETCH_COST_INFO_STARTED';
const FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; // File Stats const FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; // Stats
const FETCH_VIEW_COUNT_STARTED = 'FETCH_VIEW_COUNT_STARTED'; const FETCH_VIEW_COUNT_STARTED = 'FETCH_VIEW_COUNT_STARTED';
const FETCH_VIEW_COUNT_FAILED = 'FETCH_VIEW_COUNT_FAILED'; const FETCH_VIEW_COUNT_FAILED = 'FETCH_VIEW_COUNT_FAILED';
const FETCH_VIEW_COUNT_COMPLETED = 'FETCH_VIEW_COUNT_COMPLETED'; // Cross-device Sync const FETCH_VIEW_COUNT_COMPLETED = 'FETCH_VIEW_COUNT_COMPLETED';
const FETCH_SUB_COUNT_STARTED = 'FETCH_SUB_COUNT_STARTED';
const FETCH_SUB_COUNT_FAILED = 'FETCH_SUB_COUNT_FAILED';
const FETCH_SUB_COUNT_COMPLETED = 'FETCH_SUB_COUNT_COMPLETED'; // Cross-device Sync
const GET_SYNC_STARTED = 'GET_SYNC_STARTED'; const GET_SYNC_STARTED = 'GET_SYNC_STARTED';
const GET_SYNC_COMPLETED = 'GET_SYNC_COMPLETED'; const GET_SYNC_COMPLETED = 'GET_SYNC_COMPLETED';
@ -151,6 +154,9 @@ var action_types = /*#__PURE__*/Object.freeze({
FETCH_VIEW_COUNT_STARTED: FETCH_VIEW_COUNT_STARTED, FETCH_VIEW_COUNT_STARTED: FETCH_VIEW_COUNT_STARTED,
FETCH_VIEW_COUNT_FAILED: FETCH_VIEW_COUNT_FAILED, FETCH_VIEW_COUNT_FAILED: FETCH_VIEW_COUNT_FAILED,
FETCH_VIEW_COUNT_COMPLETED: FETCH_VIEW_COUNT_COMPLETED, FETCH_VIEW_COUNT_COMPLETED: FETCH_VIEW_COUNT_COMPLETED,
FETCH_SUB_COUNT_STARTED: FETCH_SUB_COUNT_STARTED,
FETCH_SUB_COUNT_FAILED: FETCH_SUB_COUNT_FAILED,
FETCH_SUB_COUNT_COMPLETED: FETCH_SUB_COUNT_COMPLETED,
GET_SYNC_STARTED: GET_SYNC_STARTED, GET_SYNC_STARTED: GET_SYNC_STARTED,
GET_SYNC_COMPLETED: GET_SYNC_COMPLETED, GET_SYNC_COMPLETED: GET_SYNC_COMPLETED,
SET_SYNC_STARTED: SET_SYNC_STARTED, SET_SYNC_STARTED: SET_SYNC_STARTED,
@ -2166,6 +2172,28 @@ const doFetchViewCount = claimId => dispatch => {
}); });
}); });
}; };
const doFetchSubCount = claimId => dispatch => {
dispatch({
type: FETCH_SUB_COUNT_STARTED
});
return Lbryio.call('subscription', 'sub_count', {
claim_id: claimId
}).then(result => {
const subCount = result[0];
dispatch({
type: FETCH_SUB_COUNT_COMPLETED,
data: {
claimId,
subCount
}
});
}).catch(error => {
dispatch({
type: FETCH_SUB_COUNT_FAILED,
data: error
});
});
};
function doSetSync(oldHash, newHash, data) { function doSetSync(oldHash, newHash, data) {
return dispatch => { return dispatch => {
@ -2864,7 +2892,10 @@ const homepageReducer = handleActions({
const defaultState$8 = { const defaultState$8 = {
fetchingViewCount: false, fetchingViewCount: false,
viewCountError: undefined, viewCountError: undefined,
viewCountById: {} viewCountById: {},
fetchingSubCount: false,
subCountError: undefined,
subCountById: {}
}; };
const statsReducer = handleActions({ const statsReducer = handleActions({
[FETCH_VIEW_COUNT_STARTED]: state => ({ ...state, [FETCH_VIEW_COUNT_STARTED]: state => ({ ...state,
@ -2885,6 +2916,25 @@ const statsReducer = handleActions({
fetchingViewCount: false, fetchingViewCount: false,
viewCountById viewCountById
}; };
},
[FETCH_SUB_COUNT_STARTED]: state => ({ ...state,
fetchingSubCount: true
}),
[FETCH_SUB_COUNT_FAILED]: (state, action) => ({ ...state,
subCountError: action.data
}),
[FETCH_SUB_COUNT_COMPLETED]: (state, action) => {
const {
claimId,
subCount
} = action.data;
const subCountById = { ...state.subCountById,
[claimId]: subCount
};
return { ...state,
fetchingSubCount: false,
subCountById
};
} }
}, defaultState$8); }, defaultState$8);
@ -2979,7 +3029,9 @@ const selectFetchingTrendingUris = reselect.createSelector(selectState$7, state
const selectState$8 = state => state.stats || {}; const selectState$8 = state => state.stats || {};
const selectViewCount = reselect.createSelector(selectState$8, state => state.viewCountById); const selectViewCount = reselect.createSelector(selectState$8, state => state.viewCountById);
const selectSubCount = reselect.createSelector(selectState$8, state => state.subCountById);
const makeSelectViewCountForUri = uri => reselect.createSelector(lbryRedux.makeSelectClaimForUri(uri), selectViewCount, (claim, viewCountById) => viewCountById[claim.claim_id] || 0); const makeSelectViewCountForUri = uri => reselect.createSelector(lbryRedux.makeSelectClaimForUri(uri), selectViewCount, (claim, viewCountById) => viewCountById[claim.claim_id] || 0);
const makeSelectSubCountForUri = uri => reselect.createSelector(lbryRedux.makeSelectClaimForUri(uri), selectSubCount, (claim, subCountById) => subCountById[claim.claim_id] || 0);
const selectState$9 = state => state.sync || {}; const selectState$9 = state => state.sync || {};
@ -3020,6 +3072,7 @@ exports.doFetchInviteStatus = doFetchInviteStatus;
exports.doFetchMySubscriptions = doFetchMySubscriptions; exports.doFetchMySubscriptions = doFetchMySubscriptions;
exports.doFetchRecommendedSubscriptions = doFetchRecommendedSubscriptions; exports.doFetchRecommendedSubscriptions = doFetchRecommendedSubscriptions;
exports.doFetchRewardedContent = doFetchRewardedContent; exports.doFetchRewardedContent = doFetchRewardedContent;
exports.doFetchSubCount = doFetchSubCount;
exports.doFetchTrendingUris = doFetchTrendingUris; exports.doFetchTrendingUris = doFetchTrendingUris;
exports.doFetchViewCount = doFetchViewCount; exports.doFetchViewCount = doFetchViewCount;
exports.doFilteredOutpointsSubscribe = doFilteredOutpointsSubscribe; exports.doFilteredOutpointsSubscribe = doFilteredOutpointsSubscribe;
@ -3058,6 +3111,7 @@ exports.makeSelectIsRewardClaimPending = makeSelectIsRewardClaimPending;
exports.makeSelectIsSubscribed = makeSelectIsSubscribed; exports.makeSelectIsSubscribed = makeSelectIsSubscribed;
exports.makeSelectRewardAmountByType = makeSelectRewardAmountByType; exports.makeSelectRewardAmountByType = makeSelectRewardAmountByType;
exports.makeSelectRewardByType = makeSelectRewardByType; exports.makeSelectRewardByType = makeSelectRewardByType;
exports.makeSelectSubCountForUri = makeSelectSubCountForUri;
exports.makeSelectUnreadByChannel = makeSelectUnreadByChannel; exports.makeSelectUnreadByChannel = makeSelectUnreadByChannel;
exports.makeSelectViewCountForUri = makeSelectViewCountForUri; exports.makeSelectViewCountForUri = makeSelectViewCountForUri;
exports.rewards = rewards; exports.rewards = rewards;

73
dist/bundle.js vendored
View file

@ -215,6 +215,8 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var redux_actions_stats__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(26); /* harmony import */ var redux_actions_stats__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(26);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doFetchViewCount", function() { return redux_actions_stats__WEBPACK_IMPORTED_MODULE_13__["doFetchViewCount"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doFetchViewCount", function() { return redux_actions_stats__WEBPACK_IMPORTED_MODULE_13__["doFetchViewCount"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doFetchSubCount", function() { return redux_actions_stats__WEBPACK_IMPORTED_MODULE_13__["doFetchSubCount"]; });
/* harmony import */ var redux_actions_sync__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(27); /* harmony import */ var redux_actions_sync__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(27);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doCheckSync", function() { return redux_actions_sync__WEBPACK_IMPORTED_MODULE_14__["doCheckSync"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doCheckSync", function() { return redux_actions_sync__WEBPACK_IMPORTED_MODULE_14__["doCheckSync"]; });
@ -416,6 +418,8 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var redux_selectors_stats__WEBPACK_IMPORTED_MODULE_32__ = __webpack_require__(42); /* harmony import */ var redux_selectors_stats__WEBPACK_IMPORTED_MODULE_32__ = __webpack_require__(42);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeSelectViewCountForUri", function() { return redux_selectors_stats__WEBPACK_IMPORTED_MODULE_32__["makeSelectViewCountForUri"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeSelectViewCountForUri", function() { return redux_selectors_stats__WEBPACK_IMPORTED_MODULE_32__["makeSelectViewCountForUri"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeSelectSubCountForUri", function() { return redux_selectors_stats__WEBPACK_IMPORTED_MODULE_32__["makeSelectSubCountForUri"]; });
/* harmony import */ var redux_selectors_sync__WEBPACK_IMPORTED_MODULE_33__ = __webpack_require__(43); /* harmony import */ var redux_selectors_sync__WEBPACK_IMPORTED_MODULE_33__ = __webpack_require__(43);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectHasSyncedWallet", function() { return redux_selectors_sync__WEBPACK_IMPORTED_MODULE_33__["selectHasSyncedWallet"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectHasSyncedWallet", function() { return redux_selectors_sync__WEBPACK_IMPORTED_MODULE_33__["selectHasSyncedWallet"]; });
@ -547,6 +551,9 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_VIEW_COUNT_STARTED", function() { return FETCH_VIEW_COUNT_STARTED; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_VIEW_COUNT_STARTED", function() { return FETCH_VIEW_COUNT_STARTED; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_VIEW_COUNT_FAILED", function() { return FETCH_VIEW_COUNT_FAILED; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_VIEW_COUNT_FAILED", function() { return FETCH_VIEW_COUNT_FAILED; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_VIEW_COUNT_COMPLETED", function() { return FETCH_VIEW_COUNT_COMPLETED; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_VIEW_COUNT_COMPLETED", function() { return FETCH_VIEW_COUNT_COMPLETED; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_SUB_COUNT_STARTED", function() { return FETCH_SUB_COUNT_STARTED; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_SUB_COUNT_FAILED", function() { return FETCH_SUB_COUNT_FAILED; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_SUB_COUNT_COMPLETED", function() { return FETCH_SUB_COUNT_COMPLETED; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GET_SYNC_STARTED", function() { return GET_SYNC_STARTED; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GET_SYNC_STARTED", function() { return GET_SYNC_STARTED; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GET_SYNC_COMPLETED", function() { return GET_SYNC_COMPLETED; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GET_SYNC_COMPLETED", function() { return GET_SYNC_COMPLETED; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SET_SYNC_STARTED", function() { return SET_SYNC_STARTED; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SET_SYNC_STARTED", function() { return SET_SYNC_STARTED; });
@ -620,11 +627,14 @@ var FETCH_FILTERED_CONTENT_FAILED = 'FETCH_FILTERED_CONTENT_FAILED';
var FILTERED_CONTENT_SUBSCRIBE = 'FILTERED_CONTENT_SUBSCRIBE'; // Cost Info var FILTERED_CONTENT_SUBSCRIBE = 'FILTERED_CONTENT_SUBSCRIBE'; // Cost Info
var FETCH_COST_INFO_STARTED = 'FETCH_COST_INFO_STARTED'; var FETCH_COST_INFO_STARTED = 'FETCH_COST_INFO_STARTED';
var FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; // File Stats var FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; // Stats
var FETCH_VIEW_COUNT_STARTED = 'FETCH_VIEW_COUNT_STARTED'; var FETCH_VIEW_COUNT_STARTED = 'FETCH_VIEW_COUNT_STARTED';
var FETCH_VIEW_COUNT_FAILED = 'FETCH_VIEW_COUNT_FAILED'; var FETCH_VIEW_COUNT_FAILED = 'FETCH_VIEW_COUNT_FAILED';
var FETCH_VIEW_COUNT_COMPLETED = 'FETCH_VIEW_COUNT_COMPLETED'; // Cross-device Sync var FETCH_VIEW_COUNT_COMPLETED = 'FETCH_VIEW_COUNT_COMPLETED';
var FETCH_SUB_COUNT_STARTED = 'FETCH_SUB_COUNT_STARTED';
var FETCH_SUB_COUNT_FAILED = 'FETCH_SUB_COUNT_FAILED';
var FETCH_SUB_COUNT_COMPLETED = 'FETCH_SUB_COUNT_COMPLETED'; // Cross-device Sync
var GET_SYNC_STARTED = 'GET_SYNC_STARTED'; var GET_SYNC_STARTED = 'GET_SYNC_STARTED';
var GET_SYNC_COMPLETED = 'GET_SYNC_COMPLETED'; var GET_SYNC_COMPLETED = 'GET_SYNC_COMPLETED';
@ -3664,6 +3674,7 @@ function doFetchTrendingUris() {
"use strict"; "use strict";
__webpack_require__.r(__webpack_exports__); __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doFetchViewCount", function() { return doFetchViewCount; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doFetchViewCount", function() { return doFetchViewCount; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doFetchSubCount", function() { return doFetchSubCount; });
/* harmony import */ var lbryio__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2); /* harmony import */ var lbryio__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
/* harmony import */ var constants_action_types__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1); /* harmony import */ var constants_action_types__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
@ -3692,6 +3703,30 @@ var doFetchViewCount = function doFetchViewCount(claimId) {
}); });
}; };
}; };
var doFetchSubCount = function doFetchSubCount(claimId) {
return function (dispatch) {
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_SUB_COUNT_STARTED"]
});
return lbryio__WEBPACK_IMPORTED_MODULE_0__["default"].call('subscription', 'sub_count', {
claim_id: claimId
}).then(function (result) {
var subCount = result[0];
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_SUB_COUNT_COMPLETED"],
data: {
claimId: claimId,
subCount: subCount
}
});
})["catch"](function (error) {
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_SUB_COUNT_FAILED"],
data: error
});
});
};
};
/***/ }), /***/ }),
/* 27 */ /* 27 */
@ -4574,7 +4609,10 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
var defaultState = { var defaultState = {
fetchingViewCount: false, fetchingViewCount: false,
viewCountError: undefined, viewCountError: undefined,
viewCountById: {} viewCountById: {},
fetchingSubCount: false,
subCountError: undefined,
subCountById: {}
}; };
var statsReducer = Object(util_redux_utils__WEBPACK_IMPORTED_MODULE_0__["handleActions"])((_handleActions = {}, _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_VIEW_COUNT_STARTED"], function (state) { var statsReducer = Object(util_redux_utils__WEBPACK_IMPORTED_MODULE_0__["handleActions"])((_handleActions = {}, _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_VIEW_COUNT_STARTED"], function (state) {
return _objectSpread({}, state, { return _objectSpread({}, state, {
@ -4595,6 +4633,25 @@ var statsReducer = Object(util_redux_utils__WEBPACK_IMPORTED_MODULE_0__["handleA
fetchingViewCount: false, fetchingViewCount: false,
viewCountById: viewCountById viewCountById: viewCountById
}); });
}), _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_SUB_COUNT_STARTED"], function (state) {
return _objectSpread({}, state, {
fetchingSubCount: true
});
}), _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_SUB_COUNT_FAILED"], function (state, action) {
return _objectSpread({}, state, {
subCountError: action.data
});
}), _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_SUB_COUNT_COMPLETED"], function (state, action) {
var _action$data2 = action.data,
claimId = _action$data2.claimId,
subCount = _action$data2.subCount;
var subCountById = _objectSpread({}, state.subCountById, _defineProperty({}, claimId, subCount));
return _objectSpread({}, state, {
fetchingSubCount: false,
subCountById: subCountById
});
}), _handleActions), defaultState); }), _handleActions), defaultState);
/***/ }), /***/ }),
@ -4819,7 +4876,9 @@ var selectFetchingTrendingUris = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["c
"use strict"; "use strict";
__webpack_require__.r(__webpack_exports__); __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectViewCount", function() { return selectViewCount; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectViewCount", function() { return selectViewCount; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectSubCount", function() { return selectSubCount; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "makeSelectViewCountForUri", function() { return makeSelectViewCountForUri; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "makeSelectViewCountForUri", function() { return makeSelectViewCountForUri; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "makeSelectSubCountForUri", function() { return makeSelectSubCountForUri; });
/* harmony import */ var reselect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(13); /* harmony import */ var reselect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(13);
/* harmony import */ var reselect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(reselect__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var reselect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(reselect__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var lbry_redux__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3); /* harmony import */ var lbry_redux__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
@ -4834,11 +4893,19 @@ var selectState = function selectState(state) {
var selectViewCount = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) { var selectViewCount = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
return state.viewCountById; return state.viewCountById;
}); });
var selectSubCount = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) {
return state.subCountById;
});
var makeSelectViewCountForUri = function makeSelectViewCountForUri(uri) { var makeSelectViewCountForUri = function makeSelectViewCountForUri(uri) {
return Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(Object(lbry_redux__WEBPACK_IMPORTED_MODULE_1__["makeSelectClaimForUri"])(uri), selectViewCount, function (claim, viewCountById) { return Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(Object(lbry_redux__WEBPACK_IMPORTED_MODULE_1__["makeSelectClaimForUri"])(uri), selectViewCount, function (claim, viewCountById) {
return viewCountById[claim.claim_id] || 0; return viewCountById[claim.claim_id] || 0;
}); });
}; };
var makeSelectSubCountForUri = function makeSelectSubCountForUri(uri) {
return Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(Object(lbry_redux__WEBPACK_IMPORTED_MODULE_1__["makeSelectClaimForUri"])(uri), selectSubCount, function (claim, subCountById) {
return subCountById[claim.claim_id] || 0;
});
};
/***/ }), /***/ }),
/* 43 */ /* 43 */

View file

@ -71,10 +71,13 @@ export const FILTERED_CONTENT_SUBSCRIBE = 'FILTERED_CONTENT_SUBSCRIBE';
export const FETCH_COST_INFO_STARTED = 'FETCH_COST_INFO_STARTED'; export const FETCH_COST_INFO_STARTED = 'FETCH_COST_INFO_STARTED';
export const FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; export const FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED';
// File Stats // Stats
export const FETCH_VIEW_COUNT_STARTED = 'FETCH_VIEW_COUNT_STARTED'; export const FETCH_VIEW_COUNT_STARTED = 'FETCH_VIEW_COUNT_STARTED';
export const FETCH_VIEW_COUNT_FAILED = 'FETCH_VIEW_COUNT_FAILED'; export const FETCH_VIEW_COUNT_FAILED = 'FETCH_VIEW_COUNT_FAILED';
export const FETCH_VIEW_COUNT_COMPLETED = 'FETCH_VIEW_COUNT_COMPLETED'; export const FETCH_VIEW_COUNT_COMPLETED = 'FETCH_VIEW_COUNT_COMPLETED';
export const FETCH_SUB_COUNT_STARTED = 'FETCH_SUB_COUNT_STARTED';
export const FETCH_SUB_COUNT_FAILED = 'FETCH_SUB_COUNT_FAILED';
export const FETCH_SUB_COUNT_COMPLETED = 'FETCH_SUB_COUNT_COMPLETED';
// Cross-device Sync // Cross-device Sync
export const GET_SYNC_STARTED = 'GET_SYNC_STARTED'; export const GET_SYNC_STARTED = 'GET_SYNC_STARTED';

View file

@ -63,7 +63,7 @@ export { doFetchCostInfoForUri } from 'redux/actions/cost_info';
export { doBlackListedOutpointsSubscribe } from 'redux/actions/blacklist'; export { doBlackListedOutpointsSubscribe } from 'redux/actions/blacklist';
export { doFilteredOutpointsSubscribe } from 'redux/actions/filtered'; export { doFilteredOutpointsSubscribe } from 'redux/actions/filtered';
export { doFetchFeaturedUris, doFetchTrendingUris } from 'redux/actions/homepage'; export { doFetchFeaturedUris, doFetchTrendingUris } from 'redux/actions/homepage';
export { doFetchViewCount } from 'redux/actions/stats'; export { doFetchViewCount, doFetchSubCount } from 'redux/actions/stats';
export { export {
doCheckSync, doCheckSync,
doGetSync, doGetSync,
@ -170,7 +170,7 @@ export {
selectTrendingUris, selectTrendingUris,
selectFetchingTrendingUris, selectFetchingTrendingUris,
} from 'redux/selectors/homepage'; } from 'redux/selectors/homepage';
export { makeSelectViewCountForUri } from 'redux/selectors/stats'; export { makeSelectViewCountForUri, makeSelectSubCountForUri } from 'redux/selectors/stats';
export { export {
selectHasSyncedWallet, selectHasSyncedWallet,
selectSyncData, selectSyncData,

View file

@ -14,3 +14,19 @@ export const doFetchViewCount = (claimId: string) => dispatch => {
dispatch({ type: ACTIONS.FETCH_VIEW_COUNT_FAILED, data: error }); dispatch({ type: ACTIONS.FETCH_VIEW_COUNT_FAILED, data: error });
}); });
}; };
export const doFetchSubCount = (claimId: string) => dispatch => {
dispatch({ type: ACTIONS.FETCH_SUB_COUNT_STARTED });
return Lbryio.call('subscription', 'sub_count', { claim_id: claimId })
.then((result: Array<number>) => {
const subCount = result[0];
dispatch({
type: ACTIONS.FETCH_SUB_COUNT_COMPLETED,
data: { claimId, subCount },
});
})
.catch(error => {
dispatch({ type: ACTIONS.FETCH_SUB_COUNT_FAILED, data: error });
});
};

View file

@ -5,6 +5,9 @@ const defaultState = {
fetchingViewCount: false, fetchingViewCount: false,
viewCountError: undefined, viewCountError: undefined,
viewCountById: {}, viewCountById: {},
fetchingSubCount: false,
subCountError: undefined,
subCountById: {},
}; };
export const statsReducer = handleActions( export const statsReducer = handleActions(
@ -24,6 +27,21 @@ export const statsReducer = handleActions(
viewCountById, viewCountById,
}; };
}, },
[ACTIONS.FETCH_SUB_COUNT_STARTED]: state => ({ ...state, fetchingSubCount: true }),
[ACTIONS.FETCH_SUB_COUNT_FAILED]: (state, action) => ({
...state,
subCountError: action.data,
}),
[ACTIONS.FETCH_SUB_COUNT_COMPLETED]: (state, action) => {
const { claimId, subCount } = action.data;
const subCountById = { ...state.subCountById, [claimId]: subCount };
return {
...state,
fetchingSubCount: false,
subCountById,
};
},
}, },
defaultState defaultState
); );

View file

@ -3,6 +3,7 @@ import { makeSelectClaimForUri } from 'lbry-redux';
const selectState = state => state.stats || {}; const selectState = state => state.stats || {};
export const selectViewCount = createSelector(selectState, state => state.viewCountById); export const selectViewCount = createSelector(selectState, state => state.viewCountById);
export const selectSubCount = createSelector(selectState, state => state.subCountById);
export const makeSelectViewCountForUri = uri => export const makeSelectViewCountForUri = uri =>
createSelector( createSelector(
@ -10,3 +11,10 @@ export const makeSelectViewCountForUri = uri =>
selectViewCount, selectViewCount,
(claim, viewCountById) => viewCountById[claim.claim_id] || 0 (claim, viewCountById) => viewCountById[claim.claim_id] || 0
); );
export const makeSelectSubCountForUri = uri =>
createSelector(
makeSelectClaimForUri(uri),
selectSubCount,
(claim, subCountById) => subCountById[claim.claim_id] || 0
);