From 91c7712612b4dfa1342ea27ca46e587601f77a22 Mon Sep 17 00:00:00 2001 From: Yash Date: Tue, 9 Apr 2024 01:15:33 +0000 Subject: chat --- apps/web/src/components/Main.tsx | 144 +++++++++++++++++++++++++-------------- 1 file changed, 91 insertions(+), 53 deletions(-) (limited to 'apps/web/src/components') diff --git a/apps/web/src/components/Main.tsx b/apps/web/src/components/Main.tsx index 86679dcf..b77106a9 100644 --- a/apps/web/src/components/Main.tsx +++ b/apps/web/src/components/Main.tsx @@ -1,31 +1,33 @@ -'use client'; -import { useEffect, useRef, useState } from 'react'; -import { FilterCombobox } from './Sidebar/FilterCombobox'; -import { Textarea2 } from './ui/textarea'; -import { ArrowRight } from 'lucide-react'; -import { MemoryDrawer } from './MemoryDrawer'; -import useViewport from '@/hooks/useViewport'; -import { motion } from 'framer-motion'; -import { cn } from '@/lib/utils'; -import SearchResults from './SearchResults'; +"use client"; +import { useEffect, useRef, useState } from "react"; +import { FilterCombobox } from "./Sidebar/FilterCombobox"; +import { Textarea2 } from "./ui/textarea"; +import { ArrowRight } from "lucide-react"; +import { MemoryDrawer } from "./MemoryDrawer"; +import useViewport from "@/hooks/useViewport"; +import { motion } from "framer-motion"; +import { cn } from "@/lib/utils"; +import SearchResults from "./SearchResults"; function supportsDVH() { try { - return CSS.supports('height: 100dvh'); + return CSS.supports("height: 100dvh"); } catch { return false; } } export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) { + return ; + const [hide, setHide] = useState(false); - const [value, setValue] = useState(''); + const [value, setValue] = useState(""); const { width } = useViewport(); const [searchResults, setSearchResults] = useState([]); const [isAiLoading, setIsAiLoading] = useState(false); - const [aiResponse, setAIResponse] = useState(''); - const [toBeParsed, setToBeParsed] = useState(''); + const [aiResponse, setAIResponse] = useState(""); + const [toBeParsed, setToBeParsed] = useState(""); const textArea = useRef(null); const main = useRef(null); @@ -45,9 +47,9 @@ export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) { } } - window.visualViewport?.addEventListener('resize', onResize); + window.visualViewport?.addEventListener("resize", onResize); return () => { - window.visualViewport?.removeEventListener('resize', onResize); + window.visualViewport?.removeEventListener("resize", onResize); }; }, []); @@ -62,13 +64,13 @@ export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) { // Attempt to parse the "toBeParsed" state as JSON try { // Split the accumulated data by the known delimiter "\n\n" - const parts = toBeParsed.split('\n\n'); - let remainingData = ''; + const parts = toBeParsed.split("\n\n"); + let remainingData = ""; // Process each part to extract JSON objects parts.forEach((part, index) => { try { - const parsedPart = JSON.parse(part.replace('data: ', '')); // Try to parse the part as JSON + const parsedPart = JSON.parse(part.replace("data: ", "")); // Try to parse the part as JSON // If the part is the last one and couldn't be parsed, keep it to accumulate more data if (index === parts.length - 1 && !parsedPart) { @@ -80,7 +82,7 @@ export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) { } catch (error) { // If parsing fails and it's not the last part, it's a malformed JSON if (index !== parts.length - 1) { - console.error('Malformed JSON part: ', part); + console.error("Malformed JSON part: ", part); } else { // If it's the last part, it may be incomplete, so keep it remainingData = part; @@ -93,7 +95,7 @@ export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) { setToBeParsed(remainingData); } } catch (error) { - console.error('Error parsing accumulated data: ', error); + console.error("Error parsing accumulated data: ", error); } }; @@ -126,8 +128,8 @@ export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) { if (response.body) { let reader = response.body.getReader(); - let decoder = new TextDecoder('utf-8'); - let result = ''; + let decoder = new TextDecoder("utf-8"); + let result = ""; // @ts-ignore reader.read().then(function processText({ done, value }) { @@ -145,46 +147,82 @@ export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) { }; return ( -

Ask your Second brain

-
await getSearchResults(e)}> - setValue(e.target.value), - }} - > -
- - -
-
-
- {searchResults && ( + + setValue(e.target.value), + }} + > +
+ + +
+
+ {/* {searchResults && ( - )} + )} */} {width <= 768 && } -
+ + ); +} + +export function Chat({ sidebarOpen }: { sidebarOpen: boolean }) { + const [value, setValue] = useState(""); + + return ( +
+ setValue(e.target.value), + }} + > +
+ + +
+
+
); } -- cgit v1.2.3