fix view counts on direct visits for non-video content
This commit is contained in:
parent
8eb45a9557
commit
f70887dd78
1 changed files with 5 additions and 10 deletions
|
@ -1,7 +1,6 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import FileRender from 'component/fileRender';
|
import FileRender from 'component/fileRender';
|
||||||
import usePrevious from 'effects/use-previous';
|
|
||||||
import LoadingScreen from 'component/common/loading-screen';
|
import LoadingScreen from 'component/common/loading-screen';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
@ -16,29 +15,25 @@ type Props = {
|
||||||
|
|
||||||
export default function FileRenderInline(props: Props) {
|
export default function FileRenderInline(props: Props) {
|
||||||
const { isPlaying, fileInfo, uri, streamingUrl, triggerAnalyticsView, claimRewards } = props;
|
const { isPlaying, fileInfo, uri, streamingUrl, triggerAnalyticsView, claimRewards } = props;
|
||||||
|
|
||||||
const [playTime, setPlayTime] = useState();
|
const [playTime, setPlayTime] = useState();
|
||||||
const previousUri = usePrevious(uri);
|
|
||||||
const isNewView = uri && previousUri !== uri && isPlaying;
|
|
||||||
const [hasRecordedView, setHasRecordedView] = useState(false);
|
|
||||||
const isReadyToPlay = streamingUrl || (fileInfo && fileInfo.completed);
|
const isReadyToPlay = streamingUrl || (fileInfo && fileInfo.completed);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isNewView) {
|
if (isPlaying) {
|
||||||
setPlayTime(Date.now());
|
setPlayTime(Date.now());
|
||||||
}
|
}
|
||||||
}, [isNewView, uri]);
|
}, [isPlaying, setPlayTime, uri]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (playTime && isReadyToPlay && !hasRecordedView) {
|
if (playTime && isReadyToPlay) {
|
||||||
const timeToStart = Date.now() - playTime;
|
const timeToStart = Date.now() - playTime;
|
||||||
|
|
||||||
triggerAnalyticsView(uri, timeToStart).then(() => {
|
triggerAnalyticsView(uri, timeToStart).then(() => {
|
||||||
claimRewards();
|
claimRewards();
|
||||||
setHasRecordedView(false);
|
|
||||||
setPlayTime(null);
|
setPlayTime(null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [setPlayTime, triggerAnalyticsView, isReadyToPlay, hasRecordedView, playTime, uri, claimRewards]);
|
}, [setPlayTime, claimRewards, triggerAnalyticsView, isReadyToPlay, playTime, uri]);
|
||||||
|
|
||||||
if (!isPlaying) {
|
if (!isPlaying) {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in a new issue