Spaces:
Runtime error
Runtime error
Download src/components/dashboard/RefreshButton.tsx from damndeepesh-dev/RippleWorkers: direct link, hf CLI and curl.
- Browser
- Download file 2.21 kB
-
https://huggingface.co/spaces/damndeepesh-dev/RippleWorkers/resolve/main/src/components/dashboard/RefreshButton.tsx
- Command line
-
hf download hf://spaces/damndeepesh-dev/RippleWorkers/src/components/dashboard/RefreshButton.tsx
-
curl -L -o RefreshButton.tsx https://huggingface.co/spaces/damndeepesh-dev/RippleWorkers/resolve/main/src/components/dashboard/RefreshButton.tsx
2.21 kB
| "use client"; | |
| import { RefreshCw, CheckCircle, AlertCircle } from "lucide-react"; | |
| import { useState } from "react"; | |
| import { useRouter } from "next/navigation"; | |
| export default function RefreshButton() { | |
| const [isLoading, setIsLoading] = useState(false); | |
| const [status, setStatus] = useState<"idle" | "success" | "error">("idle"); | |
| const router = useRouter(); | |
| const handleRefresh = async () => { | |
| setIsLoading(true); | |
| setStatus("idle"); | |
| try { | |
| const res = await fetch("/api/auth/refresh", { method: "POST" }); | |
| const data = await res.json(); | |
| if (res.ok) { | |
| setStatus("success"); | |
| setTimeout(() => setStatus("idle"), 3000); | |
| router.refresh(); | |
| } else { | |
| console.error(data); | |
| setStatus("error"); | |
| } | |
| } catch (error) { | |
| console.error(error); | |
| setStatus("error"); | |
| } finally { | |
| setIsLoading(false); | |
| } | |
| }; | |
| return ( | |
| <div className="flex items-center gap-2"> | |
| {status === "success" && ( | |
| <span className="text-sm text-green-600 flex items-center gap-1 animate-in fade-in slide-in-from-right-2"> | |
| <CheckCircle size={14} /> Refreshed | |
| </span> | |
| )} | |
| {status === "error" && ( | |
| <span className="text-sm text-red-600 flex items-center gap-1 animate-in fade-in slide-in-from-right-2"> | |
| <AlertCircle size={14} /> Failed | |
| </span> | |
| )} | |
| <button | |
| onClick={handleRefresh} | |
| disabled={isLoading} | |
| className="px-4 py-2 bg-white dark:bg-zinc-800 border border-gray-200 dark:border-zinc-700 hover:bg-gray-50 dark:hover:bg-zinc-700 text-gray-700 dark:text-gray-200 rounded-lg text-sm font-medium transition-all flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed" | |
| > | |
| <RefreshCw size={16} className={isLoading ? "animate-spin" : ""} /> | |
| {isLoading ? "Refreshing..." : "Refresh Token"} | |
| </button> | |
| </div> | |
| ); | |
| } | |