trigger file/view event for livestream claims
This commit is contained in:
parent
2d9fac46a5
commit
42dcd34d49
5 changed files with 41 additions and 35 deletions
|
@ -8,21 +8,18 @@ type Props = {
|
||||||
uri: string,
|
uri: string,
|
||||||
livestream?: boolean,
|
livestream?: boolean,
|
||||||
activeViewers?: number,
|
activeViewers?: number,
|
||||||
stateOfViewers: string,
|
isLive?: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
function FileSubtitle(props: Props) {
|
function FileSubtitle(props: Props) {
|
||||||
const { uri, livestream = false, activeViewers = 0, stateOfViewers } = props;
|
const { uri, livestream = false, activeViewers, isLive = false } = props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="media__subtitle--between">
|
<div className="media__subtitle--between">
|
||||||
<div className="file__viewdate">
|
<div className="file__viewdate">
|
||||||
{livestream ? <span>{__('Right now')}</span> : <DateTime uri={uri} show={DateTime.SHOW_DATE} />}
|
{livestream ? <span>{__('Right now')}</span> : <DateTime uri={uri} show={DateTime.SHOW_DATE} />}
|
||||||
{livestream ? (
|
|
||||||
<span>{__('%viewer_count% currently %viewer_state%', { viewer_count: activeViewers, viewer_state: stateOfViewers })}</span>
|
<FileViewCount uri={uri} livestream={livestream} activeViewers={activeViewers} isLive={isLive} />
|
||||||
) : (
|
|
||||||
<FileViewCount uri={uri} />
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<FileActions uri={uri} />
|
<FileActions uri={uri} />
|
||||||
|
|
|
@ -20,12 +20,12 @@ type Props = {
|
||||||
nsfw: boolean,
|
nsfw: boolean,
|
||||||
isNsfwBlocked: boolean,
|
isNsfwBlocked: boolean,
|
||||||
livestream?: boolean,
|
livestream?: boolean,
|
||||||
|
isLive?: boolean,
|
||||||
activeViewers?: number,
|
activeViewers?: number,
|
||||||
stateOfViewers: string,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function FileTitleSection(props: Props) {
|
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);
|
const [hasAcknowledgedSec, setHasAcknowledgedSec] = usePersistedState('sec-nag', false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -35,9 +35,7 @@ function FileTitleSection(props: Props) {
|
||||||
<Button button="close" icon={ICONS.REMOVE} onClick={() => setHasAcknowledgedSec(true)} />
|
<Button button="close" icon={ICONS.REMOVE} onClick={() => setHasAcknowledgedSec(true)} />
|
||||||
<h1 className="section__title">{__('Help LBRY Save Crypto')}</h1>
|
<h1 className="section__title">{__('Help LBRY Save Crypto')}</h1>
|
||||||
<p className="section__subtitle">
|
<p className="section__subtitle">
|
||||||
{__(
|
{__('The US government is attempting to destroy the cryptocurrency industry. Can you help?')}{' '}
|
||||||
'The US government is attempting to destroy the cryptocurrency industry. Can you help?'
|
|
||||||
)}{' '}
|
|
||||||
<Button label={__('Learn more and sign petition')} button="link" href="https://helplbrysavecrypto.com" />
|
<Button label={__('Learn more and sign petition')} button="link" href="https://helplbrysavecrypto.com" />
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -59,12 +57,7 @@ function FileTitleSection(props: Props) {
|
||||||
body={
|
body={
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<ClaimInsufficientCredits uri={uri} />
|
<ClaimInsufficientCredits uri={uri} />
|
||||||
<FileSubtitle
|
<FileSubtitle uri={uri} isLive={isLive} livestream={livestream} activeViewers={activeViewers} />
|
||||||
uri={uri}
|
|
||||||
livestream={livestream}
|
|
||||||
activeViewers={activeViewers}
|
|
||||||
stateOfViewers={stateOfViewers}
|
|
||||||
/>
|
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
}
|
}
|
||||||
actions={
|
actions={
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { doFetchViewCount, makeSelectViewCountForUri } from 'lbryinc';
|
|
||||||
import FileViewCount from './view';
|
|
||||||
import { makeSelectClaimForUri } from 'lbry-redux';
|
import { makeSelectClaimForUri } from 'lbry-redux';
|
||||||
|
import { doFetchViewCount, makeSelectViewCountForUri } from 'lbryinc';
|
||||||
|
import { doAnalyticsView } from 'redux/actions/app';
|
||||||
|
import FileViewCount from './view';
|
||||||
|
|
||||||
const select = (state, props) => ({
|
const select = (state, props) => ({
|
||||||
claim: makeSelectClaimForUri(props.uri)(state),
|
claim: makeSelectClaimForUri(props.uri)(state),
|
||||||
viewCount: makeSelectViewCountForUri(props.uri)(state),
|
viewCount: makeSelectViewCountForUri(props.uri)(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = (dispatch) => ({
|
||||||
fetchViewCount: claimId => dispatch(doFetchViewCount(claimId)),
|
fetchViewCount: (claimId) => dispatch(doFetchViewCount(claimId)),
|
||||||
|
doAnalyticsView: (uri) => dispatch(doAnalyticsView(uri)),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(select, perform)(FileViewCount);
|
export default connect(select, perform)(FileViewCount);
|
||||||
|
|
|
@ -1,19 +1,32 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React, { useEffect } from 'react';
|
import { SIMPLE_SITE } from 'config';
|
||||||
|
import React from 'react';
|
||||||
import HelpLink from 'component/common/help-link';
|
import HelpLink from 'component/common/help-link';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
claim: ?StreamClaim,
|
claim: ?StreamClaim,
|
||||||
fetchViewCount: string => void,
|
fetchViewCount: (string) => void,
|
||||||
uri: string,
|
uri: string,
|
||||||
viewCount: string,
|
viewCount: string,
|
||||||
|
livestream?: boolean,
|
||||||
|
activeViewers?: number,
|
||||||
|
isLive?: boolean,
|
||||||
|
doAnalyticsView: (string) => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
function FileViewCount(props: Props) {
|
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;
|
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) {
|
if (claimId) {
|
||||||
fetchViewCount(claimId);
|
fetchViewCount(claimId);
|
||||||
}
|
}
|
||||||
|
@ -23,8 +36,15 @@ function FileViewCount(props: Props) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className="media__subtitle--centered">
|
<span className="media__subtitle--centered">
|
||||||
{viewCount !== 1 ? __('%view_count% views', { view_count: formattedViewCount }) : __('1 view')}
|
{activeViewers !== undefined
|
||||||
<HelpLink href="https://lbry.com/faq/views" />
|
? __('%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 && <HelpLink href="https://lbry.com/faq/views" />}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,13 +41,7 @@ export default function LivestreamLayout(props: Props) {
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<FileTitleSection
|
<FileTitleSection uri={uri} livestream isLive={isLive} activeViewers={activeViewers} />
|
||||||
uri={uri}
|
|
||||||
livestream
|
|
||||||
isLive={isLive}
|
|
||||||
activeViewers={activeViewers}
|
|
||||||
stateOfViewers={isLive ? __('watching') : __('waiting')}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<LivestreamComments uri={uri} />
|
<LivestreamComments uri={uri} />
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in a new issue