doFetchViewCount: support multiple claimIds
## Issue Show content view counts on channel pages (https://github.com/lbryio/lbry-desktop/issues/3587) ## Changes Updated the action and reducer to handle CSV input. This wouldn't affect existing clients as it is backward compatible with a single claimId. In the unlikely event that requested count !== results count, we just fail silently for now.
This commit is contained in:
parent
6fa738e3b8
commit
0b4e41ef90
5 changed files with 52 additions and 25 deletions
27
dist/bundle.es.js
vendored
27
dist/bundle.es.js
vendored
|
@ -759,19 +759,19 @@ function doFetchTrendingUris() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
const doFetchViewCount = claimId => dispatch => {
|
const doFetchViewCount = claimIdCsv => dispatch => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: FETCH_VIEW_COUNT_STARTED
|
type: FETCH_VIEW_COUNT_STARTED
|
||||||
});
|
});
|
||||||
return Lbryio.call('file', 'view_count', {
|
return Lbryio.call('file', 'view_count', {
|
||||||
claim_id: claimId
|
claim_id: claimIdCsv
|
||||||
}).then(result => {
|
}).then(result => {
|
||||||
const viewCount = result[0];
|
const viewCounts = result;
|
||||||
dispatch({
|
dispatch({
|
||||||
type: FETCH_VIEW_COUNT_COMPLETED,
|
type: FETCH_VIEW_COUNT_COMPLETED,
|
||||||
data: {
|
data: {
|
||||||
claimId,
|
claimIdCsv,
|
||||||
viewCount
|
viewCounts
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
@ -1318,12 +1318,18 @@ const statsReducer = handleActions({
|
||||||
}),
|
}),
|
||||||
[FETCH_VIEW_COUNT_COMPLETED]: (state, action) => {
|
[FETCH_VIEW_COUNT_COMPLETED]: (state, action) => {
|
||||||
const {
|
const {
|
||||||
claimId,
|
claimIdCsv,
|
||||||
viewCount
|
viewCounts
|
||||||
} = action.data;
|
} = action.data;
|
||||||
const viewCountById = { ...state.viewCountById,
|
const viewCountById = Object.assign({}, state.viewCountById);
|
||||||
[claimId]: viewCount
|
const claimIds = claimIdCsv.split(',');
|
||||||
};
|
|
||||||
|
if (claimIds.length === viewCounts.length) {
|
||||||
|
claimIds.forEach((claimId, index) => {
|
||||||
|
viewCountById[claimId] = viewCounts[index];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return { ...state,
|
return { ...state,
|
||||||
fetchingViewCount: false,
|
fetchingViewCount: false,
|
||||||
viewCountById
|
viewCountById
|
||||||
|
@ -1599,6 +1605,7 @@ exports.selectSyncData = selectSyncData;
|
||||||
exports.selectSyncHash = selectSyncHash;
|
exports.selectSyncHash = selectSyncHash;
|
||||||
exports.selectTrendingUris = selectTrendingUris;
|
exports.selectTrendingUris = selectTrendingUris;
|
||||||
exports.selectUploadCount = selectUploadCount;
|
exports.selectUploadCount = selectUploadCount;
|
||||||
|
exports.selectViewCount = selectViewCount;
|
||||||
exports.statsReducer = statsReducer;
|
exports.statsReducer = statsReducer;
|
||||||
exports.syncReducer = syncReducer;
|
exports.syncReducer = syncReducer;
|
||||||
exports.webReducer = webReducer;
|
exports.webReducer = webReducer;
|
||||||
|
|
24
dist/bundle.js
vendored
24
dist/bundle.js
vendored
|
@ -210,6 +210,8 @@ __webpack_require__.r(__webpack_exports__);
|
||||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectFetchingTrendingUris", function() { return redux_selectors_homepage__WEBPACK_IMPORTED_MODULE_25__["selectFetchingTrendingUris"]; });
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectFetchingTrendingUris", function() { return redux_selectors_homepage__WEBPACK_IMPORTED_MODULE_25__["selectFetchingTrendingUris"]; });
|
||||||
|
|
||||||
/* harmony import */ var redux_selectors_stats__WEBPACK_IMPORTED_MODULE_26__ = __webpack_require__(38);
|
/* harmony import */ var redux_selectors_stats__WEBPACK_IMPORTED_MODULE_26__ = __webpack_require__(38);
|
||||||
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectViewCount", function() { return redux_selectors_stats__WEBPACK_IMPORTED_MODULE_26__["selectViewCount"]; });
|
||||||
|
|
||||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeSelectViewCountForUri", function() { return redux_selectors_stats__WEBPACK_IMPORTED_MODULE_26__["makeSelectViewCountForUri"]; });
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeSelectViewCountForUri", function() { return redux_selectors_stats__WEBPACK_IMPORTED_MODULE_26__["makeSelectViewCountForUri"]; });
|
||||||
|
|
||||||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeSelectSubCountForUri", function() { return redux_selectors_stats__WEBPACK_IMPORTED_MODULE_26__["makeSelectSubCountForUri"]; });
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeSelectSubCountForUri", function() { return redux_selectors_stats__WEBPACK_IMPORTED_MODULE_26__["makeSelectSubCountForUri"]; });
|
||||||
|
@ -3476,20 +3478,20 @@ __webpack_require__.r(__webpack_exports__);
|
||||||
/* 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);
|
||||||
|
|
||||||
|
|
||||||
var doFetchViewCount = function doFetchViewCount(claimId) {
|
var doFetchViewCount = function doFetchViewCount(claimIdCsv) {
|
||||||
return function (dispatch) {
|
return function (dispatch) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_VIEW_COUNT_STARTED"]
|
type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_VIEW_COUNT_STARTED"]
|
||||||
});
|
});
|
||||||
return lbryio__WEBPACK_IMPORTED_MODULE_0__["default"].call('file', 'view_count', {
|
return lbryio__WEBPACK_IMPORTED_MODULE_0__["default"].call('file', 'view_count', {
|
||||||
claim_id: claimId
|
claim_id: claimIdCsv
|
||||||
}).then(function (result) {
|
}).then(function (result) {
|
||||||
var viewCount = result[0];
|
var viewCounts = result;
|
||||||
dispatch({
|
dispatch({
|
||||||
type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_VIEW_COUNT_COMPLETED"],
|
type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_VIEW_COUNT_COMPLETED"],
|
||||||
data: {
|
data: {
|
||||||
claimId: claimId,
|
claimIdCsv: claimIdCsv,
|
||||||
viewCount: viewCount
|
viewCounts: viewCounts
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})["catch"](function (error) {
|
})["catch"](function (error) {
|
||||||
|
@ -4168,10 +4170,16 @@ var statsReducer = Object(util_redux_utils__WEBPACK_IMPORTED_MODULE_0__["handleA
|
||||||
});
|
});
|
||||||
}), _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_VIEW_COUNT_COMPLETED"], function (state, action) {
|
}), _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_VIEW_COUNT_COMPLETED"], function (state, action) {
|
||||||
var _action$data = action.data,
|
var _action$data = action.data,
|
||||||
claimId = _action$data.claimId,
|
claimIdCsv = _action$data.claimIdCsv,
|
||||||
viewCount = _action$data.viewCount;
|
viewCounts = _action$data.viewCounts;
|
||||||
|
var viewCountById = Object.assign({}, state.viewCountById);
|
||||||
|
var claimIds = claimIdCsv.split(',');
|
||||||
|
|
||||||
var viewCountById = _objectSpread({}, state.viewCountById, _defineProperty({}, claimId, viewCount));
|
if (claimIds.length === viewCounts.length) {
|
||||||
|
claimIds.forEach(function (claimId, index) {
|
||||||
|
viewCountById[claimId] = viewCounts[index];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return _objectSpread({}, state, {
|
return _objectSpread({}, state, {
|
||||||
fetchingViewCount: false,
|
fetchingViewCount: false,
|
||||||
|
|
|
@ -58,7 +58,11 @@ export {
|
||||||
selectTrendingUris,
|
selectTrendingUris,
|
||||||
selectFetchingTrendingUris,
|
selectFetchingTrendingUris,
|
||||||
} from 'redux/selectors/homepage';
|
} from 'redux/selectors/homepage';
|
||||||
export { makeSelectViewCountForUri, makeSelectSubCountForUri } from 'redux/selectors/stats';
|
export {
|
||||||
|
selectViewCount,
|
||||||
|
makeSelectViewCountForUri,
|
||||||
|
makeSelectSubCountForUri,
|
||||||
|
} from 'redux/selectors/stats';
|
||||||
export {
|
export {
|
||||||
selectHasSyncedWallet,
|
selectHasSyncedWallet,
|
||||||
selectSyncData,
|
selectSyncData,
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
import Lbryio from 'lbryio';
|
import Lbryio from 'lbryio';
|
||||||
import * as ACTIONS from 'constants/action_types';
|
import * as ACTIONS from 'constants/action_types';
|
||||||
|
|
||||||
export const doFetchViewCount = (claimId: string) => dispatch => {
|
export const doFetchViewCount = (claimIdCsv: string) => dispatch => {
|
||||||
dispatch({ type: ACTIONS.FETCH_VIEW_COUNT_STARTED });
|
dispatch({ type: ACTIONS.FETCH_VIEW_COUNT_STARTED });
|
||||||
|
|
||||||
return Lbryio.call('file', 'view_count', { claim_id: claimId })
|
return Lbryio.call('file', 'view_count', { claim_id: claimIdCsv })
|
||||||
.then((result: Array<number>) => {
|
.then((result: Array<number>) => {
|
||||||
const viewCount = result[0];
|
const viewCounts = result;
|
||||||
dispatch({ type: ACTIONS.FETCH_VIEW_COUNT_COMPLETED, data: { claimId, viewCount } });
|
dispatch({ type: ACTIONS.FETCH_VIEW_COUNT_COMPLETED, data: { claimIdCsv, viewCounts } });
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
dispatch({ type: ACTIONS.FETCH_VIEW_COUNT_FAILED, data: error });
|
dispatch({ type: ACTIONS.FETCH_VIEW_COUNT_FAILED, data: error });
|
||||||
|
|
|
@ -18,9 +18,17 @@ export const statsReducer = handleActions(
|
||||||
viewCountError: action.data,
|
viewCountError: action.data,
|
||||||
}),
|
}),
|
||||||
[ACTIONS.FETCH_VIEW_COUNT_COMPLETED]: (state, action) => {
|
[ACTIONS.FETCH_VIEW_COUNT_COMPLETED]: (state, action) => {
|
||||||
const { claimId, viewCount } = action.data;
|
const { claimIdCsv, viewCounts } = action.data;
|
||||||
|
|
||||||
|
const viewCountById = Object.assign({}, state.viewCountById);
|
||||||
|
const claimIds = claimIdCsv.split(',');
|
||||||
|
|
||||||
|
if (claimIds.length === viewCounts.length) {
|
||||||
|
claimIds.forEach((claimId, index) => {
|
||||||
|
viewCountById[claimId] = viewCounts[index];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const viewCountById = { ...state.viewCountById, [claimId]: viewCount };
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
fetchingViewCount: false,
|
fetchingViewCount: false,
|
||||||
|
|
Loading…
Reference in a new issue