fire analytics event after file has started downloading
This commit is contained in:
parent
1427ad2a76
commit
73bd46e7d8
3 changed files with 19 additions and 19 deletions
|
@ -19,8 +19,7 @@ const select = (state, props) => ({
|
|||
const perform = dispatch => ({
|
||||
openModal: (modal, props) => dispatch(doOpenModal(modal, props)),
|
||||
pause: () => dispatch(doSetPlayingUri(null)),
|
||||
download: uri => dispatch(doPlayUri(uri, false, true)),
|
||||
triggerAnalyticsView: (uri, timeToStart) => dispatch(doAnalyticsView(uri, timeToStart)),
|
||||
download: uri => dispatch(doPlayUri(uri, false, true, () => dispatch(doAnalyticsView(uri)))),
|
||||
});
|
||||
|
||||
export default connect(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// @flow
|
||||
import * as ICONS from 'constants/icons';
|
||||
import * as MODALS from 'constants/modal_types';
|
||||
import React, { useState } from 'react';
|
||||
import React from 'react';
|
||||
import Button from 'component/button';
|
||||
import ToolTip from 'component/common/tooltip';
|
||||
|
||||
|
@ -15,12 +15,10 @@ type Props = {
|
|||
openModal: (id: string, { path: string }) => void,
|
||||
pause: () => void,
|
||||
download: string => void,
|
||||
triggerAnalyticsView: (string, number) => void,
|
||||
};
|
||||
|
||||
function FileDownloadLink(props: Props) {
|
||||
const [clicked, setClicked] = useState(false);
|
||||
const { fileInfo, downloading, loading, openModal, pause, claimIsMine, download, uri, triggerAnalyticsView } = props;
|
||||
const { fileInfo, downloading, loading, openModal, pause, claimIsMine, download, uri } = props;
|
||||
|
||||
if (downloading || loading) {
|
||||
const progress = fileInfo && fileInfo.written_bytes > 0 ? (fileInfo.written_bytes / fileInfo.total_bytes) * 100 : 0;
|
||||
|
@ -30,11 +28,6 @@ function FileDownloadLink(props: Props) {
|
|||
return <span>{label}</span>;
|
||||
}
|
||||
|
||||
if (fileInfo && fileInfo.download_path && clicked) {
|
||||
triggerAnalyticsView(uri, 0);
|
||||
setClicked(false);
|
||||
}
|
||||
|
||||
if (fileInfo && fileInfo.download_path && fileInfo.completed) {
|
||||
return (
|
||||
<ToolTip label={__('Open file')}>
|
||||
|
@ -55,7 +48,6 @@ function FileDownloadLink(props: Props) {
|
|||
button="link"
|
||||
icon={ICONS.DOWNLOAD}
|
||||
onClick={() => {
|
||||
setClicked(true);
|
||||
download(uri);
|
||||
}}
|
||||
/>
|
||||
|
|
|
@ -179,19 +179,28 @@ export function doFetchClaimsByChannel(uri: string, page: number = 1, pageSize:
|
|||
};
|
||||
}
|
||||
|
||||
export function doPurchaseUriWrapper(uri: string, cost: number, saveFile: boolean) {
|
||||
export function doPurchaseUriWrapper(uri: string, cost: number, saveFile: boolean, cb: ?() => void) {
|
||||
return (dispatch: Dispatch, getState: () => any) => {
|
||||
function onSuccess(fileInfo) {
|
||||
dispatch(doUpdateLoadStatus(uri, fileInfo.outpoint));
|
||||
if (saveFile) {
|
||||
dispatch(doUpdateLoadStatus(uri, fileInfo.outpoint));
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb();
|
||||
}
|
||||
}
|
||||
|
||||
// Only pass the success callback if we are saving the file, otherwise we don't show the download percentage
|
||||
const successCallBack = saveFile ? onSuccess : undefined;
|
||||
dispatch(doPurchaseUri(uri, { costInfo: cost }, saveFile, successCallBack));
|
||||
dispatch(doPurchaseUri(uri, { costInfo: cost }, saveFile, onSuccess));
|
||||
};
|
||||
}
|
||||
|
||||
export function doPlayUri(uri: string, skipCostCheck: boolean = false, saveFileOverride: boolean = false) {
|
||||
export function doPlayUri(
|
||||
uri: string,
|
||||
skipCostCheck: boolean = false,
|
||||
saveFileOverride: boolean = false,
|
||||
cb?: () => void
|
||||
) {
|
||||
return (dispatch: Dispatch, getState: () => any) => {
|
||||
const state = getState();
|
||||
const fileInfo = makeSelectFileInfoForUri(uri)(state);
|
||||
|
@ -211,7 +220,7 @@ export function doPlayUri(uri: string, skipCostCheck: boolean = false, saveFileO
|
|||
const instantPurchaseMax = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_MAX)(state);
|
||||
|
||||
function beginGetFile() {
|
||||
dispatch(doPurchaseUriWrapper(uri, cost, saveFile));
|
||||
dispatch(doPurchaseUriWrapper(uri, cost, saveFile, cb));
|
||||
}
|
||||
|
||||
function attemptPlay(instantPurchaseMax = null) {
|
||||
|
|
Loading…
Reference in a new issue