2026-05-26 12:07:13 +08:00
|
|
|
import { useI18n } from "../../../i18n";
|
2026-05-29 17:50:53 +08:00
|
|
|
import type { Post } from "../../../types/post";
|
2026-05-27 15:30:40 +08:00
|
|
|
import { AttachmentDownloadPill } from "../AttachmentDownloadPill";
|
2026-05-29 13:09:09 +08:00
|
|
|
import { BubbleImage } from "../BubbleImage";
|
2026-05-25 05:25:57 +08:00
|
|
|
import { useLightbox } from "../overlays/ImageLightbox";
|
|
|
|
|
import { autolink } from "../utils/autolink";
|
2026-05-26 12:07:13 +08:00
|
|
|
import { postDisplayText } from "../utils/postText";
|
2026-05-25 05:25:57 +08:00
|
|
|
|
|
|
|
|
const MAX_VISIBLE = 4;
|
|
|
|
|
|
2026-05-28 10:36:38 +08:00
|
|
|
function albumGridClass(count: number) {
|
|
|
|
|
const height = "h-[230px] min-[440px]:h-[250px] md:h-[300px] lg:h-[340px]";
|
|
|
|
|
if (count === 2) return `${height} grid grid-cols-1 grid-rows-2`;
|
|
|
|
|
return `${height} grid grid-cols-2 grid-rows-2`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function albumItemClass(index: number, count: number) {
|
|
|
|
|
if (count === 3 && index === 0) return "row-span-2";
|
|
|
|
|
return "";
|
2026-05-25 05:25:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function AlbumBubble({ post }: { post: Post }) {
|
|
|
|
|
const { openLightbox } = useLightbox();
|
2026-05-26 12:07:13 +08:00
|
|
|
const { lang } = useI18n();
|
2026-05-25 05:25:57 +08:00
|
|
|
const images = post.attachments;
|
2026-05-26 12:07:13 +08:00
|
|
|
const text = postDisplayText(post, lang);
|
2026-05-25 05:25:57 +08:00
|
|
|
const visible = images.slice(0, MAX_VISIBLE);
|
|
|
|
|
const extra = images.length - MAX_VISIBLE;
|
2026-05-28 10:36:38 +08:00
|
|
|
const layoutCount = Math.min(images.length, MAX_VISIBLE);
|
2026-05-25 05:25:57 +08:00
|
|
|
|
|
|
|
|
return (
|
2026-05-28 10:36:38 +08:00
|
|
|
<div className="flex flex-col">
|
|
|
|
|
<div className={`${albumGridClass(layoutCount)} gap-px overflow-hidden`}>
|
2026-05-25 05:25:57 +08:00
|
|
|
{visible.map((att, i) => {
|
|
|
|
|
const isLastSlot = i === MAX_VISIBLE - 1 && extra > 0;
|
|
|
|
|
return (
|
2026-05-27 15:30:40 +08:00
|
|
|
<div
|
2026-05-25 05:25:57 +08:00
|
|
|
key={att.id}
|
2026-05-28 10:36:38 +08:00
|
|
|
className={`relative h-full w-full overflow-hidden ${albumItemClass(
|
|
|
|
|
i,
|
|
|
|
|
layoutCount,
|
|
|
|
|
)}`}
|
2026-05-25 05:25:57 +08:00
|
|
|
>
|
2026-05-27 15:30:40 +08:00
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-05-29 17:50:53 +08:00
|
|
|
onClick={() => openLightbox(images, i, text, post.id)}
|
|
|
|
|
className="group block h-full w-full"
|
|
|
|
|
aria-label={
|
|
|
|
|
isLastSlot ? `View all ${images.length} images` : "View image"
|
|
|
|
|
}
|
2026-05-27 15:30:40 +08:00
|
|
|
>
|
2026-05-29 13:09:09 +08:00
|
|
|
<BubbleImage
|
2026-05-27 15:30:40 +08:00
|
|
|
src={att.thumbnailUrl ?? att.url}
|
|
|
|
|
loading="lazy"
|
2026-05-29 17:50:53 +08:00
|
|
|
className="h-full w-full object-cover transition duration-300 group-hover:scale-[1.03]"
|
2026-05-27 15:30:40 +08:00
|
|
|
/>
|
|
|
|
|
{isLastSlot ? (
|
2026-05-29 17:50:53 +08:00
|
|
|
<div className="absolute inset-0 flex flex-col items-center justify-center gap-0.5 bg-black/60 text-white backdrop-blur-[1px] transition group-hover:bg-black/50">
|
|
|
|
|
<span className="text-3xl font-bold leading-none md:text-4xl">
|
|
|
|
|
+{extra}
|
|
|
|
|
</span>
|
2026-05-27 15:30:40 +08:00
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
</button>
|
|
|
|
|
{!isLastSlot ? (
|
|
|
|
|
<AttachmentDownloadPill postId={post.id} attachment={att} />
|
2026-05-25 05:25:57 +08:00
|
|
|
) : null}
|
2026-05-27 15:30:40 +08:00
|
|
|
</div>
|
2026-05-25 05:25:57 +08:00
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
2026-05-26 12:07:13 +08:00
|
|
|
{text ? (
|
2026-05-28 10:36:38 +08:00
|
|
|
<div className="message-stream-copyable-text select-text whitespace-pre-wrap break-words px-4 pt-3 text-[14px] leading-6 text-neutral-100">
|
2026-05-26 12:07:13 +08:00
|
|
|
{autolink(text)}
|
2026-05-25 05:25:57 +08:00
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|