lbry-desktop/ui/effects/use-get-poster.js

27 lines
763 B
JavaScript
Raw Normal View History

2022-03-17 11:53:18 +01:00
// @flow
import React from 'react';
import { THUMBNAIL_WIDTH_POSTER, THUMBNAIL_HEIGHT_POSTER } from 'config';
import { getThumbnailCdnUrl } from 'util/thumbnail';
2022-03-17 11:53:18 +01:00
// $FlowFixMe cannot resolve ...
import FileRenderPlaceholder from 'static/img/fileRenderPlaceholder.png';
export default function useGetPoster(claimThumbnail: ?string) {
2022-03-17 11:53:18 +01:00
const [thumbnail, setThumbnail] = React.useState(FileRenderPlaceholder);
React.useEffect(() => {
2022-06-14 15:43:41 +02:00
if (!claimThumbnail) {
setThumbnail(FileRenderPlaceholder);
} else {
setThumbnail(
getThumbnailCdnUrl({
thumbnail: claimThumbnail,
width: THUMBNAIL_WIDTH_POSTER,
height: THUMBNAIL_HEIGHT_POSTER,
})
);
2022-06-14 15:43:41 +02:00
}
}, [claimThumbnail]);
2022-03-17 11:53:18 +01:00
return thumbnail;
}