diff --git a/app/app/files/edit/page.tsx b/app/app/files/edit/page.tsx
index 287ed7e..02158e4 100644
--- a/app/app/files/edit/page.tsx
+++ b/app/app/files/edit/page.tsx
@@ -4,7 +4,9 @@ import React, { useCallback } from "react";
import { useSearchParams } from "next/navigation";
import TextEditor from "@/components/TextEditor";
-import BreadCrumbs from "@/components/FilesEditor/BreadCrumbs";
+import BreadCrumbs from "@/components/BreadCrumbs";
+import ServerIcon from "@/components/Icons/Server";
+import FolderIcon from "@/components/Icons/Folder";
function Page() {
const searchParams = useSearchParams();
@@ -17,11 +19,41 @@ function Page() {
return (
<>
-
+
+
+
+
+
+ {serverId}
+
+
+
+
+
+
+ /
+
+
+ {path
+ .split("/")
+ .filter((p) => p !== "")
+ .map((element, index) => {
+ const tmp_path = path
+ .split("/")
+ .slice(0, index + 2)
+ .join("/");
+ return (
+
+
+
+
+
+ {element}
+
+
+ );
+ })}
+
;
>
);
diff --git a/app/components/FilesEditor/index.tsx b/app/components/FilesEditor/index.tsx
index 3b0b2c9..2f557cf 100644
--- a/app/components/FilesEditor/index.tsx
+++ b/app/components/FilesEditor/index.tsx
@@ -1,7 +1,7 @@
"use client";
import { formatDistanceToNow } from "date-fns";
-import React, { useEffect, useState, useCallback } from "react";
+import React, { useEffect, useState, useCallback, useMemo } from "react";
import DocumentIcon from "@/components/Icons/Document";
import FolderIcon from "@/components/Icons/Folder";
import ServerIcon from "@/components/Icons/Server";
@@ -11,7 +11,6 @@ import RenamePopup from "./ContextMenu/rename";
import Pterodactyl from "@/components/Pterodactyl";
import BreadCrumbs from "@/components/BreadCrumbs";
import { useSearchParams } from "next/navigation";
-import Link from "next/link";
interface FileAttributes {
name: string;
@@ -47,7 +46,9 @@ const initialRenamePopupState: RenamePopupState = {
};
const Index = () => {
- const [apiKey, setApiKey] = useState("");
+ const [apiKey, setApiKey] = useState(
+ "ptlc_N77A2hEczFmSwGXm4cEXh4Gw3ZP0Ygr5NaBkGlE7pjU"
+ );
const [fileList, setFileList] = useState([]);
const [contextMenu, setContextMenu] = useState(
initialContextMenuState
@@ -57,14 +58,9 @@ const Index = () => {
);
const [selectedFile, setSelectedFile] = useState(null);
const [ptero, setPtero] = useState(null);
- const [path, setPath] = useState("/");
const urlParams = useSearchParams();
const serverId = urlParams.get("serverid");
- const pathParam = urlParams.get("path");
-
- const setCredentials = useCallback(() => {
- setApiKey("ptlc_N77A2hEczFmSwGXm4cEXh4Gw3ZP0Ygr5NaBkGlE7pjU");
- }, []);
+ const pathParam = urlParams.get("path") || "/";
const showRenamePopup = useCallback(() => {
setContextMenu(initialContextMenuState);
@@ -76,6 +72,7 @@ const Index = () => {
}, []);
const fetchFiles = useCallback(async (ptero: Pterodactyl) => {
+ console.log("chwytam pliki");
const files = await ptero.files.fetchFiles();
setFileList(files);
}, []);
@@ -108,7 +105,7 @@ const Index = () => {
if (ptero) {
ptero.helpers.setWorkingDirectory(newPath);
fetchFiles(ptero);
- setPath(newPath);
+ // setPath(newPath);
}
},
[ptero, fetchFiles]
@@ -116,20 +113,19 @@ const Index = () => {
useEffect(() => {
const setupApplication = async () => {
- await setCredentials();
- if (apiKey && serverId) {
- const pteroInstance = new Pterodactyl(serverId, apiKey);
- if (pathParam) {
- setPath(pathParam);
- }
- pteroInstance.helpers.setWorkingDirectory(path);
+ if (!apiKey || !serverId) return; // Upewniamy się, że mamy apiKey i serverId
+ if (!ptero) {
+ console.log("tworze instancje ptero");
+ const pteroInstance = await new Pterodactyl(serverId, apiKey);
setPtero(pteroInstance);
- await fetchFiles(pteroInstance);
+
+ pteroInstance.helpers.setWorkingDirectory(pathParam);
+ await fetchFiles(pteroInstance); // Wywołanie fetchFiles raz po ustawieniu instancji
}
};
setupApplication();
- }, [apiKey, serverId, setCredentials, path, fetchFiles]);
+ }, [apiKey, serverId, ptero, pathParam, fetchFiles]);
return (
<>
@@ -168,11 +164,11 @@ const Index = () => {
/
- {path
+ {pathParam
.split("/")
.filter((p) => p !== "")
.map((element, index) => {
- const tmp_path = path
+ const tmp_path = pathParam
.split("/")
.slice(0, index + 2)
.join("/");
@@ -223,7 +219,7 @@ const Index = () => {
{file.attributes.is_file ? (
{file.attributes.name}
@@ -231,7 +227,7 @@ const Index = () => {
) : (
{file.attributes.name}