diff --git a/apps/web/src/routes/app/home.tsx b/apps/web/src/routes/app/home.tsx index f8c5426..b4aff5b 100644 --- a/apps/web/src/routes/app/home.tsx +++ b/apps/web/src/routes/app/home.tsx @@ -12,16 +12,27 @@ import { import z from "zod"; import { toast } from "@tensamin/shared/log"; import { useSocket } from "@tensamin/ttp/context"; +import { useState } from "react"; +import { Loader2 } from "lucide-react"; -/** - * Executes Page. - * @param none This function has no parameters. - * @returns unknown. - */ +// The page export default function Page() { + return ( +
+ + +
+ ); +} + +// Add Conversation Button Component +function AddConversationButton() { const { send } = useSocket(); + const [loading, setLoading] = useState(false); function submit(username: string | null) { + if (loading) return; + const schema = z .string() .min(1, "Username is too short") @@ -34,48 +45,61 @@ export default function Page() { return; } + setTimeout(() => setLoading(true), 500); + send("add_conversation", { chat_partner_name: result.data, }) - .then(() => toast("success", "Conversation added")) - .catch(() => toast("error", "Failed to add conversation")); + .then(() => { + toast("success", "Conversation added"); + }) + .catch((error) => { + if (String(error).includes("error_not_found")) { + toast("error", "User not found"); + return; + } + + toast("error", "Failed to add conversation, check console for details"); + console.error("Failed to add conversation", error); + }) + .finally(() => setLoading(false)); } return ( -
- - Add Conversation} /> - - - New Conversation - - - Add a new conversation. Just enter the username of the person you - want to add as a conversation. - -
{ - event.preventDefault(); - const form = new FormData(event.currentTarget); - const username = form.get("username") as string | null; - submit(username); - }} - > - -
- Cancel} /> - -
-
-
-
- -
+ + Add Conversation} /> + + + New Conversation + + + Add a new conversation. Just enter the username of the person you want + to add as a conversation. + +
{ + event.preventDefault(); + const form = new FormData(event.currentTarget); + const username = form.get("username") as string | null; + submit(username); + }} + > + +
+ Cancel} /> + +
+
+
+
); } diff --git a/packages/shared/src/data.ts b/packages/shared/src/data.ts index c39e795..3276ad6 100644 --- a/packages/shared/src/data.ts +++ b/packages/shared/src/data.ts @@ -128,6 +128,13 @@ export const socket = { }), response: z.object({}), }, + add_conversation: { + request: z.object({ + chat_partner_id: z.number().optional(), + chat_partner_name: z.string().min(1).max(15).optional(), + }), + response: z.object({}), + }, } satisfies Record; export type Socket = typeof socket; diff --git a/packages/ui/src/cmp/sonner.tsx b/packages/ui/src/cmp/sonner.tsx index 7cbe96b..071e8f2 100644 --- a/packages/ui/src/cmp/sonner.tsx +++ b/packages/ui/src/cmp/sonner.tsx @@ -26,9 +26,9 @@ const Toaster = ({ ...props }: ToasterProps) => { }} style={ { - "--normal-bg": "var(--popover)", - "--normal-text": "var(--popover-foreground)", - "--normal-border": "var(--border)", + "--normal-bg": "var(--color-popover)", + "--normal-text": "var(--color-popover-foreground)", + "--normal-border": "var(--color-border)", "--border-radius": "var(--radius)", } as React.CSSProperties }