diff --git a/frontend/src/Setting.tsx b/frontend/src/Setting.tsx index 3bc45be7..a52bde02 100644 --- a/frontend/src/Setting.tsx +++ b/frontend/src/Setting.tsx @@ -22,11 +22,46 @@ const Setting: React.FC = () => { const [selectedPrompt, setSelectedPrompt] = useState(''); const [newPromptName, setNewPromptName] = useState(''); const [isAddPromptModalOpen, setAddPromptModalOpen] = useState(false); + const [documents, setDocuments] = useState([]); + const [isAddDocumentModalOpen, setAddDocumentModalOpen] = useState(false); + const [newDocument, setNewDocument] = useState({ + name: '', + vectorDate: '', + vectorLocation: '', + }); const onDeletePrompt = (name: string) => { setPrompts(prompts.filter((prompt) => prompt !== name)); setSelectedPrompt(''); // Clear the selected prompt }; + // Function to add a new document + const addDocument = () => { + if ( + newDocument.name && + newDocument.vectorDate && + newDocument.vectorLocation + ) { + setDocuments([...documents, newDocument]); + setNewDocument({ + name: '', + vectorDate: '', + vectorLocation: '', + }); + toggleAddDocumentModal(); + } + }; + + // Function to toggle the Add Document modal + const toggleAddDocumentModal = () => { + setAddDocumentModalOpen(!isAddDocumentModalOpen); + }; + + const handleDeleteDocument = (index: number) => { + const updatedDocuments = [...documents]; + updatedDocuments.splice(index, 1); + setDocuments(updatedDocuments); + }; + return (

Settings

@@ -64,6 +99,15 @@ const Setting: React.FC = () => {
{renderActiveTab()} + + {isAddDocumentModalOpen && ( + + )} ); @@ -97,7 +141,15 @@ const Setting: React.FC = () => { /> ); case 'Documents': - return ; + return ( + + ); case 'Widgets': return ; default: @@ -185,7 +237,7 @@ const Prompts: React.FC = ({
@@ -204,7 +256,7 @@ const Prompts: React.FC = ({
@@ -289,7 +341,7 @@ const AddPromptModal: React.FC = ({ /> @@ -304,10 +356,144 @@ const AddPromptModal: React.FC = ({ ); }; -const Documents: React.FC = () => { +type DocumentsProps = { + documents: Document[]; + isAddDocumentModalOpen: boolean; + newDocument: Document; + handleDeleteDocument: (index: number) => void; + toggleAddDocumentModal: () => void; +}; + +const Documents: React.FC = ({ + documents, + isAddDocumentModalOpen, + newDocument, + handleDeleteDocument, + toggleAddDocumentModal, +}) => { return (
-

This is the Documents section.

+
+ {/*

Documents

*/} + +
+ + + + + + + + + + + {documents.map((document, index) => ( + + + + + + + ))} + +
Document NameVector DateVector LocationActions
{document.name}{document.vectorDate} + {document.vectorLocation} + + +
+
+ +
+ + {/* {isAddDocumentModalOpen && ( + + )} */} +
+ ); +}; + +type Document = { + name: string; + vectorDate: string; + vectorLocation: string; +}; + +// Modal for adding a new document +type AddDocumentModalProps = { + newDocument: Document; + onNewDocumentChange: (document: Document) => void; + onAddDocument: () => void; + onClose: () => void; +}; + +const AddDocumentModal: React.FC = ({ + newDocument, + onNewDocumentChange, + onAddDocument, + onClose, +}) => { + return ( +
+
+

Add New Document

+ + onNewDocumentChange({ ...newDocument, name: e.target.value }) + } + className="mb-4 w-full rounded-lg border-2 p-2" + /> + + onNewDocumentChange({ ...newDocument, vectorDate: e.target.value }) + } + className="mb-4 w-full rounded-lg border-2 p-2" + /> + + onNewDocumentChange({ + ...newDocument, + vectorLocation: e.target.value, + }) + } + className="mb-4 w-full rounded-lg border-2 p-2" + /> + + +
); };