MediaAttachmentGrid: calc only when not loaded
All checks were successful
/ depoly (push) Successful in 1m7s
All checks were successful
/ depoly (push) Successful in 1m7s
* This is a workaround, the best solution is we do the calculation correctly.
This commit is contained in:
parent
f4ce206c52
commit
6306c5afbe
1 changed files with 9 additions and 6 deletions
|
@ -64,28 +64,29 @@ const MediaAttachmentGrid: Component<{
|
|||
>
|
||||
<For each={props.attachments}>
|
||||
{(item, index) => {
|
||||
const [loaded, setLoaded] = createSignal(false)
|
||||
const width = item.meta?.small?.width;
|
||||
const height = item.meta?.small?.height;
|
||||
const aspectRatio = item.meta?.small?.aspect;
|
||||
const maxHeight = vh35();
|
||||
const realHeight = height && height > maxHeight ? maxHeight : height;
|
||||
const realWidth =
|
||||
height && height > maxHeight
|
||||
? maxHeight * (aspectRatio ?? 1)
|
||||
width && height && height > maxHeight
|
||||
? maxHeight / (aspectRatio ?? 1)
|
||||
: width;
|
||||
const style = {
|
||||
const style = () => loaded() ? undefined : {
|
||||
width: realWidth ? `${realWidth}px` : undefined,
|
||||
height: realHeight ? `${realHeight}px` : undefined,
|
||||
"aspect-ratio": aspectRatio?.toString(),
|
||||
};
|
||||
switch (item.type) {
|
||||
case "image":
|
||||
return (
|
||||
<img
|
||||
src={item.previewUrl}
|
||||
style={style}
|
||||
style={style()}
|
||||
alt={item.description || undefined}
|
||||
onClick={[openViewerFor, index()]}
|
||||
onLoad={[setLoaded, true]}
|
||||
loading="lazy"
|
||||
></img>
|
||||
);
|
||||
|
@ -93,8 +94,10 @@ const MediaAttachmentGrid: Component<{
|
|||
return (
|
||||
<video
|
||||
src={item.url || undefined}
|
||||
style={style}
|
||||
style={style()}
|
||||
onLoadedMetadata={[setLoaded, true]}
|
||||
autoplay={false}
|
||||
controls
|
||||
/>
|
||||
);
|
||||
case "gifv":
|
||||
|
|
Loading…
Reference in a new issue