From 0edc5ad5ff9ef9d7320f86c54d03e3708668c418 Mon Sep 17 00:00:00 2001 From: Ankita Sahu <71656941+SAHU-01@users.noreply.github.com> Date: Mon, 15 Apr 2024 12:48:52 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1Improve:=20Codebase=20and=20popup=20mo?= =?UTF-8?q?dal=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/App.tsx | 34 +-- src/common/ChatUI.tsx | 205 ++++++++++-------- src/common/CredentialsComponent.tsx | 39 ++-- src/common/FileUploadComponent.tsx | 36 ++-- src/common/PasswordComponent.tsx | 87 ++++---- src/common/UpdatePasswordComponent.tsx | 34 ++- src/context/ModalContext.tsx | 10 +- src/state/chat.ts | 280 ++++++++++++------------- 8 files changed, 376 insertions(+), 349 deletions(-) diff --git a/src/common/App.tsx b/src/common/App.tsx index f85d497..9a49e82 100644 --- a/src/common/App.tsx +++ b/src/common/App.tsx @@ -1,5 +1,17 @@ import React, { useEffect, useState } from 'react'; -import { Box, ChakraProvider, Heading, HStack, Tabs, TabList, Tab, TabPanels, TabPanel, Button, Input } from '@chakra-ui/react'; +import { + Box, + ChakraProvider, + Heading, + HStack, + Tabs, + TabList, + Tab, + TabPanels, + TabPanel, + Button, + Input, +} from '@chakra-ui/react'; import { useAppState } from '../state/store'; import ModelDropdown from './ModelDropdown'; import SetAPIKey from './SetAPIKey'; @@ -15,15 +27,14 @@ const App: React.FC = () => { const [loggedIn, setLoggedIn] = useState(false); const [selectedFile, setSelectedFile] = useState(null); - useEffect(() => { // Check local storage to see if the user has already logged in const isUserLoggedIn = localStorage.getItem('userLoggedIn'); if (isUserLoggedIn === 'true') { - console.log(isUserLoggedIn) + console.log(isUserLoggedIn); setLoggedIn(true); } else { - setLoggedIn(false) + setLoggedIn(false); } }, []); @@ -43,10 +54,8 @@ const App: React.FC = () => { } // Call the parent component callback with the selected file and message - }; - return ( @@ -62,13 +71,13 @@ const App: React.FC = () => { ZkSurf - {/* {loggedIn ?( + {loggedIn ?( ):NaN} */} + ):NaN} @@ -76,7 +85,7 @@ const App: React.FC = () => { - {/* {loggedIn ? ( */} + {loggedIn ? ( Browser Automation @@ -89,16 +98,15 @@ const App: React.FC = () => { - + - {/* ) : ( + ) : ( -)} */} - +)} ); diff --git a/src/common/ChatUI.tsx b/src/common/ChatUI.tsx index 622e4c2..66e2f77 100644 --- a/src/common/ChatUI.tsx +++ b/src/common/ChatUI.tsx @@ -1,5 +1,19 @@ import React, { useState, useCallback, useEffect, useContext } from 'react'; -import { VStack, HStack, Textarea, useToast, Spacer, Button, Modal, ModalOverlay, ModalContent, ModalHeader, ModalFooter, ModalBody, ModalCloseButton } from '@chakra-ui/react'; +import { + VStack, + HStack, + Textarea, + useToast, + Spacer, + Button, + Modal, + ModalOverlay, + ModalContent, + ModalHeader, + ModalFooter, + ModalBody, + ModalCloseButton, +} from '@chakra-ui/react'; import useChatStore, { ChatMessage } from '../state/chat'; import RunChatButton from './RunChatButton'; import ChatHistory from './ChatHistory'; @@ -11,22 +25,33 @@ import CredentialsComponent from './CredentialsComponent'; import FileUploadComponent from './FileUploadComponent'; import { ModalContext } from '../context/ModalContext'; - const ChatUI = () => { const [message, setMessage] = useState(''); - // const [file, setFile] = useState(null); - // const [userPass, setUserPass] = useState(''); const [fileName, setFileName] = useState(''); const [isFileAttached, setIsFileAttached] = useState(false); // Track if file is attached - // const [showUpdatePasswordModal, setShowUpdatePasswordModal] = useState(false); // State to control Update Password modal - // const [showCredentialsModal, setShowCredentialsModal] = useState(false); // State to control Credentials modal - // const [currentPassword, setCurrentPassword] = useState(''); // State to store current password - // const [newPassword, setNewPassword] = useState(''); // State to store new password - // const [password, setPassword] = useState(''); // State to store password - // const [privateKey, setPrivateKey] = useState(''); // State to store private key - - const { file, setFile, userPass, currentPassword, newPassword, password, privateKey } = useContext(ModalContext); - const { history, addMessage, generateChat, showPasswordModal, setShowPasswordModal,showCredentialsModal,setShowCredentialsModal,showUpdatePasswordModal,setShowUpdatePasswordModal ,showFileUploadModal,setShowFileUploadModal,} = useChatStore(); + + const { + file, + setFile, + userPass, + currentPassword, + newPassword, + password, + privateKey, + } = useContext(ModalContext); + const { + history, + addMessage, + generateChat, + showPasswordModal, + setShowPasswordModal, + showCredentialsModal, + setShowCredentialsModal, + showUpdatePasswordModal, + setShowUpdatePasswordModal, + showFileUploadModal, + setShowFileUploadModal, + } = useChatStore(); const toast = useToast(); useEffect(() => { @@ -53,28 +78,60 @@ const ChatUI = () => { ); useEffect(() => { - if(password){ - generateChat(message.trim(), file, userPass, currentPassword, newPassword, password, privateKey); + if (password) { + generateChat( + message.trim(), + file, + userPass, + currentPassword, + newPassword, + password, + privateKey + ); } - },[showCredentialsModal]) + }, [showCredentialsModal]); useEffect(() => { - if(currentPassword){ - generateChat(message.trim(), file, userPass, currentPassword, newPassword, password, privateKey); + if (currentPassword) { + generateChat( + message.trim(), + file, + userPass, + currentPassword, + newPassword, + password, + privateKey + ); } - },[showUpdatePasswordModal]) + }, [showUpdatePasswordModal]); useEffect(() => { - if(file){ - generateChat(message.trim(), file, userPass, currentPassword, newPassword, password, privateKey); + if (file) { + generateChat( + message.trim(), + file, + userPass, + currentPassword, + newPassword, + password, + privateKey + ); } - },[showFileUploadModal]) + }, [showFileUploadModal]); useEffect(() => { - if(password){ - generateChat(message.trim(), file, userPass, currentPassword, newPassword, password, privateKey); + if (password) { + generateChat( + message.trim(), + file, + userPass, + currentPassword, + newPassword, + password, + privateKey + ); } - },[showPasswordModal]) + }, [showPasswordModal]); const handleSendMessage = () => { if (message.trim() === '') return; @@ -87,7 +144,15 @@ const ChatUI = () => { }; addMessage(newMessage); - generateChat(message.trim(), file, userPass, currentPassword, newPassword, password, privateKey); + generateChat( + message.trim(), + file, + userPass, + currentPassword, + newPassword, + password, + privateKey + ); setMessage(''); setFile(null); setFileName(''); @@ -101,15 +166,6 @@ const ChatUI = () => { } }; - // const handleFileChange = (e: React.ChangeEvent) => { - // if (e.target.files && e.target.files.length > 0) { - // const selectedFile = e.target.files[0]; - // setFile(selectedFile); - // setFileName(selectedFile.name); - // setIsFileAttached(true); // Set file attachment status - // } - // }; - useEffect(() => { const chatHistoryElement = document.getElementById('chat-history'); if (chatHistoryElement) { @@ -129,76 +185,60 @@ const ChatUI = () => { Enter Password - + - - - {/* Update Password Modal */} - setShowUpdatePasswordModal(false)}> + setShowUpdatePasswordModal(false)} + > Update Password - { - // setCurrentPassword(currentPassword); - // setNewPassword(newPassword); - // }} - /> + - - - {/* Credentials Modal */} - setShowCredentialsModal(false)}> + setShowCredentialsModal(false)} + > Manage Credentials - { - // setPassword(password); - // setPrivateKey(privateKey); - // }} - /> + - - - {/* File Upload Modal */} - setShowFileUploadModal(false)}> - - - Upload File - - - { - //setFile(file); - setFileName(file.name); - setIsFileAttached(true); - //setShowFileUploadModal(false); - }} /> - - - - - - + setShowFileUploadModal(false)} + > + + + Upload File + + + { + setFileName(file.name); + setIsFileAttached(true); + }} + /> + + +