This commit is contained in:
bipproduction
2025-10-21 16:26:38 +08:00
parent 49114d5664
commit 3cc04e42c2

View File

@@ -1,17 +1,14 @@
import apiFetch from "@/lib/apiFetch"; import apiFetch from "@/lib/apiFetch";
import { Card, Pagination, Skeleton, Stack, Text, Title } from "@mantine/core"; import { Card, Pagination, Skeleton, Stack, Text, Title } from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks"; import { useLocalStorage, useShallowEffect } from "@mantine/hooks";
import useSWR from "swr";
import dayjs from "dayjs"; import dayjs from "dayjs";
import { useLocalStorage } from "@mantine/hooks"; import useSWR from "swr";
import { useState } from "react";
export default function WaHookHome() { export default function WaHookHome() {
const [page, setPage] = useLocalStorage({ const [page, setPage] = useLocalStorage({
key: "wa-hook-page", key: "wa-hook-page",
defaultValue: 1, defaultValue: 1,
}) })
const [totalPages, setTotalPages] = useState(1);
const { data, error, isLoading, mutate } = useSWR("/wa-hook",() => apiFetch["wa-hook"].list.get({ query: { page, limit: 10 } }), { 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,
@@ -25,7 +22,6 @@ export default function WaHookHome() {
useShallowEffect(() => { useShallowEffect(() => {
mutate() mutate()
setPage(data?.data?.list?.length || 1) setPage(data?.data?.list?.length || 1)
setTotalPages(data?.data?.count || 1)
}, []) }, [])
if (isLoading) return <Skeleton height={500} /> if (isLoading) return <Skeleton height={500} />
@@ -48,7 +44,7 @@ export default function WaHookHome() {
))} ))}
<Pagination <Pagination
value={page} value={page}
total={totalPages} total={data?.data?.count || 1}
onChange={setPage} onChange={setPage}
withEdges withEdges
/> />