mirror of
https://github.com/LBRYFoundation/lbry-desktop.git
synced 2025-08-23 17:47:24 +00:00
trigger analytics view for download on lbry.tv
This commit is contained in:
parent
978871a927
commit
b50f1b0d8b
3 changed files with 55 additions and 18 deletions
|
@ -98,7 +98,14 @@ const Button = forwardRef<any, {}>((props: Props, ref: any) => {
|
||||||
|
|
||||||
if (href) {
|
if (href) {
|
||||||
return (
|
return (
|
||||||
<OutboundLink eventLabel="outboundClick" to={href} target="_blank" className={combinedClassName} {...otherProps}>
|
<OutboundLink
|
||||||
|
eventLabel="outboundClick"
|
||||||
|
to={href}
|
||||||
|
target="_blank"
|
||||||
|
className={combinedClassName}
|
||||||
|
onClick={onClick}
|
||||||
|
{...otherProps}
|
||||||
|
>
|
||||||
{content}
|
{content}
|
||||||
</OutboundLink>
|
</OutboundLink>
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
makeSelectClaimIsMine,
|
makeSelectClaimIsMine,
|
||||||
makeSelectClaimForUri,
|
makeSelectClaimForUri,
|
||||||
} from 'lbry-redux';
|
} from 'lbry-redux';
|
||||||
|
import { makeSelectCostInfoForUri } from 'lbryinc';
|
||||||
import { doOpenModal, doAnalyticsView } from 'redux/actions/app';
|
import { doOpenModal, doAnalyticsView } from 'redux/actions/app';
|
||||||
import { doSetPlayingUri, doPlayUri } from 'redux/actions/content';
|
import { doSetPlayingUri, doPlayUri } from 'redux/actions/content';
|
||||||
import FileDownloadLink from './view';
|
import FileDownloadLink from './view';
|
||||||
|
@ -16,12 +17,14 @@ const select = (state, props) => ({
|
||||||
loading: makeSelectLoadingForUri(props.uri)(state),
|
loading: makeSelectLoadingForUri(props.uri)(state),
|
||||||
claimIsMine: makeSelectClaimIsMine(props.uri)(state),
|
claimIsMine: makeSelectClaimIsMine(props.uri)(state),
|
||||||
claim: makeSelectClaimForUri(props.uri)(state),
|
claim: makeSelectClaimForUri(props.uri)(state),
|
||||||
|
costInfo: makeSelectCostInfoForUri(props.uri)(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => ({
|
||||||
openModal: (modal, props) => dispatch(doOpenModal(modal, props)),
|
openModal: (modal, props) => dispatch(doOpenModal(modal, props)),
|
||||||
pause: () => dispatch(doSetPlayingUri(null)),
|
pause: () => dispatch(doSetPlayingUri(null)),
|
||||||
download: uri => dispatch(doPlayUri(uri, false, true, () => dispatch(doAnalyticsView(uri)))),
|
download: uri => dispatch(doPlayUri(uri, false, true, () => dispatch(doAnalyticsView(uri)))),
|
||||||
|
triggerViewEvent: uri => dispatch(doAnalyticsView(uri)),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
|
|
|
@ -17,14 +17,43 @@ type Props = {
|
||||||
openModal: (id: string, { path: string }) => void,
|
openModal: (id: string, { path: string }) => void,
|
||||||
pause: () => void,
|
pause: () => void,
|
||||||
download: string => void,
|
download: string => void,
|
||||||
|
triggerViewEvent: string => void,
|
||||||
|
costInfo: ?{ cost: string },
|
||||||
};
|
};
|
||||||
|
|
||||||
function FileDownloadLink(props: Props) {
|
function FileDownloadLink(props: Props) {
|
||||||
const { fileInfo, downloading, loading, openModal, pause, claimIsMine, download, uri, claim } = props;
|
const {
|
||||||
|
fileInfo,
|
||||||
|
downloading,
|
||||||
|
loading,
|
||||||
|
openModal,
|
||||||
|
pause,
|
||||||
|
claimIsMine,
|
||||||
|
download,
|
||||||
|
uri,
|
||||||
|
claim,
|
||||||
|
triggerViewEvent,
|
||||||
|
costInfo,
|
||||||
|
} = props;
|
||||||
|
const cost = costInfo ? Number(costInfo.cost) : 0;
|
||||||
|
const isPaidContent = cost > 0;
|
||||||
const { name, claim_id: claimId, value } = claim;
|
const { name, claim_id: claimId, value } = claim;
|
||||||
const fileName = value && value.source && value.source.name;
|
const fileName = value && value.source && value.source.name;
|
||||||
const downloadUrl = generateDownloadUrl(name, claimId, undefined, true);
|
const downloadUrl = generateDownloadUrl(name, claimId, undefined, true);
|
||||||
|
|
||||||
|
function handleDownload() {
|
||||||
|
// @if TARGET='app'
|
||||||
|
download(uri);
|
||||||
|
// @endif;
|
||||||
|
// @if TARGET='web'
|
||||||
|
triggerViewEvent(uri);
|
||||||
|
// @endif;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IS_WEB && isPaidContent) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (downloading || loading) {
|
if (downloading || loading) {
|
||||||
const progress = fileInfo && fileInfo.written_bytes > 0 ? (fileInfo.written_bytes / fileInfo.total_bytes) * 100 : 0;
|
const progress = fileInfo && fileInfo.written_bytes > 0 ? (fileInfo.written_bytes / fileInfo.total_bytes) * 100 : 0;
|
||||||
const label =
|
const label =
|
||||||
|
@ -46,15 +75,14 @@ function FileDownloadLink(props: Props) {
|
||||||
/>
|
/>
|
||||||
</ToolTip>
|
</ToolTip>
|
||||||
);
|
);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ToolTip label={IS_WEB ? __('Download') : __('Add to your library')}>
|
<ToolTip label={IS_WEB ? __('Download') : __('Add to your library')}>
|
||||||
<Button
|
<Button
|
||||||
button="alt"
|
button="alt"
|
||||||
icon={ICONS.DOWNLOAD}
|
icon={ICONS.DOWNLOAD}
|
||||||
// @if TARGET='app'
|
onClick={handleDownload}
|
||||||
onClick={() => download(uri)}
|
|
||||||
// @endif
|
|
||||||
// @if TARGET='web'
|
// @if TARGET='web'
|
||||||
download={fileName}
|
download={fileName}
|
||||||
href={downloadUrl}
|
href={downloadUrl}
|
||||||
|
@ -63,6 +91,5 @@ function FileDownloadLink(props: Props) {
|
||||||
</ToolTip>
|
</ToolTip>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export default FileDownloadLink;
|
export default FileDownloadLink;
|
||||||
|
|
Loading…
Add table
Reference in a new issue