remove old placeholder algorithm
All checks were successful
/ depoly (push) Successful in 1m21s

- TootPreviewCard and MediaAttachmentGrid
- the placeholder thing is now offloaded to the
  browser
This commit is contained in:
thislight 2024-10-27 23:57:10 +08:00
parent b9b2d40614
commit 66bded813d
No known key found for this signature in database
GPG key ID: A50F9451AC56A63E
3 changed files with 29 additions and 28 deletions

View file

@ -81,58 +81,52 @@ 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 =
width && height && height > maxHeight
? maxHeight * (aspectRatio ?? 1)
: width;
const style = () =>
loaded()
? undefined
: {
width: realWidth ? `${realWidth}px` : undefined,
height: realHeight ? `${realHeight}px` : undefined,
};
// I don't know why mastodon does not return this
// and the condition for it to return this.
// Anyway, It is useless now.
// My hope is the FastAverageColor, but
// we may need better tool to manage the performance impact
// before using this. See #37.
// TODO: use fast average color to extract accent color
const accentColor = item.meta?.colors?.accent;
switch (item.type) {
case "image":
return (
<img
src={item.previewUrl}
style={style()}
width={item.meta?.small?.width}
height={item.meta?.small?.height}
alt={item.description || undefined}
onClick={[openViewerFor, index()]}
onLoad={[setLoaded, true]}
loading="lazy"
style={
accentColor ? { "--media-color-accent": accentColor } : {}
}
></img>
);
case "video":
return (
<video
src={item.url || undefined}
style={style()}
onLoadedMetadata={[setLoaded, true]}
autoplay={settings().autoPlayVideos}
playsinline={settings().autoPlayVideos ? true : undefined}
controls
poster={item.previewUrl}
width={item.meta?.small?.width}
height={item.meta?.small?.height}
/>
);
case "gifv":
return (
<video
src={item.url || undefined}
style={style()}
onLoadedMetadata={[setLoaded, true]}
autoplay={settings().autoPlayGIFs}
controls
playsinline /* or safari on iOS will play in full-screen */
loop
poster={item.previewUrl}
width={item.meta?.small?.width}
height={item.meta?.small?.height}
/>
);