diff --git a/Frontend/src/components/FileList.jsx b/Frontend/src/components/FileList.jsx new file mode 100644 index 0000000..22e4d1a --- /dev/null +++ b/Frontend/src/components/FileList.jsx @@ -0,0 +1,134 @@ +import React, { useState, useEffect } from "react"; +import PropTypes from "prop-types"; + +const FileTable = ({ initialPath }) => { + const [currentPath, setCurrentPath] = useState(initialPath || "/"); + const [files, setFiles] = useState([]); + + // Helpers to parse entry + const getType = (entry) => + entry.trim().startsWith("📁") ? "Folder" : "File"; + const getName = (entry) => entry.trim().replace(/^📁\s*|^📄\s*/, ""); + const isFile = (entry) => getType(entry) === "File"; + + // Fetch and show only top-level entries (indentation = 0) + const fetchFiles = async () => { + try { + const response = await fetch( + `http://192.168.29.61:8080/api/hdfs/listFiles?hdfsPath=${currentPath}` + ); + const data = await response.json(); + + // Filter entries: only those without leading spaces + const filtered = data.filter( + (entry) => entry.match(/^ */)[0].length === 0 + ); + setFiles(filtered); + } catch (error) { + console.error("Failed to fetch files:", error); + setFiles([]); + } + }; + + useEffect(() => { + fetchFiles(); + }, [currentPath]); + + // Navigate into a folder + const handleOpenFolder = (folderName) => { + const newPath = + currentPath === "/" ? `/${folderName}` : `${currentPath}/${folderName}`; + setCurrentPath(newPath); + }; + + // Go up one level + const goBack = () => { + if (currentPath === "/") return; + const parts = currentPath.split("/").filter(Boolean); + parts.pop(); + setCurrentPath(parts.length === 0 ? "/" : `/${parts.join("/")}`); + }; + + return ( +
+
+ Path: {currentPath} + {currentPath !== "/" && ( + + )} +
+ + + + + + + + + + {files.length === 0 ? ( + + + + ) : ( + files.map((entry, idx) => { + const name = getName(entry); + const type = getType(entry); + const encodedPath = encodeURIComponent(`${currentPath}/${name}`); + const downloadUrl = `http://192.168.29.61:8080/api/hdfs/downloadFile?hdfsPath=${encodedPath}&localPath=E:/testdownload/${name}&kalas=${ + currentPath.split("/")[1] || "user" + }`; + + return ( + + + + + + ); + }) + )} + +
+ File Name + + Type + + Action +
+ No files found. +
+ {name} + {type} + {isFile(entry) ? ( + + Download + + ) : ( + + )} +
+
+ ); +}; + +FileTable.propTypes = { + initialPath: PropTypes.string, +}; + +export default FileTable; diff --git a/Frontend/src/pages/UserPages/Dashboard.jsx b/Frontend/src/pages/UserPages/Dashboard.jsx index b04bf35..9e1a582 100644 --- a/Frontend/src/pages/UserPages/Dashboard.jsx +++ b/Frontend/src/pages/UserPages/Dashboard.jsx @@ -1,16 +1,23 @@ import React from "react"; import Sidebar from "../../components/Sidebar"; +import FileList from "../../components/FileList"; import FileUpload from "../../components/FileUpload"; import { FiPlus } from "react-icons/fi"; const Dashboard = () => { - const handlefetch = async () => { - fetch("http://192.168.29.61:8080/api/hdfs/listFiles?hdfsPath=/") - .then((response) => response.json()) - .then((data) => console.log(data)); - }; + const [files, setFiles] = React.useState([]); + + React.useEffect(() => { + const fetchData = async () => { + const response = await fetch( + "http://192.168.29.61:8080/api/hdfs/listFiles?hdfsPath=/" + ); + const data = await response.json(); + setFiles(data); + }; + fetchData(); + }, []); - handlefetch(); return ( <> {/* */} @@ -91,6 +98,7 @@ const Dashboard = () => { +
{/* */}
diff --git a/package-lock.json b/package-lock.json index f7d7ae9..dfff477 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "Drive-thru", + "name": "cc-mini", "lockfileVersion": 3, "requires": true, "packages": {}