adds anaytics to download button
This commit is contained in:
parent
5da78c9553
commit
723d1fabbb
2 changed files with 14 additions and 3 deletions
|
@ -5,7 +5,7 @@ import {
|
|||
makeSelectLoadingForUri,
|
||||
makeSelectClaimIsMine,
|
||||
} from 'lbry-redux';
|
||||
import { doOpenModal } from 'redux/actions/app';
|
||||
import { doOpenModal, doAnalyticsView } from 'redux/actions/app';
|
||||
import { doSetPlayingUri, doPlayUri } from 'redux/actions/content';
|
||||
import FileDownloadLink from './view';
|
||||
|
||||
|
@ -20,6 +20,7 @@ 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)),
|
||||
});
|
||||
|
||||
export default connect(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// @flow
|
||||
import * as ICONS from 'constants/icons';
|
||||
import * as MODALS from 'constants/modal_types';
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import Button from 'component/button';
|
||||
import ToolTip from 'component/common/tooltip';
|
||||
|
||||
|
@ -15,12 +15,17 @@ type Props = {
|
|||
openModal: (id: string, { path: string }) => void,
|
||||
pause: () => void,
|
||||
download: string => void,
|
||||
triggerAnalyticsView: (string, number) => void,
|
||||
};
|
||||
|
||||
function FileDownloadLink(props: Props) {
|
||||
const { fileInfo, downloading, loading, openModal, pause, claimIsMine, download, uri } = props;
|
||||
const [shouldTrigger, setShouldTrigger] = useState(false);
|
||||
const { fileInfo, downloading, loading, openModal, pause, claimIsMine, download, uri, triggerAnalyticsView } = props;
|
||||
|
||||
if (downloading || loading) {
|
||||
if (!shouldTrigger) {
|
||||
setShouldTrigger(true);
|
||||
}
|
||||
const progress = fileInfo && fileInfo.written_bytes > 0 ? (fileInfo.written_bytes / fileInfo.total_bytes) * 100 : 0;
|
||||
const label =
|
||||
fileInfo && fileInfo.written_bytes > 0 ? progress.toFixed(0) + __('% downloaded') : __('Connecting...');
|
||||
|
@ -28,6 +33,11 @@ function FileDownloadLink(props: Props) {
|
|||
return <span>{label}</span>;
|
||||
}
|
||||
|
||||
if (fileInfo && fileInfo.download_path && fileInfo.completed && shouldTrigger) {
|
||||
triggerAnalyticsView(uri, 0);
|
||||
setShouldTrigger(false);
|
||||
}
|
||||
|
||||
if (fileInfo && fileInfo.download_path && fileInfo.completed) {
|
||||
return (
|
||||
<ToolTip label={__('Open file')}>
|
||||
|
|
Loading…
Reference in a new issue