fixing first thumbnail bug

This commit is contained in:
Anthony 2022-06-14 15:43:41 +02:00 committed by Thomas Zarebczan
parent 91e83760d4
commit 90c2272720

View file

@ -8,20 +8,20 @@ export default function useThumbnail(claimThumbnail: ?string, containerRef: any)
const [thumbnail, setThumbnail] = React.useState(FileRenderPlaceholder); const [thumbnail, setThumbnail] = React.useState(FileRenderPlaceholder);
React.useEffect(() => { React.useEffect(() => {
if (!claimThumbnail) return; if (!claimThumbnail) {
return setThumbnail(FileRenderPlaceholder);
}
const timer = setTimeout(() => { const timer = setTimeout(() => {
let newThumbnail = claimThumbnail; let newThumbnail = claimThumbnail;
if ( // generate the thumbnail url served by the cdn
containerRef.current && if (containerRef.current?.parentElement?.offsetWidth) {
containerRef.current.parentElement &&
containerRef.current.parentElement.offsetWidth
) {
const w = containerRef.current.parentElement.offsetWidth; const w = containerRef.current.parentElement.offsetWidth;
newThumbnail = getThumbnailCdnUrl({ thumbnail: newThumbnail, width: w, height: w }); newThumbnail = getThumbnailCdnUrl({ thumbnail: newThumbnail, width: w, height: w });
} }
// update new thumbnail in state
if (newThumbnail !== thumbnail) { if (newThumbnail !== thumbnail) {
setThumbnail(newThumbnail); setThumbnail(newThumbnail);
} }