lbry-desktop/ui/effects/use-get-thumbnail.js
Thomas Zarebczan 75478ad18f Thumbnail improvements
- always pass to optimizer, even for speech

- default channel thumb to optimized at 5
50px, original on channel page

- fix misc analytics bug
2022-03-21 13:13:25 -04:00

55 lines
1.6 KiB
JavaScript

// @flow
import React from 'react';
import { generateStreamUrl } from 'util/web';
import { MISSING_THUMB_DEFAULT } from 'config';
export default function useGetThumbnail(
uri: string,
claim: ?Claim,
streamingUrl: ?string,
getFile: (string) => void,
shouldHide: boolean
) {
let thumbnailToUse;
// $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);
const isCollection = claim && claim.value_type === 'collection';
const thumbnailInClaim = claim && claim.value && claim.value.thumbnail && claim.value.thumbnail.url;
// @if TARGET='web'
if (thumbnailInClaim) {
thumbnailToUse = thumbnailInClaim;
} else if (claim && isImage && isFree) {
thumbnailToUse = generateStreamUrl(claim.name, claim.claim_id);
} else if (isCollection) {
thumbnailToUse = MISSING_THUMB_DEFAULT;
}
// @endif
// @if TARGET='app'
thumbnailToUse = thumbnailInClaim;
//
// 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]);
// @endif
const [thumbnail, setThumbnail] = React.useState(thumbnailToUse);
React.useEffect(() => {
setThumbnail(thumbnailToUse);
}, [thumbnailToUse]);
return thumbnail;
}