terry-staging #9
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
Archive,
|
||||
Download,
|
||||
Eye,
|
||||
File,
|
||||
FileText,
|
||||
Image as ImageIcon,
|
||||
@@ -20,9 +19,7 @@ import { resourceTypeLabel } from "../resourceTypeLabels";
|
||||
import { cleanCategoryDisplayName } from "../utils/categoryDisplay";
|
||||
import { formatDateYmd } from "../utils/format";
|
||||
import { postToResource } from "../utils/postResourceAdapter";
|
||||
import type { Attachment, Post } from "../types/post";
|
||||
import { useLightbox } from "./messageStream/overlays/ImageLightbox";
|
||||
import { useVideoPlayer } from "./messageStream/overlays/VideoPlayer";
|
||||
import type { Post } from "../types/post";
|
||||
import { downloadAttachment } from "./messageStream/utils/downloadFile";
|
||||
import { useToast } from "./Toast";
|
||||
|
||||
@@ -94,8 +91,6 @@ function PopularRankRow({
|
||||
}) {
|
||||
const { t, lang } = useI18n();
|
||||
const navigate = useNavigate();
|
||||
const { openLightbox } = useLightbox();
|
||||
const { openVideo } = useVideoPlayer();
|
||||
const { showToast } = useToast();
|
||||
const [isDownloading, setIsDownloading] = useState(false);
|
||||
const [coverFailed, setCoverFailed] = useState(false);
|
||||
@@ -104,22 +99,6 @@ function PopularRankRow({
|
||||
const cover = r.coverImage && !coverFailed ? assetUrl(r.coverImage) : "";
|
||||
const isTop3 = index < MEDALS.length;
|
||||
|
||||
const first: Attachment | undefined = post.attachments[0];
|
||||
const imageAttachments = post.attachments.filter((a) => a.kind === "image");
|
||||
|
||||
const handlePreview = () => {
|
||||
if (first?.kind === "video") {
|
||||
openVideo(first);
|
||||
return;
|
||||
}
|
||||
if (imageAttachments.length > 0) {
|
||||
openLightbox(imageAttachments, 0, r.title, post.id);
|
||||
return;
|
||||
}
|
||||
// Documents / links have no inline overlay — fall through to the detail page.
|
||||
navigate(`/resource/${post.id}`);
|
||||
};
|
||||
|
||||
const handleDownload = async () => {
|
||||
if (isDownloading || !r.downloadPostId || !r.downloadAttachmentId) return;
|
||||
setIsDownloading(true);
|
||||
@@ -185,15 +164,6 @@ function PopularRankRow({
|
||||
</div>
|
||||
|
||||
<div className="relative z-10 flex shrink-0 items-center gap-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handlePreview}
|
||||
aria-label={t("preview")}
|
||||
title={t("preview")}
|
||||
className="flex h-9 w-9 items-center justify-center rounded-lg text-neutral-300 outline-none transition hover:bg-white/5 hover:text-ark-gold focus-visible:ring-2 focus-visible:ring-ark-gold/70"
|
||||
>
|
||||
<Eye className="h-[18px] w-[18px]" />
|
||||
</button>
|
||||
{r.isDownloadable ? (
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -1,27 +1,49 @@
|
||||
import { ImageOff } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
|
||||
type BubbleImageProps = {
|
||||
src: string | undefined;
|
||||
/**
|
||||
* Optional absolute URL(s) to try if `src` fails to load. Useful when `src`
|
||||
* is an optimized-but-fragile thumbnail (e.g. a root-relative thumbnailUrl)
|
||||
* and we want to fall back to the reliable full-size asset before giving up.
|
||||
*/
|
||||
fallbackSrc?: string | (string | undefined)[];
|
||||
className?: string;
|
||||
loading?: "lazy" | "eager";
|
||||
};
|
||||
|
||||
/**
|
||||
* Thumbnail <img> for message bubbles. Renders with an empty alt (decorative)
|
||||
* and, if the asset fails to load, falls back to a neutral placeholder instead
|
||||
* of the browser's broken-image box — which would otherwise expose the raw
|
||||
* file name via alt text.
|
||||
* and, if every candidate source fails to load, falls back to a neutral
|
||||
* placeholder instead of the browser's broken-image box — which would otherwise
|
||||
* expose the raw file name via alt text.
|
||||
*/
|
||||
export function BubbleImage({ src, className, loading }: BubbleImageProps) {
|
||||
const [failed, setFailed] = useState(false);
|
||||
export function BubbleImage({
|
||||
src,
|
||||
fallbackSrc,
|
||||
className,
|
||||
loading,
|
||||
}: BubbleImageProps) {
|
||||
// Ordered, de-duplicated list of sources to attempt in turn.
|
||||
const candidates = useMemo(() => {
|
||||
const extra = Array.isArray(fallbackSrc) ? fallbackSrc : [fallbackSrc];
|
||||
return [src, ...extra].filter(
|
||||
(value, index, all): value is string =>
|
||||
!!value && all.indexOf(value) === index,
|
||||
);
|
||||
}, [src, fallbackSrc]);
|
||||
|
||||
// Reset when the source changes so a reused element re-attempts the new src.
|
||||
const [attempt, setAttempt] = useState(0);
|
||||
|
||||
// Reset when the candidate set changes so a reused element re-attempts.
|
||||
useEffect(() => {
|
||||
setFailed(false);
|
||||
}, [src]);
|
||||
setAttempt(0);
|
||||
}, [candidates]);
|
||||
|
||||
if (!src || failed) {
|
||||
const current = candidates[attempt];
|
||||
|
||||
if (!current) {
|
||||
return (
|
||||
<div
|
||||
className={`flex items-center justify-center bg-gradient-to-br from-neutral-800 to-neutral-900 ${
|
||||
@@ -36,11 +58,11 @@ export function BubbleImage({ src, className, loading }: BubbleImageProps) {
|
||||
|
||||
return (
|
||||
<img
|
||||
src={src}
|
||||
src={current}
|
||||
alt=""
|
||||
loading={loading}
|
||||
className={className}
|
||||
onError={() => setFailed(true)}
|
||||
onError={() => setAttempt((i) => i + 1)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
import { LoaderCircle, X } from "lucide-react";
|
||||
import { DownloadCloudIcon } from "../../icons/DownloadCloudIcon";
|
||||
import { useEffect, useState } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { useI18n } from "../../../i18n";
|
||||
import type { Attachment, Post } from "../../../types/post";
|
||||
import type { Post } from "../../../types/post";
|
||||
import { AttachmentDownloadPill } from "../AttachmentDownloadPill";
|
||||
import { BubbleImage } from "../BubbleImage";
|
||||
import { useLightbox } from "../overlays/ImageLightbox";
|
||||
import { autolink } from "../utils/autolink";
|
||||
import { downloadAttachment } from "../utils/downloadFile";
|
||||
import { formatBytes } from "../utils/formatBytes";
|
||||
import { postDisplayText } from "../utils/postText";
|
||||
import { useToast } from "../../Toast";
|
||||
|
||||
const MAX_VISIBLE = 4;
|
||||
|
||||
@@ -26,135 +19,9 @@ function albumItemClass(index: number, count: number) {
|
||||
return "";
|
||||
}
|
||||
|
||||
function ImageListDownloadButton({
|
||||
postId,
|
||||
attachment,
|
||||
}: {
|
||||
postId: string;
|
||||
attachment: Attachment;
|
||||
}) {
|
||||
const { t } = useI18n();
|
||||
const { showToast } = useToast();
|
||||
const [isDownloading, setIsDownloading] = useState(false);
|
||||
|
||||
const handleDownload = async () => {
|
||||
if (isDownloading) return;
|
||||
setIsDownloading(true);
|
||||
try {
|
||||
await downloadAttachment(postId, attachment.id, attachment.filename);
|
||||
showToast(t("downloadOk"));
|
||||
} catch {
|
||||
showToast(t("downloadFail"), "error");
|
||||
} finally {
|
||||
setIsDownloading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleDownload();
|
||||
}}
|
||||
disabled={isDownloading}
|
||||
className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-white/10 text-white transition hover:bg-white/20 disabled:cursor-wait"
|
||||
aria-label={
|
||||
isDownloading ? t("downloading") : `Download ${attachment.filename}`
|
||||
}
|
||||
aria-busy={isDownloading}
|
||||
>
|
||||
{isDownloading ? (
|
||||
<LoaderCircle className="h-4 w-4 animate-spin" strokeWidth={2.3} />
|
||||
) : (
|
||||
<DownloadCloudIcon className="h-4 w-4" />
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function ImageListDialog({
|
||||
postId,
|
||||
images,
|
||||
onClose,
|
||||
onPick,
|
||||
}: {
|
||||
postId: string;
|
||||
images: Attachment[];
|
||||
onClose: () => void;
|
||||
onPick: (index: number) => void;
|
||||
}) {
|
||||
useEffect(() => {
|
||||
const onKey = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") onClose();
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [onClose]);
|
||||
|
||||
return createPortal(
|
||||
<div
|
||||
className="fixed inset-0 z-[100] flex items-center justify-center bg-black/75 px-4 backdrop-blur-sm"
|
||||
onClick={onClose}
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label="Image list"
|
||||
>
|
||||
<div
|
||||
className="w-full max-w-md overflow-hidden rounded-2xl border border-ark-line bg-ark-panel shadow-2xl"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div className="flex items-center justify-between border-b border-ark-line px-4 py-3">
|
||||
<div className="text-sm font-semibold text-neutral-100">选择图片</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="flex h-8 w-8 items-center justify-center rounded-full bg-white/10 text-white transition hover:bg-white/20"
|
||||
aria-label="Close"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
<div className="max-h-[70vh] overflow-y-auto p-2 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
|
||||
{images.map((image, index) => (
|
||||
<div
|
||||
key={image.id}
|
||||
className="flex w-full items-center gap-3 rounded-xl p-2 text-left transition hover:bg-white/5"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onPick(index)}
|
||||
className="flex min-w-0 flex-1 items-center gap-3 text-left"
|
||||
>
|
||||
<div className="h-16 w-16 shrink-0 overflow-hidden rounded-lg bg-black">
|
||||
<BubbleImage
|
||||
src={image.thumbnailUrl ?? image.url}
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate text-sm font-medium text-neutral-100">
|
||||
图片 {index + 1}
|
||||
</div>
|
||||
<div className="mt-1 truncate text-xs text-neutral-400">
|
||||
{formatBytes(image.sizeBytes)}
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
<ImageListDownloadButton postId={postId} attachment={image} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>,
|
||||
document.body,
|
||||
);
|
||||
}
|
||||
|
||||
export function AlbumBubble({ post }: { post: Post }) {
|
||||
const { openLightbox } = useLightbox();
|
||||
const { lang } = useI18n();
|
||||
const [listOpen, setListOpen] = useState(false);
|
||||
const images = post.attachments;
|
||||
const text = postDisplayText(post, lang);
|
||||
const visible = images.slice(0, MAX_VISIBLE);
|
||||
@@ -176,21 +43,23 @@ export function AlbumBubble({ post }: { post: Post }) {
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
if (isLastSlot) setListOpen(true);
|
||||
else openLightbox(images, i, text, post.id);
|
||||
}}
|
||||
className="block h-full w-full"
|
||||
aria-label={isLastSlot ? "Open image list" : "View image"}
|
||||
onClick={() => openLightbox(images, i, text, post.id)}
|
||||
className="group block h-full w-full"
|
||||
aria-label={
|
||||
isLastSlot ? `View all ${images.length} images` : "View image"
|
||||
}
|
||||
>
|
||||
<BubbleImage
|
||||
src={att.thumbnailUrl ?? att.url}
|
||||
src={att.thumbnailUrl ?? att.thumbUrl ?? att.url}
|
||||
fallbackSrc={[att.thumbUrl, att.url]}
|
||||
loading="lazy"
|
||||
className="h-full w-full object-cover"
|
||||
className="h-full w-full object-cover transition duration-300 group-hover:scale-[1.03]"
|
||||
/>
|
||||
{isLastSlot ? (
|
||||
<div className="absolute inset-0 flex items-center justify-center bg-black/55 text-4xl font-bold text-white">
|
||||
+{extra}
|
||||
<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>
|
||||
</div>
|
||||
) : null}
|
||||
</button>
|
||||
@@ -206,17 +75,6 @@ export function AlbumBubble({ post }: { post: Post }) {
|
||||
{autolink(text)}
|
||||
</div>
|
||||
) : null}
|
||||
{listOpen ? (
|
||||
<ImageListDialog
|
||||
postId={post.id}
|
||||
images={images}
|
||||
onClose={() => setListOpen(false)}
|
||||
onPick={(index) => {
|
||||
setListOpen(false);
|
||||
openLightbox(images, index, text, post.id);
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,9 +8,14 @@ import {
|
||||
type PropsWithChildren,
|
||||
} from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { ChevronLeft, ChevronRight, X } from "lucide-react";
|
||||
import { ChevronLeft, ChevronRight, LoaderCircle, X } from "lucide-react";
|
||||
import type { Attachment } from "../../../types/post";
|
||||
import { DownloadCloudIcon } from "../../icons/DownloadCloudIcon";
|
||||
import { useI18n } from "../../../i18n";
|
||||
import { useToast } from "../../Toast";
|
||||
import { BubbleImage } from "../BubbleImage";
|
||||
import { autolink } from "../utils/autolink";
|
||||
import { downloadAttachment } from "../utils/downloadFile";
|
||||
|
||||
type LightboxState = {
|
||||
images: Attachment[];
|
||||
@@ -65,6 +70,7 @@ export function ImageLightboxProvider({ children }: PropsWithChildren) {
|
||||
images={state.images}
|
||||
startIndex={state.index}
|
||||
caption={state.caption}
|
||||
postId={state.postId}
|
||||
onClose={closeLightbox}
|
||||
/>
|
||||
) : null}
|
||||
@@ -72,15 +78,121 @@ export function ImageLightboxProvider({ children }: PropsWithChildren) {
|
||||
);
|
||||
}
|
||||
|
||||
function LightboxDownloadButton({
|
||||
postId,
|
||||
attachment,
|
||||
}: {
|
||||
postId: string;
|
||||
attachment: Attachment;
|
||||
}) {
|
||||
const { t } = useI18n();
|
||||
const { showToast } = useToast();
|
||||
const [isDownloading, setIsDownloading] = useState(false);
|
||||
|
||||
const handleDownload = async () => {
|
||||
if (isDownloading) return;
|
||||
setIsDownloading(true);
|
||||
try {
|
||||
await downloadAttachment(postId, attachment.id, attachment.filename);
|
||||
showToast(t("downloadOk"));
|
||||
} catch {
|
||||
showToast(t("downloadFail"), "error");
|
||||
} finally {
|
||||
setIsDownloading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleDownload();
|
||||
}}
|
||||
disabled={isDownloading}
|
||||
className="flex h-10 w-10 items-center justify-center rounded-full bg-white/10 text-white transition hover:bg-white/20 disabled:cursor-wait"
|
||||
aria-label={isDownloading ? t("downloading") : t("download")}
|
||||
aria-busy={isDownloading}
|
||||
>
|
||||
{isDownloading ? (
|
||||
<LoaderCircle className="h-5 w-5 animate-spin" strokeWidth={2.3} />
|
||||
) : (
|
||||
<DownloadCloudIcon className="h-5 w-5" />
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function Filmstrip({
|
||||
images,
|
||||
index,
|
||||
onSelect,
|
||||
}: {
|
||||
images: Attachment[];
|
||||
index: number;
|
||||
onSelect: (i: number) => void;
|
||||
}) {
|
||||
const activeRef = useRef<HTMLButtonElement | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
activeRef.current?.scrollIntoView({
|
||||
behavior: "smooth",
|
||||
block: "nearest",
|
||||
inline: "center",
|
||||
});
|
||||
}, [index]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className="shrink-0 bg-gradient-to-t from-black/90 to-transparent pb-[max(env(safe-area-inset-bottom),0.75rem)] pt-3"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div className="overflow-x-auto px-4 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
|
||||
<div className="mx-auto flex w-fit max-w-[920px] gap-2">
|
||||
{images.map((image, i) => {
|
||||
const active = i === index;
|
||||
return (
|
||||
<button
|
||||
key={image.id}
|
||||
ref={active ? activeRef : null}
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onSelect(i);
|
||||
}}
|
||||
className={`relative h-14 w-14 shrink-0 overflow-hidden rounded-lg bg-black transition duration-200 md:h-16 md:w-16 ${
|
||||
active
|
||||
? "opacity-100 ring-2 ring-white"
|
||||
: "opacity-45 hover:opacity-80"
|
||||
}`}
|
||||
aria-label={`Image ${i + 1}`}
|
||||
aria-current={active}
|
||||
>
|
||||
<BubbleImage
|
||||
src={image.thumbnailUrl ?? image.thumbUrl ?? image.url}
|
||||
fallbackSrc={[image.thumbUrl, image.url]}
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function LightboxView({
|
||||
images,
|
||||
startIndex,
|
||||
caption: captionText,
|
||||
postId,
|
||||
onClose,
|
||||
}: {
|
||||
images: Attachment[];
|
||||
startIndex: number;
|
||||
caption?: string;
|
||||
postId?: string;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const [index, setIndex] = useState(startIndex);
|
||||
@@ -103,13 +215,21 @@ function LightboxView({
|
||||
if (e.key === "ArrowRight") goNext();
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [goPrev, goNext, onClose]);
|
||||
|
||||
// Lock background scroll while the lightbox is open, then restore the exact
|
||||
// scroll position on close — otherwise dismissing the overlay leaves the page
|
||||
// scrolled back to the top instead of where the user was reading.
|
||||
useEffect(() => {
|
||||
const scrollY = window.scrollY;
|
||||
const prevOverflow = document.body.style.overflow;
|
||||
document.body.style.overflow = "hidden";
|
||||
return () => {
|
||||
window.removeEventListener("keydown", onKey);
|
||||
document.body.style.overflow = prevOverflow;
|
||||
window.scrollTo(0, scrollY);
|
||||
};
|
||||
}, [goPrev, goNext, onClose]);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
setIsCaptionVisible(true);
|
||||
@@ -118,6 +238,7 @@ function LightboxView({
|
||||
const current = images[index];
|
||||
const caption = captionText?.trim();
|
||||
const showCaption = !!caption && isCaptionVisible;
|
||||
const hasMany = images.length > 1;
|
||||
if (!current) return null;
|
||||
|
||||
return createPortal(
|
||||
@@ -127,51 +248,64 @@ function LightboxView({
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onClose();
|
||||
}}
|
||||
className="absolute right-4 top-4 z-10 flex h-10 w-10 items-center justify-center rounded-full bg-white/10 text-white transition hover:bg-white/20"
|
||||
aria-label="Close"
|
||||
{/* Top bar: counter + actions */}
|
||||
<div
|
||||
className="relative z-20 flex shrink-0 items-center justify-between px-4 pb-2 pt-[max(env(safe-area-inset-top),1rem)]"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<X className="h-5 w-5" />
|
||||
</button>
|
||||
|
||||
{images.length > 1 ? (
|
||||
<>
|
||||
<div className="flex h-10 items-center">
|
||||
{hasMany ? (
|
||||
<span className="rounded-full bg-white/10 px-3 py-1 text-xs font-medium text-white">
|
||||
{index + 1} / {images.length}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{postId ? (
|
||||
<LightboxDownloadButton postId={postId} attachment={current} />
|
||||
) : null}
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
goPrev();
|
||||
}}
|
||||
className="absolute left-2 top-1/2 z-10 flex h-12 w-12 -translate-y-1/2 items-center justify-center rounded-full bg-white/10 text-white transition hover:bg-white/20 md:left-6"
|
||||
aria-label="Previous"
|
||||
onClick={onClose}
|
||||
className="flex h-10 w-10 items-center justify-center rounded-full bg-white/10 text-white transition hover:bg-white/20"
|
||||
aria-label="Close"
|
||||
>
|
||||
<ChevronLeft className="h-6 w-6" />
|
||||
<X className="h-5 w-5" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
goNext();
|
||||
}}
|
||||
className="absolute right-2 top-1/2 z-10 flex h-12 w-12 -translate-y-1/2 items-center justify-center rounded-full bg-white/10 text-white transition hover:bg-white/20 md:right-6"
|
||||
aria-label="Next"
|
||||
>
|
||||
<ChevronRight className="h-6 w-6" />
|
||||
</button>
|
||||
<div className="absolute left-1/2 top-4 z-10 -translate-x-1/2 rounded-full bg-white/10 px-3 py-1 text-xs text-white">
|
||||
{index + 1} / {images.length}
|
||||
</div>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Image stage */}
|
||||
<div className="relative flex min-h-0 w-full flex-1 items-center justify-center">
|
||||
{hasMany ? (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
goPrev();
|
||||
}}
|
||||
className="absolute left-2 top-1/2 z-10 flex h-12 w-12 -translate-y-1/2 items-center justify-center rounded-full bg-white/10 text-white transition hover:bg-white/20 md:left-6"
|
||||
aria-label="Previous"
|
||||
>
|
||||
<ChevronLeft className="h-6 w-6" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
goNext();
|
||||
}}
|
||||
className="absolute right-2 top-1/2 z-10 flex h-12 w-12 -translate-y-1/2 items-center justify-center rounded-full bg-white/10 text-white transition hover:bg-white/20 md:right-6"
|
||||
aria-label="Next"
|
||||
>
|
||||
<ChevronRight className="h-6 w-6" />
|
||||
</button>
|
||||
</>
|
||||
) : null}
|
||||
|
||||
<div className="flex min-h-0 w-full flex-1 items-center justify-center px-4 py-16">
|
||||
<div
|
||||
className="flex h-full w-full items-center justify-center"
|
||||
className="flex h-full w-full items-center justify-center px-4 py-2"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
if (caption) setIsCaptionVisible((visible) => !visible);
|
||||
@@ -192,21 +326,26 @@ function LightboxView({
|
||||
<img
|
||||
src={current.url}
|
||||
alt={current.filename}
|
||||
className="max-h-full max-w-full object-contain select-none"
|
||||
className="max-h-full max-w-full select-none object-contain"
|
||||
draggable={false}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{showCaption ? (
|
||||
<div
|
||||
className="absolute inset-x-0 bottom-0 z-20 bg-gradient-to-t from-black via-black/90 to-black/70 px-4 py-4 text-sm leading-snug text-white sm:px-6"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div className="message-stream-copyable-text mx-auto max-h-[32vh] max-w-[920px] overflow-y-auto whitespace-pre-wrap break-words [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
|
||||
{autolink(caption)}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{showCaption ? (
|
||||
<div
|
||||
className="absolute inset-x-0 bottom-0 z-20 bg-gradient-to-t from-black via-black/90 to-black/70 px-4 py-4 text-sm leading-snug text-white sm:px-6"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div className="message-stream-copyable-text mx-auto max-h-[32vh] max-w-[920px] overflow-y-auto whitespace-pre-wrap break-words [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
|
||||
{autolink(caption)}
|
||||
</div>
|
||||
</div>
|
||||
{/* Bottom thumbnail filmstrip */}
|
||||
{hasMany ? (
|
||||
<Filmstrip images={images} index={index} onSelect={setIndex} />
|
||||
) : null}
|
||||
</div>,
|
||||
document.body,
|
||||
|
||||
@@ -343,6 +343,7 @@ export function PublicLayout() {
|
||||
to="/"
|
||||
className="flex h-8 shrink-0 items-center gap-2 rounded-sm text-[20px] font-black leading-5 tracking-tight text-ark-gold outline-none focus-visible:ring-2 focus-visible:ring-ark-gold/80 focus-visible:ring-offset-2 focus-visible:ring-offset-[#08070c]"
|
||||
aria-label={t("brand")}
|
||||
onClick={(e) => { if (isHome) { e.preventDefault(); window.scrollTo({ top: 0, behavior: "smooth" }); } }}
|
||||
>
|
||||
<ArkLogoMark className="h-8 w-8 shrink-0" />
|
||||
<span className="truncate text-ark-gold">{t("brand")}</span>
|
||||
@@ -412,6 +413,7 @@ export function PublicLayout() {
|
||||
<Link
|
||||
to="/"
|
||||
className="flex min-w-0 shrink-0 items-center gap-2.5 rounded-sm text-xl font-bold tracking-wide text-ark-gold outline-none focus-visible:ring-2 focus-visible:ring-ark-gold/80 focus-visible:ring-offset-2 focus-visible:ring-offset-ark-bg"
|
||||
onClick={(e) => { if (isHome) { e.preventDefault(); window.scrollTo({ top: 0, behavior: "smooth" }); } }}
|
||||
>
|
||||
<ArkLogoMark className="h-10 w-10 shrink-0" />
|
||||
<span className="max-w-[8rem] truncate text-ark-gold sm:inline">
|
||||
|
||||
@@ -4,10 +4,6 @@ import { useEffect, useRef, useState } from "react";
|
||||
import { getJSON, itemsOrEmpty, readJSONCache, type Category } from "../../api";
|
||||
import { CategoryIcon } from "../../components/CategoryIcon";
|
||||
import { FigmaBanner } from "../../components/FigmaBanner";
|
||||
import {
|
||||
ComingSoonLatestUpdateRow,
|
||||
LatestUpdateRow,
|
||||
} from "../../components/LatestUpdateRow";
|
||||
import { PopularRankList } from "../../components/PopularRankList";
|
||||
import { RecommendedCard } from "../../components/RecommendedCard";
|
||||
import { SectionHeader } from "../../components/SectionHeader";
|
||||
@@ -49,17 +45,14 @@ export function Home() {
|
||||
const { hash } = useLocation();
|
||||
const [cats, setCats] = useState<Category[]>([]);
|
||||
const [rec, setRec] = useState<PostBackedResource[]>([]);
|
||||
const [latest, setLatest] = useState<PostBackedResource[]>([]);
|
||||
const [latestPosts, setLatestPosts] = useState<Post[]>([]);
|
||||
const [popular, setPopular] = useState<PostBackedResource[]>([]);
|
||||
const [popularPosts, setPopularPosts] = useState<Post[]>([]);
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
const recRowRef = useRef<HTMLDivElement>(null);
|
||||
const latestRowRef = useRef<HTMLDivElement>(null);
|
||||
const categoryRowRef = useRef<HTMLDivElement>(null);
|
||||
const [activeCategoryPage, setActiveCategoryPage] = useState(0);
|
||||
const [canScrollRec, setCanScrollRec] = useState(false);
|
||||
const [canScrollLatest, setCanScrollLatest] = useState(false);
|
||||
const [recScroll, setRecScroll] = useState({ ratio: 1, progress: 0 });
|
||||
|
||||
useEffect(() => {
|
||||
@@ -88,9 +81,6 @@ export function Home() {
|
||||
);
|
||||
const latestItems = itemsOrEmpty(l.items);
|
||||
setLatestPosts(latestItems);
|
||||
setLatest(
|
||||
latestItems.map((post) => postToResource(post, lang, categoryItems)),
|
||||
);
|
||||
const popularItems = itemsOrEmpty<Post>(p.items);
|
||||
setPopularPosts(popularItems);
|
||||
setPopular(
|
||||
@@ -139,9 +129,6 @@ export function Home() {
|
||||
};
|
||||
}, [lang]);
|
||||
|
||||
const iconKeyForResource = (r: PostBackedResource) =>
|
||||
cats.find((c) => c.id === r.categoryId)?.iconKey ?? "folder";
|
||||
|
||||
const figmaOrderedCategories = [...cats].sort(
|
||||
(a, b) => figmaCategoryRank(a) - figmaCategoryRank(b),
|
||||
);
|
||||
@@ -208,31 +195,6 @@ export function Home() {
|
||||
recRowRef.current?.scrollBy({ left: dir * 280, behavior: "smooth" });
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const row = latestRowRef.current;
|
||||
if (!row) {
|
||||
setCanScrollLatest(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const update = () => {
|
||||
setCanScrollLatest(row.scrollWidth > row.clientWidth + 1);
|
||||
};
|
||||
|
||||
update();
|
||||
const resizeObserver = new ResizeObserver(update);
|
||||
resizeObserver.observe(row);
|
||||
row.addEventListener("scroll", update, { passive: true });
|
||||
return () => {
|
||||
resizeObserver.disconnect();
|
||||
row.removeEventListener("scroll", update);
|
||||
};
|
||||
}, [latest.length]);
|
||||
|
||||
const scrollLatest = (dir: 1 | -1) => {
|
||||
latestRowRef.current?.scrollBy({ left: dir * 360, behavior: "smooth" });
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!hash) return;
|
||||
const id = hash.slice(1);
|
||||
@@ -243,9 +205,8 @@ export function Home() {
|
||||
});
|
||||
});
|
||||
return () => window.cancelAnimationFrame(frame);
|
||||
}, [hash, cats.length, rec.length, latest.length, popular.length]);
|
||||
}, [hash, cats.length, rec.length, latestPosts.length, popular.length]);
|
||||
|
||||
const latestPlaceholderCount = Math.max(0, 5 - latest.length);
|
||||
const hasPopular = popular.length > 0 || popularPosts.length > 0;
|
||||
const recommendedDotCount = rec.length;
|
||||
const activeRecommendedDot =
|
||||
@@ -446,59 +407,21 @@ export function Home() {
|
||||
|
||||
<Reveal>
|
||||
<section id="latest" className="scroll-mt-16 md:scroll-mt-24">
|
||||
<div className="px-4 md:px-0">
|
||||
<SectionHeader
|
||||
title={t("latestSection")}
|
||||
viewAllTo="/browse"
|
||||
viewAllLabel={t("viewAll")}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-3 md:hidden">
|
||||
{latestPosts.slice(0, 5).map((post) => (
|
||||
<MessageBubble key={post.id} post={post} />
|
||||
))}
|
||||
</div>
|
||||
<div className="relative hidden md:block">
|
||||
<div
|
||||
ref={latestRowRef}
|
||||
className="mt-7 flex gap-4 overflow-x-auto overflow-y-hidden pb-5 scroll-smooth [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"
|
||||
>
|
||||
{latest.map((r) => (
|
||||
<div key={r.id} className="w-[340px] shrink-0 xl:w-[352px]">
|
||||
<LatestUpdateRow r={r} iconKey={iconKeyForResource(r)} />
|
||||
</div>
|
||||
))}
|
||||
{Array.from({ length: latestPlaceholderCount }).map(
|
||||
(_, index) => (
|
||||
<div
|
||||
key={`latest-coming-soon-${index}`}
|
||||
className="w-[340px] shrink-0 xl:w-[352px]"
|
||||
>
|
||||
<ComingSoonLatestUpdateRow index={latest.length + index} />
|
||||
</div>
|
||||
),
|
||||
)}
|
||||
<div className="mx-auto max-w-full md:max-w-[820px] lg:max-w-[1080px] xl:max-w-[1180px]">
|
||||
<div className="px-4 md:px-0">
|
||||
<SectionHeader
|
||||
title={t("latestSection")}
|
||||
viewAllTo="/browse"
|
||||
viewAllLabel={t("viewAll")}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-4 flex flex-col gap-3 md:mt-7">
|
||||
{latestPosts.slice(0, 5).map((post, index) => (
|
||||
<Reveal key={post.id} delay={Math.min(index, 8) * 0.05}>
|
||||
<MessageBubble post={post} />
|
||||
</Reveal>
|
||||
))}
|
||||
</div>
|
||||
{canScrollLatest ? (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => scrollLatest(-1)}
|
||||
className="absolute left-0 top-[45%] hidden h-9 w-9 -translate-y-1/2 items-center justify-center rounded-lg border border-ark-line bg-[#292a31]/95 text-neutral-200 shadow-lg backdrop-blur transition hover:border-ark-gold hover:text-ark-gold md:flex"
|
||||
aria-label="Previous latest updates"
|
||||
>
|
||||
<ChevronLeft className="h-5 w-5" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => scrollLatest(1)}
|
||||
className="absolute right-0 top-[45%] hidden h-9 w-9 -translate-y-1/2 items-center justify-center rounded-lg border border-ark-line bg-[#292a31]/95 text-neutral-200 shadow-lg backdrop-blur transition hover:border-ark-gold hover:text-ark-gold md:flex"
|
||||
aria-label="Next latest updates"
|
||||
>
|
||||
<ChevronRight className="h-5 w-5" />
|
||||
</button>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
</section>
|
||||
</Reveal>
|
||||
|
||||
@@ -30,6 +30,7 @@ export type Attachment = {
|
||||
height?: number;
|
||||
durationSec?: number;
|
||||
posterUrl?: string;
|
||||
thumbUrl?: string;
|
||||
thumbnailUrl?: string;
|
||||
};
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ function coverFor(att: Attachment | undefined) {
|
||||
if (att.kind === "image" || att.mime.startsWith("image/")) {
|
||||
return att.thumbnailUrl || att.url;
|
||||
}
|
||||
return att.posterUrl || att.thumbnailUrl || "";
|
||||
return att.posterUrl || att.thumbUrl || att.thumbnailUrl || "";
|
||||
}
|
||||
|
||||
export function postToResource(
|
||||
|
||||
@@ -4,6 +4,17 @@ import react from "@vitejs/plugin-react";
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), "");
|
||||
const apiProxyTarget = env.DEV_API_PROXY_TARGET || "http://127.0.0.1:8080";
|
||||
// Uploaded assets (thumbnails etc.) are served from the site root, NOT under
|
||||
// the API's /apnew prefix. Proxy /uploads to the origin root so relative
|
||||
// thumbnailUrls like "/uploads/thumb52-….jpg" resolve to a real image in dev
|
||||
// instead of falling through to the SPA's index.html.
|
||||
const uploadsProxyTarget = (() => {
|
||||
try {
|
||||
return new URL(apiProxyTarget).origin;
|
||||
} catch {
|
||||
return apiProxyTarget;
|
||||
}
|
||||
})();
|
||||
|
||||
return {
|
||||
plugins: [react()],
|
||||
@@ -26,7 +37,7 @@ export default defineConfig(({ mode }) => {
|
||||
rewrite: (path) => path.replace(/^\/apnew/, ""),
|
||||
},
|
||||
"/api": { target: apiProxyTarget, changeOrigin: true },
|
||||
"/uploads": { target: apiProxyTarget, changeOrigin: true },
|
||||
"/uploads": { target: uploadsProxyTarget, changeOrigin: true },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user