"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 { MultipleSelector, Option } from "@repo/ui/shadcn/combobox"; import { useRouter } from "next/navigation"; import { getSpaces } from "@/app/actions/fetchers"; function QueryInput({ initialQuery = "", initialSpaces = [], disabled = false, }: { initialQuery?: string; initialSpaces?: { id: number; name: string; }[]; disabled?: boolean; }) { const [q, setQ] = useState(initialQuery); const [selectedSpaces, setSelectedSpaces] = useState([]); const { push } = useRouter(); const parseQ = () => { // preparedSpaces is list of spaces selected by user, with id and name const preparedSpaces = initialSpaces .filter((x) => selectedSpaces.includes(x.id)) .map((x) => { return { id: x.id, name: x.name, }; }); const newQ = "/chat?q=" + encodeURI(q) + (selectedSpaces ? "&spaces=" + JSON.stringify(preparedSpaces) : ""); return newQ; }; const options = useMemo( () => initialSpaces.map((x) => ({ label: x.name, value: x.id.toString(), })), [initialSpaces], ); return (
{/* input and action button */}
push(parseQ())} className="flex gap-4 p-3">