diff --git a/frontend/src/pages/resource_details_page.tsx b/frontend/src/pages/resource_details_page.tsx
index 18c96b6..19dd6e2 100644
--- a/frontend/src/pages/resource_details_page.tsx
+++ b/frontend/src/pages/resource_details_page.tsx
@@ -34,6 +34,7 @@ import {
MdOutlineArticle,
MdOutlineChevronLeft,
MdOutlineChevronRight,
+ MdOutlineClose,
MdOutlineCloud,
MdOutlineComment,
MdOutlineContentCopy,
@@ -2071,6 +2072,17 @@ function Gallery({ images, nsfw }: { images: number[], nsfw: number[] }) {
};
}, []);
+ // 预加载下一张图片
+ useEffect(() => {
+ if (images.length <= 1) return;
+
+ const nextIndex = (currentIndex + 1) % images.length;
+ const nextImageUrl = network.getImageUrl(images[nextIndex]);
+
+ const img = new Image();
+ img.src = nextImageUrl;
+ }, [currentIndex, images]);
+
if (!images || images.length === 0) {
return <>>;
}
@@ -2099,25 +2111,16 @@ function Gallery({ images, nsfw }: { images: number[], nsfw: number[] }) {
return (
<>
-
+
;
+ images: number[];
+ currentIndex: number;
+ direction: number;
+ isHovered: boolean;
+ setIsHovered: (hovered: boolean) => void;
+ goToPrevious: () => void;
+ goToNext: () => void;
+}) {
+ const [width, setWidth] = useState(0);
+ const containerRef = useRef
(null);
+
+ useEffect(() => {
+ const updateWidth = () => {
+ if (containerRef.current) {
+ console.log(containerRef.current.clientWidth);
+ setWidth(containerRef.current.clientWidth);
+ }
+ };
+ updateWidth();
+ window.addEventListener("resize", updateWidth);
+ return () => {
+ window.removeEventListener("resize", updateWidth);
+ };
+ }, []);
+
+ useEffect(() => {
+ const handleKeyDown = (e: KeyboardEvent) => {
+ if (dialogRef.current?.open) {
+ if (e.key === "ArrowLeft") {
+ e.preventDefault();
+ goToPrevious();
+ } else if (e.key === "ArrowRight") {
+ e.preventDefault();
+ goToNext();
+ } else if (e.key === "Escape") {
+ dialogRef.current?.close();
+ }
+ }
+ };
+
+ window.addEventListener("keydown", handleKeyDown);
+ return () => {
+ window.removeEventListener("keydown", handleKeyDown);
+ };
+ }, [dialogRef, goToPrevious, goToNext]);
+
+ return (
+
+ );
+}
+
function GalleryImage({src, nfsw}: {src: string, nfsw: boolean}) {
const [show, setShow] = useState(!nfsw);