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: , - 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() {
{ const content = e.get("content")?.toString(); - - await handleSubmit(content, selectedSpaces); + toast.promise(handleSubmit(content, selectedSpaces), { + loading: ( + + {" "} + Creating memory... + + ), + 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: ( + + {" "} + Creating memory... + + ), + success: (data) => "Memory created", + error: (error) => error.message, + richColors: true, + }); } }} />