fixing first thumbnail bug
This commit is contained in:
parent
91e83760d4
commit
90c2272720
1 changed files with 6 additions and 6 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue