From 42dcd34d49606d2fefa8b039f5f89f367fc7c0cf Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Wed, 14 Apr 2021 11:40:36 -0400 Subject: [PATCH] trigger file/view event for livestream claims --- ui/component/fileSubtitle/view.jsx | 11 ++++----- ui/component/fileTitleSection/view.jsx | 15 ++++-------- ui/component/fileViewCount/index.js | 10 ++++---- ui/component/fileViewCount/view.jsx | 32 +++++++++++++++++++++----- ui/component/livestreamLayout/view.jsx | 8 +------ 5 files changed, 41 insertions(+), 35 deletions(-) diff --git a/ui/component/fileSubtitle/view.jsx b/ui/component/fileSubtitle/view.jsx index 91e1ae802..2c80c0539 100644 --- a/ui/component/fileSubtitle/view.jsx +++ b/ui/component/fileSubtitle/view.jsx @@ -8,21 +8,18 @@ type Props = { uri: string, livestream?: boolean, activeViewers?: number, - stateOfViewers: string, + isLive?: boolean, }; function FileSubtitle(props: Props) { - const { uri, livestream = false, activeViewers = 0, stateOfViewers } = props; + const { uri, livestream = false, activeViewers, isLive = false } = props; return (
{livestream ? {__('Right now')} : } - {livestream ? ( - {__('%viewer_count% currently %viewer_state%', { viewer_count: activeViewers, viewer_state: stateOfViewers })} - ) : ( - - )} + +
diff --git a/ui/component/fileTitleSection/view.jsx b/ui/component/fileTitleSection/view.jsx index 989fc0078..0d00b9a67 100644 --- a/ui/component/fileTitleSection/view.jsx +++ b/ui/component/fileTitleSection/view.jsx @@ -20,12 +20,12 @@ type Props = { nsfw: boolean, isNsfwBlocked: boolean, livestream?: boolean, + isLive?: boolean, activeViewers?: number, - stateOfViewers: string, }; function FileTitleSection(props: Props) { - const { title, uri, nsfw, isNsfwBlocked, livestream = false, activeViewers, stateOfViewers } = props; + const { title, uri, nsfw, isNsfwBlocked, livestream = false, isLive = false, activeViewers } = props; const [hasAcknowledgedSec, setHasAcknowledgedSec] = usePersistedState('sec-nag', false); return ( @@ -35,9 +35,7 @@ function FileTitleSection(props: Props) {
@@ -59,12 +57,7 @@ function FileTitleSection(props: Props) { body={ - + } actions={ diff --git a/ui/component/fileViewCount/index.js b/ui/component/fileViewCount/index.js index b5a935b67..d2c7af7eb 100644 --- a/ui/component/fileViewCount/index.js +++ b/ui/component/fileViewCount/index.js @@ -1,15 +1,17 @@ import { connect } from 'react-redux'; -import { doFetchViewCount, makeSelectViewCountForUri } from 'lbryinc'; -import FileViewCount from './view'; import { makeSelectClaimForUri } from 'lbry-redux'; +import { doFetchViewCount, makeSelectViewCountForUri } from 'lbryinc'; +import { doAnalyticsView } from 'redux/actions/app'; +import FileViewCount from './view'; const select = (state, props) => ({ claim: makeSelectClaimForUri(props.uri)(state), viewCount: makeSelectViewCountForUri(props.uri)(state), }); -const perform = dispatch => ({ - fetchViewCount: claimId => dispatch(doFetchViewCount(claimId)), +const perform = (dispatch) => ({ + fetchViewCount: (claimId) => dispatch(doFetchViewCount(claimId)), + doAnalyticsView: (uri) => dispatch(doAnalyticsView(uri)), }); export default connect(select, perform)(FileViewCount); diff --git a/ui/component/fileViewCount/view.jsx b/ui/component/fileViewCount/view.jsx index fa0d2aab5..41b5db9ab 100644 --- a/ui/component/fileViewCount/view.jsx +++ b/ui/component/fileViewCount/view.jsx @@ -1,19 +1,32 @@ // @flow -import React, { useEffect } from 'react'; +import { SIMPLE_SITE } from 'config'; +import React from 'react'; import HelpLink from 'component/common/help-link'; type Props = { claim: ?StreamClaim, - fetchViewCount: string => void, + fetchViewCount: (string) => void, uri: string, viewCount: string, + livestream?: boolean, + activeViewers?: number, + isLive?: boolean, + doAnalyticsView: (string) => void, }; function FileViewCount(props: Props) { - const { claim, uri, fetchViewCount, viewCount } = props; + const { claim, uri, fetchViewCount, viewCount, livestream, activeViewers, isLive = false, doAnalyticsView } = props; const claimId = claim && claim.claim_id; - useEffect(() => { + React.useEffect(() => { + if (livestream) { + // Regular claims will call the file/view event when a user actually watches the claim + // This can be removed when we get rid of the livestream iframe + doAnalyticsView(uri); + } + }, [livestream, doAnalyticsView, uri]); + + React.useEffect(() => { if (claimId) { fetchViewCount(claimId); } @@ -23,8 +36,15 @@ function FileViewCount(props: Props) { return ( - {viewCount !== 1 ? __('%view_count% views', { view_count: formattedViewCount }) : __('1 view')} - + {activeViewers !== undefined + ? __('%viewer_count% currently %viewer_state%', { + viewer_count: activeViewers, + viewer_state: isLive ? __('watching') : __('waiting'), + }) + : viewCount !== 1 + ? __('%view_count% views', { view_count: formattedViewCount }) + : __('1 view')} + {!SIMPLE_SITE && } ); } diff --git a/ui/component/livestreamLayout/view.jsx b/ui/component/livestreamLayout/view.jsx index 537765495..85c35cd0c 100644 --- a/ui/component/livestreamLayout/view.jsx +++ b/ui/component/livestreamLayout/view.jsx @@ -41,13 +41,7 @@ export default function LivestreamLayout(props: Props) { })} )} - +