2020-01-07 22:07:12 +01:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
2020-05-07 20:44:11 +02:00
|
|
|
import { generateStreamUrl } from 'util/web';
|
2020-01-07 22:07:12 +01:00
|
|
|
|
2020-01-13 20:12:27 +01:00
|
|
|
export default function useGetThumbnail(
|
|
|
|
uri: string,
|
|
|
|
claim: ?Claim,
|
|
|
|
streamingUrl: ?string,
|
|
|
|
getFile: string => void,
|
|
|
|
shouldHide: boolean
|
|
|
|
) {
|
2020-01-24 17:25:31 +01:00
|
|
|
// const hasClaim = claim !== undefined;
|
2020-01-07 22:07:12 +01:00
|
|
|
|
|
|
|
// $FlowFixMe
|
|
|
|
const isImage = claim && claim.value && claim.value.stream_type === 'image';
|
|
|
|
// $FlowFixMe
|
|
|
|
const isFree = claim && claim.value && (!claim.value.fee || Number(claim.value.fee.amount) <= 0);
|
|
|
|
let thumbnailToUse;
|
|
|
|
|
|
|
|
// @if TARGET='web'
|
|
|
|
if (claim && isImage && isFree) {
|
2020-01-24 17:25:31 +01:00
|
|
|
thumbnailToUse = generateStreamUrl(claim.name, claim.claim_id);
|
2020-01-07 22:07:12 +01:00
|
|
|
}
|
|
|
|
// @endif
|
|
|
|
|
|
|
|
const [thumbnail, setThumbnail] = React.useState(thumbnailToUse);
|
|
|
|
React.useEffect(() => {
|
|
|
|
setThumbnail(thumbnailToUse);
|
|
|
|
}, [thumbnailToUse]);
|
|
|
|
|
|
|
|
// @if TARGET='app'
|
2020-01-17 20:57:09 +01:00
|
|
|
//
|
|
|
|
// Temporarily disabled until we can call get with "save_blobs: off"
|
|
|
|
//
|
|
|
|
// React.useEffect(() => {
|
|
|
|
// if (hasClaim && isImage && isFree) {
|
|
|
|
// if (streamingUrl) {
|
|
|
|
// setThumbnail(streamingUrl);
|
|
|
|
// } else if (!shouldHide) {
|
|
|
|
// getFile(uri);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }, [hasClaim, isFree, isImage, streamingUrl, uri, shouldHide]);
|
2020-01-07 22:07:12 +01:00
|
|
|
// @endif
|
|
|
|
|
|
|
|
return thumbnail;
|
|
|
|
}
|