29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
"use client";
|
|
|
|
import { useRouter } from "next/navigation";
|
|
import { useTransition, type ComponentProps } from "react";
|
|
import { RefreshCwIcon } from "lucide-react";
|
|
import { toast } from "sonner";
|
|
|
|
import { syncStygianArchiveAction } from "@/app/admin/stygian/actions";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Spinner } from "@/components/ui/spinner";
|
|
|
|
export function StygianSyncButton({ size }: Pick<ComponentProps<typeof Button>, "size"> = {}) {
|
|
const router = useRouter();
|
|
const [pending, startTransition] = useTransition();
|
|
return (
|
|
<Button size={size} disabled={pending} onClick={() => startTransition(async () => {
|
|
const result = await syncStygianArchiveAction();
|
|
if (result.status === "error") toast.error(result.message);
|
|
else {
|
|
toast.success(`Imported through ${result.imported.at(-1) ?? "none"}; stopped at ${result.stoppedAt}`);
|
|
router.refresh();
|
|
}
|
|
})}>
|
|
{pending ? <Spinner data-icon="inline-start" /> : <RefreshCwIcon data-icon="inline-start" />}
|
|
Sync archive
|
|
</Button>
|
|
);
|
|
}
|