diff --git a/components/ChatSection.tsx b/components/ChatSection.tsx index b35e707..ac3f50b 100644 --- a/components/ChatSection.tsx +++ b/components/ChatSection.tsx @@ -1,23 +1,37 @@ -import ChatBubble from "@/components/ChatBubble"; -import { useRef, useEffect } from "react"; +import ChatBubble from '@/components/ChatBubble' +import { useState, useRef, useEffect } from 'react' +import Header from './Header' interface ChatSectionProps { - chat?: Array<{ sent: boolean; message: string }>; + chat?: Array<{ sent: boolean; message: string }> } const ChatSection = ({ chat }: ChatSectionProps) => { - const messagesEndRef = useRef(null); + const messagesEndRef = useRef(null) + const [firstResponseGenerated, setFirstResponseGenerated] = useState(false) const scrollToBottom = () => { if (messagesEndRef.current) { - messagesEndRef.current.scrollIntoView({ behavior: "smooth" }); + messagesEndRef.current.scrollIntoView({ behavior: 'smooth' }) } - }; + } - useEffect(scrollToBottom, [chat]); + useEffect(() => { + if (chat && chat.length > 0 && !firstResponseGenerated) { + scrollToBottom() + setFirstResponseGenerated(true) + } + }, [chat, firstResponseGenerated]) return (
+ {firstResponseGenerated ? ( +

+ BhagavadGita.ai +

+ ) : ( +
+ )} { ))}
- ); -}; + ) +} -export default ChatSection; +export default ChatSection diff --git a/components/Header.tsx b/components/Header.tsx index f2156c2..d418223 100644 --- a/components/Header.tsx +++ b/components/Header.tsx @@ -1,6 +1,4 @@ -import React from "react"; -import Image from "next/image"; -import Tooltip from "./Tooltip"; +import React from 'react' const Header = () => { return ( @@ -9,53 +7,22 @@ const Header = () => { BhagavadGita.ai

- Unlock Your Potential with GitaGPT - The AI-Powered Spiritual Companion. - {/*

*/} - {/*

*/} + Unlock the Wisdom of Krishna with{' '} - Powered by ChatSonic. + ChatSonic

-
+

- 300,000+ devotees guided so far + 200,000+ devotees guided so far

-
- - - Twitter - - -
-
- - - Github - - -
- ); -}; + ) +} -export default Header; +export default Header diff --git a/pages/index.tsx b/pages/index.tsx index 498d33f..09384f1 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,27 +1,27 @@ -import ChatSection from "@/components/ChatSection"; -import Header from "@/components/Header"; -import Input from "@/components/Input"; -import Navbar from "@/components/Navbar"; -import { useEffect, useState } from "react"; -import Head from "next/head"; -import { useCookies } from "react-cookie"; -import { useRouter } from "next/router"; +import ChatSection from '@/components/ChatSection' +import Header from '@/components/Header' +import Input from '@/components/Input' +import Navbar from '@/components/Navbar' +import { useEffect, useState } from 'react' +import Head from 'next/head' +import { useCookies } from 'react-cookie' +import { useRouter } from 'next/router' export default function Home() { - const [showSuggestions, setShowSuggestions] = useState(true); - const [input, setInput] = useState(""); - const [chat, setChat] = useState>(); - const [cookies, setCookie, removeCookie] = useCookies(["Token"]); - const router = useRouter(); + const [showSuggestions, setShowSuggestions] = useState(true) + const [input, setInput] = useState('') + const [chat, setChat] = useState>() + const [cookies, setCookie, removeCookie] = useCookies(['Token']) + const router = useRouter() useEffect(() => { - const pathName = router.asPath; - const access_token = pathName.match(/\#(?:access_token)\=([\S\s]*?)\&/); + const pathName = router.asPath + const access_token = pathName.match(/\#(?:access_token)\=([\S\s]*?)\&/) if (access_token && access_token.length > 1) { - setCookie("Token", access_token[1]); + setCookie('Token', access_token[1]) } - }, [router.query]); + }, [router.query]) function addJsonLd() { return { @@ -51,7 +51,7 @@ export default function Home() { }, } `, - }; + } } return ( @@ -118,7 +118,7 @@ export default function Home() {
-
+ {/*
*/}
- ); + ) }