This commit is contained in:
bipproduction
2025-10-21 16:25:17 +08:00
parent 313752140f
commit 49114d5664
2 changed files with 10 additions and 4 deletions

View File

@@ -3,12 +3,16 @@ import { Card, Pagination, Skeleton, Stack, Text, Title } from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks"; import { useShallowEffect } from "@mantine/hooks";
import useSWR from "swr"; import useSWR from "swr";
import dayjs from "dayjs"; import dayjs from "dayjs";
import { useLocalStorage } from "@mantine/hooks";
import { useState } from "react"; import { useState } from "react";
export default function WaHookHome() { export default function WaHookHome() {
const [page, setPage] = useState(1); const [page, setPage] = useLocalStorage({
key: "wa-hook-page",
defaultValue: 1,
})
const [totalPages, setTotalPages] = useState(1); const [totalPages, setTotalPages] = useState(1);
const { data, error, isLoading, mutate } = useSWR("/wa-hook", apiFetch["wa-hook"].list.get, { const { data, error, isLoading, mutate } = useSWR("/wa-hook",() => apiFetch["wa-hook"].list.get({ query: { page, limit: 10 } }), {
refreshInterval: 3000, refreshInterval: 3000,
revalidateOnFocus: true, revalidateOnFocus: true,
revalidateOnReconnect: true, revalidateOnReconnect: true,
@@ -20,6 +24,8 @@ export default function WaHookHome() {
useShallowEffect(() => { useShallowEffect(() => {
mutate() mutate()
setPage(data?.data?.list?.length || 1)
setTotalPages(data?.data?.count || 1)
}, []) }, [])
if (isLoading) return <Skeleton height={500} /> if (isLoading) return <Skeleton height={500} />

View File

@@ -139,7 +139,7 @@ const WaHookRoute = new Elysia({
.get("/list", async ({ query }) => { .get("/list", async ({ query }) => {
const list = await prisma.waHook.findMany({ const list = await prisma.waHook.findMany({
take: query.limit, take: query.limit,
skip: query.offset, skip: ((query.page || 1) - 1) * (query.limit || 10),
orderBy: { orderBy: {
createdAt: "desc", createdAt: "desc",
}, },
@@ -158,8 +158,8 @@ const WaHookRoute = new Elysia({
}; };
}, { }, {
query: t.Object({ query: t.Object({
page: t.Optional(t.Number({ minimum: 1, default: 1 })),
limit: t.Optional(t.Number({ minimum: 1, maximum: 100, default: 10 })), limit: t.Optional(t.Number({ minimum: 1, maximum: 100, default: 10 })),
offset: t.Optional(t.Number({ minimum: 0, default: 0 })),
}), }),
detail: { detail: {
summary: "List WhatsApp Hook", summary: "List WhatsApp Hook",