diff options
| author | Tushar Daiya <[email protected]> | 2024-07-30 12:40:11 +0530 |
|---|---|---|
| committer | Tushar Daiya <[email protected]> | 2024-07-30 12:40:11 +0530 |
| commit | f23f8d286dd36792840ac9477af10f6a6cf85cc8 (patch) | |
| tree | 583bd07178a474d3edeef08f8a984dded229b184 /apps/web | |
| parent | Merge pull request #186 from fyzanshaik/bugfix/github-key-interference (diff) | |
| download | supermemory-f23f8d286dd36792840ac9477af10f6a6cf85cc8.tar.xz supermemory-f23f8d286dd36792840ac9477af10f6a6cf85cc8.zip | |
sonner promise toaster added
Diffstat (limited to 'apps/web')
| -rw-r--r-- | apps/web/app/(dash)/menu.tsx | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/apps/web/app/(dash)/menu.tsx b/apps/web/app/(dash)/menu.tsx index c1173eb6..616ab058 100644 --- a/apps/web/app/(dash)/menu.tsx +++ b/apps/web/app/(dash)/menu.tsx @@ -111,36 +111,18 @@ 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; }; - + return ( <> {/* Desktop Menu */} @@ -193,8 +175,24 @@ function Menu() { <form action={async (e: FormData) => { const content = e.get("content")?.toString(); + 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) => { + if (data.success) { + return "Memory created"; + } else { + return `Memory creation failed: ${data.error}`; + } + }, + error: (error) => `Memory creation failed: ${error}`, + richColors: true, + }); - await handleSubmit(content, selectedSpaces); }} className="flex flex-col gap-4 " > @@ -218,7 +216,23 @@ 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) => { + if (data.success) { + return "Memory created"; + } else { + return `Memory creation failed: ${data.error}`; + } + }, + error: (error) => `Memory creation failed: ${error}`, + richColors: true, + }); } }} /> |