2020-04-29 22:50:06 +02:00
|
|
|
// @flow
|
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import FileViewerEmbeddedTitle from 'component/fileViewerEmbeddedTitle';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
import useIsMobile from 'effects/use-is-mobile';
|
|
|
|
import { formatLbryUrlForWeb } from 'util/url';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
|
|
|
thumbnail: string,
|
|
|
|
claim: ?Claim,
|
|
|
|
doResolveUri: string => void,
|
|
|
|
doFetchCostInfoForUri: string => void,
|
|
|
|
doSetFloatingUri: string => void,
|
|
|
|
floatingPlayerEnabled: boolean,
|
2020-05-21 18:53:21 +02:00
|
|
|
doPlayUri: (string, ?boolean, ?boolean, (GetResponse) => void) => void,
|
|
|
|
doAnaltyicsPurchaseEvent: GetResponse => void,
|
2020-04-29 22:50:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default function FileRenderFloating(props: Props) {
|
|
|
|
const {
|
|
|
|
uri,
|
|
|
|
thumbnail = '',
|
|
|
|
claim,
|
|
|
|
doResolveUri,
|
|
|
|
doFetchCostInfoForUri,
|
|
|
|
doSetFloatingUri,
|
|
|
|
floatingPlayerEnabled,
|
2020-04-30 20:25:51 +02:00
|
|
|
doPlayUri,
|
2020-05-21 18:53:21 +02:00
|
|
|
doAnaltyicsPurchaseEvent,
|
2020-04-29 22:50:06 +02:00
|
|
|
} = props;
|
|
|
|
const { push } = useHistory();
|
|
|
|
const isMobile = useIsMobile();
|
|
|
|
const hasResolvedUri = claim !== undefined;
|
|
|
|
|
|
|
|
useEffect(() => {
|
2020-05-21 18:53:21 +02:00
|
|
|
doResolveUri(uri);
|
|
|
|
doFetchCostInfoForUri(uri);
|
|
|
|
}, [uri, doResolveUri, doFetchCostInfoForUri]);
|
|
|
|
|
|
|
|
function handleClick() {
|
2020-04-29 22:50:06 +02:00
|
|
|
if (!hasResolvedUri) {
|
2020-05-21 18:53:21 +02:00
|
|
|
return;
|
2020-04-29 22:50:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isMobile || !floatingPlayerEnabled) {
|
|
|
|
const formattedUrl = formatLbryUrlForWeb(uri);
|
|
|
|
push(formattedUrl);
|
|
|
|
} else {
|
2020-05-21 18:53:21 +02:00
|
|
|
doPlayUri(uri, undefined, undefined, fileInfo => {
|
|
|
|
doSetFloatingUri(uri);
|
|
|
|
doAnaltyicsPurchaseEvent(fileInfo);
|
|
|
|
});
|
2020-04-29 22:50:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2020-05-21 18:53:21 +02:00
|
|
|
disabled={!hasResolvedUri}
|
2020-04-29 22:50:06 +02:00
|
|
|
role="button"
|
|
|
|
className="embed__inline-button"
|
|
|
|
onClick={handleClick}
|
|
|
|
style={{ backgroundImage: `url('${thumbnail.replace(/'/g, "\\'")}')` }}
|
|
|
|
>
|
|
|
|
<FileViewerEmbeddedTitle uri={uri} isInApp />
|
|
|
|
<Button onClick={handleClick} iconSize={30} title={__('Play')} className={'button--icon button--play'} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|