Skip to content

Commit

Permalink
Merge pull request #91 from TeamXFive/feat/knowledge
Browse files Browse the repository at this point in the history
[feat] First steps into file retrieval
  • Loading branch information
LoriaLawrenceZ authored Oct 23, 2024
2 parents c10f77e + 7c17507 commit 81a1954
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 18 deletions.
62 changes: 44 additions & 18 deletions src/pages/Knowledge/Knowledge.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '../../style/Knowledge/Knowledge.css';
import { useRef, useState } from "react";
import {useEffect, useRef, useState} from "react";
import useKnowledgeContext from "../../hook/Knowledge/useKnowledgeContext.jsx";

function Knowledge() {
Expand Down Expand Up @@ -59,8 +59,6 @@ function Knowledge() {
};

const validateAndSetFiles = (incomingFiles) => {
const validFiles = [];

incomingFiles.forEach(async (file) => {
// Validate file type
if (!allowedFileTypes.includes(file.type)) {
Expand All @@ -84,19 +82,44 @@ function Knowledge() {

const formData = new FormData();
formData.append('file', file);

const response = await fetch('http://localhost:3000/upload', {
method: 'POST',
body: formData
});
validFiles.push(file);


try {
const response = await fetch('http://localhost:3000/upload', {
method: 'POST',
body: formData
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

const result = await response.text();
console.log(result);
getFiles();
} catch (error) {
console.error('Error uploading file:', error);
}
}
});

setFiles(validFiles);
};

const getFiles = async () => {
try {
const response = await fetch('http://localhost:3000/file_retrieval', {
method: 'POST'
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

const result = await response.json();
console.log(result);
setFiles(result)
} catch (error) {
console.error('Error retrieving files:', error);
}
}

// Handle button click to open file input dialog
const openFileDialog = () => {
fileInputRef.current.click();
Expand Down Expand Up @@ -142,12 +165,15 @@ function Knowledge() {
</section>

<section className={`knowledge-documents`}>
<div>Stored Documents</div>
<ul>
{files.map((file, index) => (
<li key={index}>{file.name}</li>
))}
</ul>
<div className={`knowledge-documents-header`}>Stored Documents</div>

<div className={`knowledge-documents-list-container`}>
<ul className={`knowledge-documents-list`}>
{files.map((file, index) => (
<li className={`knowledge-documents-item`} key={index}>{file.filename}</li>
))}
</ul>
</div>
</section>
</article>
</>
Expand Down
18 changes: 18 additions & 0 deletions src/style/Knowledge/Knowledge.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@
.knowledge-documents {
height: 55%;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
border: solid 1px var(--dark-gray);
border-radius: 1em;
background-color: var(--black-gray);
}

/*-----===| Drag n Drop |===-----*/
.knowledge-header-description {
height: 25%;
width: 90%;
Expand All @@ -53,4 +58,17 @@
display: flex;
align-items: center;
justify-content: center;
}

/*-----===| Documents Listing |===-----*/
.knowledge-documents-header {}

.knowledge-documents-list-container {
height: 90%;
width: 95%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
overflow: auto;
}

0 comments on commit 81a1954

Please sign in to comment.