have a initial search query

This commit is contained in:
Yash 2024-04-09 16:40:50 +00:00
parent 1693f33b01
commit 531fd5c1ce
2 changed files with 21 additions and 22 deletions

View file

@ -2,6 +2,7 @@ import React, { useEffect } from "react";
import { motion } from "framer-motion";
import { ArrowUpRight, Globe } from "lucide-react";
import { convertRemToPixels } from "@/lib/utils";
import { SpaceIcon } from "@/assets/Memories";
export function ChatAnswer({
children: message,
@ -19,11 +20,11 @@ export function ChatAnswer({
) : (
<div className="w-full text-lg text-white/60">{message}</div>
)}
{sources && sources?.length > 0 && (
{!loading && sources && sources?.length > 0 && (
<>
<h1 className="animate-fade-in text-md flex items-center justify-center gap-1 opacity-0 [animation-duration:1s]">
<ArrowUpRight className="h-5 w-5" />
Sources
<h1 className="animate-fade-in text-rgray-12 text-md flex items-center justify-center gap-2 opacity-0 [animation-duration:1s]">
<SpaceIcon className="h-6 w-6 -translate-y-[2px]" />
Related Memories
</h1>
<div className="animate-fade-in -mt-3 flex items-center justify-start opacity-0 [animation-duration:1s]">
{sources?.map((source) => (

View file

@ -10,31 +10,17 @@ import { cn, countLines } from "@/lib/utils";
import { ChatHistory } from "../../types/memory";
import { ChatAnswer, ChatMessage, ChatQuestion } from "./ChatMessage";
import { useSession } from "next-auth/react";
import { useRouter, useSearchParams } from "next/navigation";
const dummyChatHistory: ChatHistory = {
question: "What is the capital of France?",
question: "who is dhravya?",
answer: {
parts: [
{
text: "Paris",
},
{
text: "is",
},
{
text: "the",
},
{
text: "capital",
},
{
text: "of",
},
{
text: "France",
text: "Dhravya Shah is an 18-year-old full-stack developer based in Arizona, USA. He is a passionate developer who focuses on creating products that people love. Dhravya has a background in entrepreneurship, having been a 2x acquired founder and a participant in various hackathons. He is also involved in open-source contributions, content creation to inspire others in coding, and has a growing community of developers. Dhravya's work spans from creating AI-powered note-taking apps to personalized music companions and educational tools. Additionally, he is a guitarist, student, and active in sharing his experiences as a developer and entrepreneur",
},
],
sources: ["Wikipedia"],
sources: ["dhravya.dev"],
},
};
@ -47,6 +33,9 @@ function supportsDVH() {
}
export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) {
const searchParams = useSearchParams();
const router = useRouter();
const [hide, setHide] = useState(false);
const [layout, setLayout] = useState<"chat" | "initial">("initial");
const [value, setValue] = useState("");
@ -73,6 +62,15 @@ export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) {
const textArea = useRef<HTMLDivElement>(null);
const main = useRef<HTMLDivElement>(null);
useEffect(() => {
const search = searchParams.get("q");
if (search && search.trim().length > 0) {
setValue(search);
onSend();
router.push("/");
}
}, []);
useEffect(() => {
function onResize() {
if (!main.current || !window.visualViewport) return;