diff --git a/.gitignore b/.gitignore index 4c8dc75..5b59762 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ .env \myenv -/tailwind/* \ No newline at end of file +/tailwind/* +*.log \ No newline at end of file diff --git a/client/bun.lockb b/client/bun.lockb index 40bd376..2c4007b 100755 Binary files a/client/bun.lockb and b/client/bun.lockb differ diff --git a/client/src/contexts/settings-context.tsx b/client/src/contexts/settings-context.tsx index dfd1747..beca7c6 100644 --- a/client/src/contexts/settings-context.tsx +++ b/client/src/contexts/settings-context.tsx @@ -34,6 +34,8 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ if (savedConfigs) { try { const parsedConfigs = JSON.parse(savedConfigs); + + setCurrentConfig(parsedConfigs[0]); // Optionally, you can check if parsedConfigs is an array or object if (Array.isArray(parsedConfigs) || typeof parsedConfigs === "object") { setConfigurations(parsedConfigs); diff --git a/client/src/pages/Chatbot.tsx b/client/src/pages/Chatbot.tsx index bda7659..1ab75a2 100644 --- a/client/src/pages/Chatbot.tsx +++ b/client/src/pages/Chatbot.tsx @@ -15,7 +15,7 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import axios from "axios"; import { ArrowLeft, Loader2, SendIcon, Trash2 } from "lucide-react"; -import { useRef, useState } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import { useForm } from "react-hook-form"; import toast from "react-hot-toast"; import { useNavigate, useParams } from "react-router-dom"; @@ -32,6 +32,7 @@ export default function ChatbotPage() { queryKey: ["chatbot", id], queryFn: () => fetchChatbotData(id), }); + const messageEl = useRef(null); const singleClickTimeout = useRef(null); const { currentConfig } = useSettings(); const [loading, setLoading] = useState(false); // Loading state for request @@ -46,11 +47,25 @@ export default function ChatbotPage() { const mutation = useMutation({ mutationFn: deleteAllChats, - onSuccess: () => rq.invalidateQueries({ queryKey: ["chatbot", id] }), + onSuccess: async () => { + await rq.invalidateQueries({ queryKey: ["chatbot", id] }); + }, }); + const scrollToBottom = useCallback(() => { + if (messageEl.current) { + // @ts-ignore + messageEl.current.scrollTop = messageEl.current.scrollHeight; + } + }, []); + + useEffect(() => { + scrollToBottom(); + }, [data?.chats, scrollToBottom]); + async function onSubmit(values: z.infer) { try { + if (!values.query.trim()) return; if (currentConfig == null) { toast.error("Please Select AI engine in settings"); return; @@ -140,7 +155,11 @@ export default function ChatbotPage() { -
+
{data ? ( <> {data.chats.map((chat) => ( diff --git a/client/src/pages/Imagine.tsx b/client/src/pages/Imagine.tsx index 4584a51..37dbf87 100644 --- a/client/src/pages/Imagine.tsx +++ b/client/src/pages/Imagine.tsx @@ -1,5 +1,11 @@ import Separator from "@/components/Separator"; import { Button } from "@/components/ui/button"; +import { + Card, + CardContent, + CardFooter, + CardHeader, +} from "@/components/ui/card"; import { Form, FormControl, @@ -15,7 +21,7 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { useQuery, useQueryClient } from "@tanstack/react-query"; import axios from "axios"; import { ArrowLeft, Download, Loader2, SendIcon } from "lucide-react"; -import { useState } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import { useForm } from "react-hook-form"; import toast from "react-hot-toast"; import { Link } from "react-router-dom"; @@ -26,6 +32,7 @@ export default function ImaginePage() { queryKey: ["images"], queryFn: fetchImagesData, }); + const messageEl = useRef(null); const [loading, setLoading] = useState(false); // Loading state for request const rq = useQueryClient(); const form = useForm>({ @@ -35,6 +42,17 @@ export default function ImaginePage() { }, }); + const scrollToBottom = useCallback(() => { + if (messageEl.current) { + // @ts-ignore + messageEl.current.scrollTop = messageEl.current.scrollHeight; + } + }, []); + + useEffect(() => { + scrollToBottom(); + }, [data, scrollToBottom]); + async function onSubmit(values: z.infer) { try { const token = localStorage.getItem("token"); @@ -86,7 +104,10 @@ export default function ImaginePage() {
-
+
{!data ? ( ) : ( @@ -98,28 +119,35 @@ export default function ImaginePage() { )} {data.map((image) => ( <> -
-
- {image.prompt} -

{image.prompt}

-
- - - + + +
+ {image.prompt}
-
-
+ + +

+ {image.prompt} +

+
+ + + + + + ))}