diff --git a/src/timelines/MediaAttachmentGrid.tsx b/src/timelines/MediaAttachmentGrid.tsx index c018c89..c9da6a3 100644 --- a/src/timelines/MediaAttachmentGrid.tsx +++ b/src/timelines/MediaAttachmentGrid.tsx @@ -2,6 +2,7 @@ import type { mastodon } from "masto"; import { type Component, For, + Index, createMemo, createRenderEffect, createSignal, @@ -103,6 +104,31 @@ const MediaAttachmentGrid: Component<{ }; }); + const itemStyle = (item: mastodon.v1.MediaAttachment) => { + const { width, height } = constraintedSize( + item.meta?.small || { width: 1, height: 1 }, + { width: 2, height: 2 }, + itemMaxSize(), + ); + + // 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; + + return Object.assign( + { + width: `${width}px`, + height: `${height}px`, + }, + accentColor ? { "--media-color-accent": accentColor } : {}, + ); + }; + css` .attachments { column-count: ${columnCount().toString()}; @@ -118,74 +144,48 @@ const MediaAttachmentGrid: Component<{ } }} > - + {(item, index) => { - // 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; - const { width, height } = item.meta?.small || {}; - - const size = () => { - return constraintedSize( - item.meta?.small || { width: 1, height: 1 }, - { width: 2, height: 2 }, - itemMaxSize(), - ); - }; - - const style = () => { - return Object.assign( - { - width: `${size().width}px`, - height: `${size().height}px`, - }, - accentColor ? { "--media-color-accent": accentColor } : {}, - ); - }; - - switch (item.type) { + switch (item().type) { case "image": return ( {item.description ); case "video": return ( + ); };