fix: always record file views

This commit is contained in:
Sean Yesmunt 2019-09-17 15:20:55 -04:00
parent bca9e76f39
commit 14f4401aef

View file

@ -62,9 +62,8 @@ export default function FileViewer(props: Props) {
: __('Loading'); : __('Loading');
const previousUri = usePrevious(uri); const previousUri = usePrevious(uri);
const previousIsReadyToPlay = usePrevious(isReadyToPlay);
const isNewView = uri && previousUri !== uri && isPlaying; const isNewView = uri && previousUri !== uri && isPlaying;
const wasntReadyButNowItIs = isReadyToPlay && !previousIsReadyToPlay; const [hasRecordedView, setHasRecordedView] = useState(false);
useEffect(() => { useEffect(() => {
if (isNewView) { if (isNewView) {
@ -73,13 +72,14 @@ export default function FileViewer(props: Props) {
}, [isNewView, uri]); }, [isNewView, uri]);
useEffect(() => { useEffect(() => {
if (playTime && isReadyToPlay && wasntReadyButNowItIs) { if (playTime && isReadyToPlay && !hasRecordedView) {
const timeToStart = Date.now() - playTime; const timeToStart = Date.now() - playTime;
triggerAnalyticsView(uri, timeToStart); triggerAnalyticsView(uri, timeToStart);
claimRewards(); claimRewards();
setPlayTime(null); setPlayTime(null);
setHasRecordedView(false);
} }
}, [setPlayTime, triggerAnalyticsView, isReadyToPlay, wasntReadyButNowItIs, playTime, uri, claimRewards]); }, [setPlayTime, triggerAnalyticsView, isReadyToPlay, hasRecordedView, playTime, uri, claimRewards]);
useEffect(() => { useEffect(() => {
function handleResize() { function handleResize() {