diff --git a/apps/web/src/app/(app)/@user/history.tsx b/apps/web/src/app/(app)/@user/history.tsx index ed7fbb4..7f053c1 100644 --- a/apps/web/src/app/(app)/@user/history.tsx +++ b/apps/web/src/app/(app)/@user/history.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState } from "react"; +import { useRef, useState } from "react"; import Link from "next/link"; import { Drawer, DrawerContent, DrawerTrigger } from "@/components/drawer"; import { api } from "@/trpc/react"; @@ -17,11 +17,12 @@ import { } from "@nextui-org/react"; import { FaChevronRight } from "react-icons/fa6"; import { IoMenu } from "react-icons/io5"; -import { RiDeleteBin2Line } from "react-icons/ri"; +import { RiCheckFill, RiDeleteBin2Line, RiPencilLine } from "react-icons/ri"; import { useMediaQuery } from "usehooks-ts"; import { Button } from "@tanya.in/ui/button"; import { Card, CardContent } from "@tanya.in/ui/card"; +import { Input } from "@tanya.in/ui/form"; import { toast } from "@tanya.in/ui/toast"; function Content() { @@ -30,11 +31,19 @@ function Content() { function List(props: { chat: NonNullable[0] }) { const { isOpen, onOpenChange, onOpen } = useDisclosure(); + const [edit, setEdit] = useState(false); const utils = api.useUtils(); const deleteChat = api.chat.delete.useMutation(); + const changeChatTitle = api.chat.changeTitle.useMutation(); const title = props.chat.title ?? props.chat.messages.at(0)?.content; + const titleRef = useRef(null); + + function preventDefault(e: React.MouseEvent) { + e.preventDefault(); + e.nativeEvent.stopImmediatePropagation(); + } return ( <> @@ -46,22 +55,80 @@ function Content() { > -

{title}

- + {edit ? ( + { + preventDefault(e); + }} + /> + ) : ( +

{title}

+ )} +
+ {edit ? ( + + ) : ( + <> + + + + )} +
diff --git a/apps/web/src/server/api/routers/chat/chat.procedure.ts b/apps/web/src/server/api/routers/chat/chat.procedure.ts index ca00913..b9c71ea 100644 --- a/apps/web/src/server/api/routers/chat/chat.procedure.ts +++ b/apps/web/src/server/api/routers/chat/chat.procedure.ts @@ -23,6 +23,7 @@ export const chatRouter = createTRPCRouter({ limit: 1, }, }, + orderBy: (chat, { desc }) => [desc(chat.createdAt)], }); }), @@ -41,6 +42,22 @@ export const chatRouter = createTRPCRouter({ }); }), + changeTitle: protectedProcedure + .input( + z.object({ + id: z.string(), + title: z.string(), + }), + ) + .mutation(async ({ ctx, input }) => { + return await ctx.db + .update(chats) + .set({ + title: input.title, + }) + .where(eq(chats.id, input.id)); + }), + delete: protectedProcedure .input( z.object({