Merge pull request #189 from tushar-daiya/promiseToaster

Sonner promise toaster added
This commit is contained in:
Dhravya Shah 2024-07-30 20:40:13 -07:00 committed by GitHub
commit f7ef7df638
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -111,34 +111,19 @@ function Menu() {
const handleSubmit = async (content?: string, spaces?: number[]) => {
setDialogOpen(false);
toast.info("Creating memory...", {
icon: <PlusCircleIcon className="w-4 h-4 text-white animate-spin" />,
duration: 7500,
});
if (!content || content.length === 0) {
toast.error("Content is required");
return;
throw new Error("Content is required");
}
console.log(spaces);
const cont = await createMemory({
content: content,
spaces: spaces ?? undefined,
});
setContent("");
setSelectedSpaces([]);
if (cont.success) {
toast.success("Memory created", {
richColors: true,
});
} else {
toast.error(`Memory creation failed: ${cont.error}`);
return cont;
}
throw new Error(`Memory creation failed: ${cont.error}`);
};
return (
@ -193,8 +178,17 @@ function Menu() {
<form
action={async (e: FormData) => {
const content = e.get("content")?.toString();
await handleSubmit(content, selectedSpaces);
toast.promise(handleSubmit(content, selectedSpaces), {
loading: (
<span>
<PlusCircleIcon className="w-4 h-4 inline mr-2 text-white animate-spin" />{" "}
Creating memory...
</span>
),
success: (data) => "Memory created",
error: (error) => error.message,
richColors: true,
});
}}
className="flex flex-col gap-4 "
>
@ -218,7 +212,17 @@ function Menu() {
onKeyDown={(e) => {
if (e.key === "Enter" && !e.shiftKey) {
e.preventDefault();
handleSubmit(content, selectedSpaces);
toast.promise(handleSubmit(content, selectedSpaces), {
loading: (
<span>
<PlusCircleIcon className="w-4 h-4 inline mr-2 text-white animate-spin" />{" "}
Creating memory...
</span>
),
success: (data) => "Memory created",
error: (error) => error.message,
richColors: true,
});
}
}}
/>