From 0a34ed130de8cd5b4867345f51f66e371478ee0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=87=E8=B6=A3=E4=BF=9D=E7=BD=97?= Date: Sat, 6 Jan 2024 02:32:44 +0800 Subject: [PATCH] Feat(Gallery): Adds Pagination MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 相册翻页功能,顺带优化图片加载高度闪烁的问题 --- app/routes/gallery.$/route.tsx | 23 +++++++++++++++++------ app/routes/gallery.$/styles.module.less | 2 ++ app/routes/note._index.tsx | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/routes/gallery.$/route.tsx b/app/routes/gallery.$/route.tsx index 6aae711..7723723 100644 --- a/app/routes/gallery.$/route.tsx +++ b/app/routes/gallery.$/route.tsx @@ -1,5 +1,6 @@ -import { NavLink, useLoaderData } from "@remix-run/react"; +import { NavLink, useLoaderData, useNavigate } from "@remix-run/react"; import { json, LoaderFunctionArgs, type MetaFunction } from "@remix-run/node"; +import Pagination from "~/components/common/pagination"; import { clsn, siteTitle } from "~/utils"; import styles from "./styles.module.less"; @@ -7,7 +8,7 @@ import styles from "./styles.module.less"; export const meta: MetaFunction = ({ data }) => { return [ { title: siteTitle(data?.currentCategory?.name || "相册") }, - { name: "description", content: "奇趣保罗的日常笔记" }, + { name: "description", content: data?.currentCategory?.description || "奇趣保罗的照片与收藏" }, ]; }; @@ -34,11 +35,18 @@ export async function loader({ request, params }: LoaderFunctionArgs) { const media = await fetch(`https://paul.ren/api/media/?${searchParams.toString()}`).then((res) => res.json()) as unknown as API.PageResponse; const currentCategory = cateIndex > -1 ? category.data[cateIndex]: undefined; - return json({ media, category, currentCategory }); + return json({ media, category, currentCategory, page }); } export default function Gallery() { - const { media, category } = useLoaderData(); + const navigate = useNavigate(); + const { media, category, page } = useLoaderData(); + + const onChangePage = (value: number) => { + navigate({ + search: `?page=${value}`, + }); + }; return (
@@ -55,10 +63,10 @@ export default function Gallery() { ))} -
+
{media.data.map((item) => (
- {item.title} + {item.title}
{item.take_time.substring(0, 10)}

{item.title}

@@ -66,6 +74,9 @@ export default function Gallery() {
))}
+
+ +
); } diff --git a/app/routes/gallery.$/styles.module.less b/app/routes/gallery.$/styles.module.less index 2243420..8223182 100644 --- a/app/routes/gallery.$/styles.module.less +++ b/app/routes/gallery.$/styles.module.less @@ -1,4 +1,6 @@ .image { + width: 100%; aspect-ratio: 1 / 1; + background-color: #999; clip-path: polygon(0 0, 100% 0%, 100% 100%, 0 75%); } diff --git a/app/routes/note._index.tsx b/app/routes/note._index.tsx index b87671c..a63e8df 100644 --- a/app/routes/note._index.tsx +++ b/app/routes/note._index.tsx @@ -83,7 +83,7 @@ export default function Note() {