diff options
| author | Dhravya Shah <[email protected]> | 2024-07-30 20:40:13 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-07-30 20:40:13 -0700 |
| commit | f7ef7df6386f771f0141a174476102d6a5895e28 (patch) | |
| tree | 4491ef6efc5ad0611420dd808a8dd5ae9e6619c4 | |
| parent | cleaner (diff) | |
| parent | fixed error shows as success toast (diff) | |
| download | supermemory-f7ef7df6386f771f0141a174476102d6a5895e28.tar.xz supermemory-f7ef7df6386f771f0141a174476102d6a5895e28.zip | |
Merge pull request #189 from tushar-daiya/promiseToaster
Sonner promise toaster added
| -rw-r--r-- | apps/web/app/(dash)/menu.tsx | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/apps/web/app/(dash)/menu.tsx b/apps/web/app/(dash)/menu.tsx index c1173eb6..7eac5a56 100644 --- a/apps/web/app/(dash)/menu.tsx +++ b/apps/web/app/(dash)/menu.tsx @@ -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, + }); } }} /> |