diff --git a/ui/component/fileRenderInline/view.jsx b/ui/component/fileRenderInline/view.jsx index 6b3f6733a..79fe323ac 100644 --- a/ui/component/fileRenderInline/view.jsx +++ b/ui/component/fileRenderInline/view.jsx @@ -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;