diff --git a/apps/web/app/(dash)/home/history.tsx b/apps/web/app/(dash)/home/history.tsx index 922734df..e09a5c82 100644 --- a/apps/web/app/(dash)/home/history.tsx +++ b/apps/web/app/(dash)/home/history.tsx @@ -5,26 +5,28 @@ import Link from "next/link"; import { memo, useEffect, useState } from "react"; import { motion } from "framer-motion"; import { chatThreads } from "@/server/db/schema"; +import { getQuerySuggestions } from "@/app/actions/doers"; +import { Button } from "@repo/ui/shadcn/button"; -const History = memo(() => { - const [chatThreads_, setChatThreads] = useState< - (typeof chatThreads.$inferSelect)[] | null - >(null); +const History = memo(({ setQuery }: { setQuery: (q: string) => void }) => { + const [suggestions, setSuggestions] = useState(null); useEffect(() => { (async () => { - const chatThreads = await getChatHistory(); - if (!chatThreads.success || !chatThreads.data) { - console.error(chatThreads.error); + const suggestions = await getQuerySuggestions(); + if (!suggestions.success || !suggestions.data) { + console.error(suggestions.error); + setSuggestions([]); return; } - setChatThreads(chatThreads.data.reverse().slice(0, 3)); + console.log(suggestions); + setSuggestions(suggestions.data.reverse()); })(); }, []); return ( diff --git a/apps/web/app/(dash)/home/page.tsx b/apps/web/app/(dash)/home/page.tsx index 416428e7..dfcac577 100644 --- a/apps/web/app/(dash)/home/page.tsx +++ b/apps/web/app/(dash)/home/page.tsx @@ -3,8 +3,12 @@ import React, { useEffect, useState } from "react"; import QueryInput from "./queryinput"; import { getSessionAuthToken, getSpaces } from "@/app/actions/fetchers"; -import { useRouter } from "next/navigation"; -import { createChatThread, linkTelegramToUser } from "@/app/actions/doers"; +import { redirect, useRouter } from "next/navigation"; +import { + createChatThread, + getQuerySuggestions, + linkTelegramToUser, +} from "@/app/actions/doers"; import { toast } from "sonner"; import { motion } from "framer-motion"; import { ChromeIcon, GithubIcon, TwitterIcon } from "lucide-react"; @@ -25,20 +29,14 @@ const slap = { }; function Page({ searchParams }: { searchParams: Record }) { - const query = searchParams.q || ""; - const [queryPresent, setQueryPresent] = useState(false); - - const [telegramUser, setTelegramUser] = useState( - searchParams.telegramUser as string, - ); - const [extensionInstalled, setExtensionInstalled] = useState< - string | undefined - >(searchParams.extension as string); - - const { push } = useRouter(); + const telegramUser = searchParams.telegramUser; + const extensionInstalled = searchParams.extension; + const [query, setQuery] = useState(searchParams.q || ""); const [spaces, setSpaces] = useState<{ id: number; name: string }[]>([]); + const { push } = useRouter(); + useEffect(() => { if (telegramUser) { const linkTelegram = async () => { @@ -92,8 +90,8 @@ function Page({ searchParams }: { searchParams: Record }) {
{ if (q.length === 0) { toast.error("Query is required"); @@ -114,7 +112,7 @@ function Page({ searchParams }: { searchParams: Record }) { initialSpaces={spaces} /> - +
diff --git a/apps/web/app/(dash)/home/queryinput.tsx b/apps/web/app/(dash)/home/queryinput.tsx index 9f1e7292..82561438 100644 --- a/apps/web/app/(dash)/home/queryinput.tsx +++ b/apps/web/app/(dash)/home/queryinput.tsx @@ -8,26 +8,24 @@ import { Switch } from "@repo/ui/shadcn/switch"; import { Label } from "@repo/ui/shadcn/label"; function QueryInput({ - setQueryPresent, - initialQuery, initialSpaces, handleSubmit, + query, + setQuery, }: { - setQueryPresent: (t: boolean) => void; initialSpaces?: { id: number; name: string; }[]; - initialQuery?: string; mini?: boolean; handleSubmit: ( q: string, spaces: { id: number; name: string }[], proMode: boolean, ) => void; + query: string; + setQuery: (q: string) => void; }) { - const [q, setQ] = useState(initialQuery || ""); - const [proMode, setProMode] = useState(false); const [selectedSpaces, setSelectedSpaces] = useState< @@ -42,11 +40,11 @@ function QueryInput({ {/* input and action button */}
{ - if (q.trim().length === 0) { + if (query.trim().length === 0) { return; } - handleSubmit(q, selectedSpaces, proMode); - setQ(""); + handleSubmit(query, selectedSpaces, proMode); + setQuery(""); }} >