fix view counts on direct visits for non-video content

This commit is contained in:
Sean Yesmunt 2020-04-08 17:01:14 -04:00
parent 8eb45a9557
commit f70887dd78

View file

@ -1,7 +1,6 @@
// @flow
import React, { useState, useEffect } from 'react';
import FileRender from 'component/fileRender';
import usePrevious from 'effects/use-previous';
import LoadingScreen from 'component/common/loading-screen';
type Props = {
@ -16,29 +15,25 @@ type Props = {
export default function FileRenderInline(props: Props) {
const { isPlaying, fileInfo, uri, streamingUrl, triggerAnalyticsView, claimRewards } = props;
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);
useEffect(() => {
if (isNewView) {
if (isPlaying) {
setPlayTime(Date.now());
}
}, [isNewView, uri]);
}, [isPlaying, setPlayTime, uri]);
useEffect(() => {
if (playTime && isReadyToPlay && !hasRecordedView) {
if (playTime && isReadyToPlay) {
const timeToStart = Date.now() - playTime;
triggerAnalyticsView(uri, timeToStart).then(() => {
claimRewards();
setHasRecordedView(false);
setPlayTime(null);
});
}
}, [setPlayTime, triggerAnalyticsView, isReadyToPlay, hasRecordedView, playTime, uri, claimRewards]);
}, [setPlayTime, claimRewards, triggerAnalyticsView, isReadyToPlay, playTime, uri]);
if (!isPlaying) {
return null;