From 4c96fa349c6fe2409a54ee7bb6c8a43b85a4e109 Mon Sep 17 00:00:00 2001 From: Dhravya Shah Date: Sat, 20 Jul 2024 20:49:33 -0500 Subject: changes in queryinput home layout --- apps/web/app/(dash)/chat/chatQueryInput.tsx | 181 ++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 apps/web/app/(dash)/chat/chatQueryInput.tsx (limited to 'apps/web/app/(dash)/chat/chatQueryInput.tsx') diff --git a/apps/web/app/(dash)/chat/chatQueryInput.tsx b/apps/web/app/(dash)/chat/chatQueryInput.tsx new file mode 100644 index 00000000..c7267298 --- /dev/null +++ b/apps/web/app/(dash)/chat/chatQueryInput.tsx @@ -0,0 +1,181 @@ +"use client"; + +import { ArrowRightIcon } from "@repo/ui/icons"; +import Image from "next/image"; +import React, { useEffect, useMemo, useState } from "react"; +import Divider from "@repo/ui/shadcn/divider"; +import { useRouter } from "next/navigation"; +import { getSpaces } from "@/app/actions/fetchers"; +import Combobox from "@repo/ui/shadcn/combobox"; +import { MinusIcon } from "lucide-react"; +import { toast } from "sonner"; +import { createSpace } from "@/app/actions/doers"; + +function QueryInput({ + initialQuery = "", + initialSpaces = [], + disabled = false, + className, + mini = false, + handleSubmit, + setInitialSpaces, +}: { + initialQuery?: string; + initialSpaces?: { + id: number; + name: string; + }[]; + disabled?: boolean; + className?: string; + mini?: boolean; + handleSubmit: (q: string, spaces: { id: number; name: string }[]) => void; + setInitialSpaces?: React.Dispatch< + React.SetStateAction<{ id: number; name: string }[]> + >; +}) { + const [q, setQ] = useState(initialQuery); + + const [selectedSpaces, setSelectedSpaces] = useState([]); + + const options = useMemo( + () => + initialSpaces.map((x) => ({ + label: x.name, + value: x.id.toString(), + })), + [initialSpaces], + ); + + const preparedSpaces = useMemo( + () => + initialSpaces + .filter((x) => selectedSpaces.includes(x.id)) + .map((x) => { + return { + id: x.id, + name: x.name, + }; + }), + [selectedSpaces, initialSpaces], + ); + + return ( +
+
+ {/* input and action button */} +
{ + handleSubmit(q, preparedSpaces); + setQ(""); + }} + className="flex gap-4 p-3" + > +