feat: add MaybeWrap component and enhance artifact admin sidebar

MaybeWrap conditionally wraps children based on a boolean prop.
Artifact sidebar now shows HoverCard with comment/UID for queue-less
entries (donations) and a Bitcoin icon.
This commit is contained in:
2026-06-07 23:05:04 +00:00 Unverified
parent 62033bbe83
commit dcaa8a88a5
3 changed files with 138 additions and 27 deletions
+55
View File
@@ -0,0 +1,55 @@
"use client";
import { Button } from "@/components/ui/button";
import { Spinner } from "@/components/ui/spinner";
import { MaybePromise } from "bun";
import { Check } from "lucide-react";
import { ComponentProps, ReactNode, useEffect, useState } from "react";
import { toast } from "sonner";
export function ActionButton({
action,
children,
onClick,
...props
}: ComponentProps<typeof Button> & { action: () => MaybePromise<void> }) {
const [state, setState] = useState<0 | 1 | 2>(0);
useEffect(() => {
if (state !== 2) return;
const tm = setTimeout(() => setState(0), 2000);
return () => clearTimeout(tm);
});
return (
<Button
disabled={state > 0}
{...props}
onClick={async (ev) => {
onClick?.(ev);
setState(1);
try {
await action();
setState(2);
} catch (e) {
toast.error("An error occured!");
console.error(e);
setState(0);
}
}}
>
{state === 0 ? children : state === 1 ? <Spinner /> : <Check />}
</Button>
);
}
export function MaybeWrap({
wrap,
wrapper,
children,
}: {
wrap: boolean;
wrapper: (props: { children?: ReactNode }) => ReactNode;
children?: ReactNode;
}) {
return wrap ? wrapper({ children }) : children;
}