infoalloggi-monorepo/apps/infoalloggi/src/components/subscriptionDbg.tsx

66 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-08-04 17:45:44 +02:00
import { cn } from "~/lib/utils";
import { run } from "~/utils/utils";
export function SubscriptionStatus({
2025-08-28 18:27:07 +02:00
status,
errorMsg,
reset,
2025-08-04 17:45:44 +02:00
}: {
2025-08-28 18:27:07 +02:00
status: "idle" | "connecting" | "pending" | "error";
errorMsg: string | undefined;
reset: () => void;
2025-08-04 17:45:44 +02:00
}) {
2025-08-28 18:27:07 +02:00
return (
<div
className={cn(
"rounded-full p-2 text-sm transition-colors",
run(() => {
switch (status) {
case "idle":
case "connecting":
return "bg-white text-gray-500 dark:bg-gray-900 dark:text-gray-400";
case "error":
return "bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200";
case "pending":
return "bg-emerald-100 text-emerald-800 dark:bg-emerald-900 dark:text-emerald-200";
}
}),
)}
>
{run(() => {
switch (status) {
case "idle":
case "connecting":
// treat idle and connecting the same
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
return (
<div>
Connecting...
{errorMsg && " (There are connection problems)"} {errorMsg}
</div>
);
case "error":
// something went wrong
return (
<div>
Error - <em>{errorMsg}</em>
<button
type="button"
onClick={() => {
reset();
}}
className="hover:underline"
>
Try Again
</button>
</div>
);
case "pending":
// we are polling for new messages
return <div>Connected - awaiting messages</div>;
}
})}
</div>
);
2025-08-04 17:45:44 +02:00
}