feat: add refresh button to various dashboard pages for improved data fetching
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
||||
Table,
|
||||
TextField,
|
||||
} from "@heroui/react";
|
||||
import { ArrowLeft, Pencil, PlugConnection } from "@gravity-ui/icons";
|
||||
import { ArrowLeft, Pencil, PlugConnection, ArrowRotateRight } from "@gravity-ui/icons";
|
||||
import { api } from "@/lib/api";
|
||||
import { useSession } from "@/lib/auth-client";
|
||||
|
||||
@@ -107,7 +107,7 @@ export default function ChargePointDetailPage({ params }: { params: Promise<{ id
|
||||
feePerKwh: "0",
|
||||
});
|
||||
|
||||
const cpQuery = useQuery({
|
||||
const { isFetching: refreshing, ...cpQuery } = useQuery({
|
||||
queryKey: ["chargePoint", id],
|
||||
queryFn: () => api.chargePoints.get(id),
|
||||
refetchInterval: 3_000,
|
||||
@@ -227,12 +227,17 @@ export default function ChargePointDetailPage({ params }: { params: Promise<{ id
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{isAdmin && (
|
||||
<Button size="sm" variant="secondary" onPress={openEdit}>
|
||||
<Pencil className="size-4" />
|
||||
编辑
|
||||
<div className="flex items-center gap-2">
|
||||
<Button isIconOnly size="sm" variant="ghost" isDisabled={refreshing} onPress={() => cpQuery.refetch()} aria-label="刷新">
|
||||
<ArrowRotateRight className={`size-4 ${refreshing ? "animate-spin" : ""}`} />
|
||||
</Button>
|
||||
)}
|
||||
{isAdmin && (
|
||||
<Button size="sm" variant="secondary" onPress={openEdit}>
|
||||
<Pencil className="size-4" />
|
||||
编辑
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Info grid */}
|
||||
|
||||
Reference in New Issue
Block a user