From 917125603331d0fa3d659b8e33cd6cd0ff266796 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Thu, 14 Mar 2019 14:40:26 -0400 Subject: [PATCH] add viewcount stats --- package.json | 2 +- src/ui/page/file/index.js | 9 ++++++++- src/ui/page/file/view.jsx | 41 +++++++++++++++++++++++++++++++++------ src/ui/store.js | 2 ++ yarn.lock | 4 ++-- 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 7f00d6e84..644453953 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "keytar": "^4.3.0", "lbry-format": "https://github.com/lbryio/lbry-format.git", "lbry-redux": "lbryio/lbry-redux#f140db38dd73cead9e87549340fa9434da62ba8a", - "lbryinc": "lbryio/lbryinc#636f014f421827ab6b74caf334c364a362a1a099", + "lbryinc": "lbryio/lbryinc#351d0a08806b0f770b50066b61a806171f6424d4", "localforage": "^1.7.1", "mammoth": "^1.4.6", "mime": "^2.3.1", diff --git a/src/ui/page/file/index.js b/src/ui/page/file/index.js index ebaa384dd..c610819af 100644 --- a/src/ui/page/file/index.js +++ b/src/ui/page/file/index.js @@ -14,7 +14,12 @@ import { makeSelectMetadataForUri, makeSelectChannelForClaimUri, } from 'lbry-redux'; -import { makeSelectCostInfoForUri, doFetchCostInfoForUri } from 'lbryinc'; +import { + makeSelectCostInfoForUri, + doFetchCostInfoForUri, + doFetchViewCount, + makeSelectViewCountForUri, +} from 'lbryinc'; import { selectShowNsfw, makeSelectClientSetting } from 'redux/selectors/settings'; import { makeSelectIsSubscribed } from 'redux/selectors/subscriptions'; import { doPrepareEdit } from 'redux/actions/publish'; @@ -34,6 +39,7 @@ const select = (state, props) => ({ autoplay: makeSelectClientSetting(settings.AUTOPLAY)(state), isSubscribed: makeSelectIsSubscribed(props.uri)(state), channelUri: makeSelectChannelForClaimUri(props.uri, true)(state), + viewCount: makeSelectViewCountForUri(props.uri)(state), }); const perform = dispatch => ({ @@ -45,6 +51,7 @@ const perform = dispatch => ({ setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)), setViewed: uri => dispatch(doSetContentHistoryItem(uri)), markSubscriptionRead: (channel, uri) => dispatch(doRemoveUnreadSubscription(channel, uri)), + fetchViewCount: claimId => dispatch(doFetchViewCount(claimId)), }); export default connect( diff --git a/src/ui/page/file/view.jsx b/src/ui/page/file/view.jsx index ab8182d40..d7b6ba712 100644 --- a/src/ui/page/file/view.jsx +++ b/src/ui/page/file/view.jsx @@ -37,10 +37,12 @@ type Props = { isSubscribed: ?string, isSubscribed: boolean, channelUri: string, + viewCount: number, prepareEdit: ({}, string) => void, navigate: (string, ?{}) => void, openModal: (id: string, { uri: string }) => void, markSubscriptionRead: (string, string) => void, + fetchViewCount: string => void, }; class FilePage extends React.Component { @@ -58,11 +60,25 @@ class FilePage extends React.Component { ]; componentDidMount() { - const { uri, fetchFileInfo, fetchCostInfo, setViewed, isSubscribed } = this.props; + const { + uri, + fetchFileInfo, + fetchCostInfo, + setViewed, + isSubscribed, + claimIsMine, + fetchViewCount, + claim, + } = this.props; if (isSubscribed) { this.removeFromSubscriptionNotifications(); } + + if (claimIsMine) { + fetchViewCount(claim.claim_id); + } + // always refresh file info when entering file page fetchFileInfo(uri); @@ -83,9 +99,15 @@ class FilePage extends React.Component { } componentDidUpdate(prevProps: Props) { - if (!prevProps.isSubscribed && this.props.isSubscribed) { + const { isSubscribed, claim, uri, fetchViewCount } = this.props; + + if (!prevProps.isSubscribed && isSubscribed) { this.removeFromSubscriptionNotifications(); } + + if (prevProps.uri !== uri) { + fetchViewCount(claim.claim_id); + } } removeFromSubscriptionNotifications() { @@ -110,6 +132,7 @@ class FilePage extends React.Component { costInfo, fileInfo, channelUri, + viewCount, } = this.props; // File info @@ -182,11 +205,17 @@ class FilePage extends React.Component { -
-
- +
+
+
+ +
+ {__('Published on')} +
+ +
+ {viewCount} {viewCount !== 1 ? __('Views') : __('View')}
- {__('Published on')}
diff --git a/src/ui/store.js b/src/ui/store.js index 1a00e3b6c..0f462462a 100644 --- a/src/ui/store.js +++ b/src/ui/store.js @@ -14,6 +14,7 @@ import { costInfoReducer, blacklistReducer, homepageReducer, + statsReducer, } from 'lbryinc'; import navigationReducer from 'redux/reducers/navigation'; import settingsReducer from 'redux/reducers/settings'; @@ -74,6 +75,7 @@ const reducers = combineReducers({ notifications: notificationsReducer, blacklist: blacklistReducer, homepage: homepageReducer, + stats: statsReducer, }); const bulkThunk = createBulkThunkMiddleware(); diff --git a/yarn.lock b/yarn.lock index dd40e4eba..ab1b6b13b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5980,9 +5980,9 @@ lbry-redux@lbryio/lbry-redux#f140db38dd73cead9e87549340fa9434da62ba8a: reselect "^3.0.0" uuid "^3.3.2" -lbryinc@lbryio/lbryinc#636f014f421827ab6b74caf334c364a362a1a099: +lbryinc@lbryio/lbryinc#0f74a896e1b42b86e3143d79398ab27217901b01: version "0.0.1" - resolved "https://codeload.github.com/lbryio/lbryinc/tar.gz/636f014f421827ab6b74caf334c364a362a1a099" + resolved "https://codeload.github.com/lbryio/lbryinc/tar.gz/0f74a896e1b42b86e3143d79398ab27217901b01" dependencies: bluebird "^3.5.1" reselect "^3.0.0"