2022-03-17 11:53:18 +01:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
2022-06-17 03:38:29 +02:00
|
|
|
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';
|
|
|
|
|
2022-06-16 06:56:46 +02:00
|
|
|
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) {
|
2022-06-16 06:56:46 +02:00
|
|
|
setThumbnail(FileRenderPlaceholder);
|
|
|
|
} else {
|
2022-06-17 03:38:29 +02:00
|
|
|
setThumbnail(
|
|
|
|
getThumbnailCdnUrl({
|
|
|
|
thumbnail: claimThumbnail,
|
|
|
|
width: THUMBNAIL_WIDTH_POSTER,
|
|
|
|
height: THUMBNAIL_HEIGHT_POSTER,
|
|
|
|
})
|
|
|
|
);
|
2022-06-14 15:43:41 +02:00
|
|
|
}
|
2022-06-16 06:56:46 +02:00
|
|
|
}, [claimThumbnail]);
|
2022-03-17 11:53:18 +01:00
|
|
|
|
|
|
|
return thumbnail;
|
|
|
|
}
|