fix
This commit is contained in:
@@ -4,7 +4,9 @@ import React, { useCallback } from "react";
|
|||||||
|
|
||||||
import { useSearchParams } from "next/navigation";
|
import { useSearchParams } from "next/navigation";
|
||||||
import TextEditor from "@/components/TextEditor";
|
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() {
|
function Page() {
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
@@ -17,11 +19,41 @@ function Page() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<BreadCrumbs
|
<BreadCrumbs>
|
||||||
changeDirectory={changeDirectory}
|
<li>
|
||||||
serverId={serverId}
|
<div className="mr-2">
|
||||||
path={path}
|
<ServerIcon />
|
||||||
/>
|
</div>
|
||||||
|
{serverId}
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href={`/files?serverid=${serverId}&path=/`}>
|
||||||
|
<div className="mr-2">
|
||||||
|
<FolderIcon />
|
||||||
|
</div>
|
||||||
|
<span>/</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{path
|
||||||
|
.split("/")
|
||||||
|
.filter((p) => p !== "")
|
||||||
|
.map((element, index) => {
|
||||||
|
const tmp_path = path
|
||||||
|
.split("/")
|
||||||
|
.slice(0, index + 2)
|
||||||
|
.join("/");
|
||||||
|
return (
|
||||||
|
<li key={index}>
|
||||||
|
<a href={`/files?serverid=${serverId}&path=${tmp_path}`}>
|
||||||
|
<div className="mr-2">
|
||||||
|
<FolderIcon />
|
||||||
|
</div>
|
||||||
|
<span>{element}</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</BreadCrumbs>
|
||||||
<TextEditor />;
|
<TextEditor />;
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { formatDistanceToNow } from "date-fns";
|
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 DocumentIcon from "@/components/Icons/Document";
|
||||||
import FolderIcon from "@/components/Icons/Folder";
|
import FolderIcon from "@/components/Icons/Folder";
|
||||||
import ServerIcon from "@/components/Icons/Server";
|
import ServerIcon from "@/components/Icons/Server";
|
||||||
@@ -11,7 +11,6 @@ import RenamePopup from "./ContextMenu/rename";
|
|||||||
import Pterodactyl from "@/components/Pterodactyl";
|
import Pterodactyl from "@/components/Pterodactyl";
|
||||||
import BreadCrumbs from "@/components/BreadCrumbs";
|
import BreadCrumbs from "@/components/BreadCrumbs";
|
||||||
import { useSearchParams } from "next/navigation";
|
import { useSearchParams } from "next/navigation";
|
||||||
import Link from "next/link";
|
|
||||||
|
|
||||||
interface FileAttributes {
|
interface FileAttributes {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -47,7 +46,9 @@ const initialRenamePopupState: RenamePopupState = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Index = () => {
|
const Index = () => {
|
||||||
const [apiKey, setApiKey] = useState<string>("");
|
const [apiKey, setApiKey] = useState<string>(
|
||||||
|
"ptlc_N77A2hEczFmSwGXm4cEXh4Gw3ZP0Ygr5NaBkGlE7pjU"
|
||||||
|
);
|
||||||
const [fileList, setFileList] = useState<FileProps[]>([]);
|
const [fileList, setFileList] = useState<FileProps[]>([]);
|
||||||
const [contextMenu, setContextMenu] = useState<ContextMenuState>(
|
const [contextMenu, setContextMenu] = useState<ContextMenuState>(
|
||||||
initialContextMenuState
|
initialContextMenuState
|
||||||
@@ -57,14 +58,9 @@ const Index = () => {
|
|||||||
);
|
);
|
||||||
const [selectedFile, setSelectedFile] = useState<FileProps | null>(null);
|
const [selectedFile, setSelectedFile] = useState<FileProps | null>(null);
|
||||||
const [ptero, setPtero] = useState<Pterodactyl | null>(null);
|
const [ptero, setPtero] = useState<Pterodactyl | null>(null);
|
||||||
const [path, setPath] = useState<string>("/");
|
|
||||||
const urlParams = useSearchParams();
|
const urlParams = useSearchParams();
|
||||||
const serverId = urlParams.get("serverid");
|
const serverId = urlParams.get("serverid");
|
||||||
const pathParam = urlParams.get("path");
|
const pathParam = urlParams.get("path") || "/";
|
||||||
|
|
||||||
const setCredentials = useCallback(() => {
|
|
||||||
setApiKey("ptlc_N77A2hEczFmSwGXm4cEXh4Gw3ZP0Ygr5NaBkGlE7pjU");
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const showRenamePopup = useCallback(() => {
|
const showRenamePopup = useCallback(() => {
|
||||||
setContextMenu(initialContextMenuState);
|
setContextMenu(initialContextMenuState);
|
||||||
@@ -76,6 +72,7 @@ const Index = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const fetchFiles = useCallback(async (ptero: Pterodactyl) => {
|
const fetchFiles = useCallback(async (ptero: Pterodactyl) => {
|
||||||
|
console.log("chwytam pliki");
|
||||||
const files = await ptero.files.fetchFiles();
|
const files = await ptero.files.fetchFiles();
|
||||||
setFileList(files);
|
setFileList(files);
|
||||||
}, []);
|
}, []);
|
||||||
@@ -108,7 +105,7 @@ const Index = () => {
|
|||||||
if (ptero) {
|
if (ptero) {
|
||||||
ptero.helpers.setWorkingDirectory(newPath);
|
ptero.helpers.setWorkingDirectory(newPath);
|
||||||
fetchFiles(ptero);
|
fetchFiles(ptero);
|
||||||
setPath(newPath);
|
// setPath(newPath);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[ptero, fetchFiles]
|
[ptero, fetchFiles]
|
||||||
@@ -116,20 +113,19 @@ const Index = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const setupApplication = async () => {
|
const setupApplication = async () => {
|
||||||
await setCredentials();
|
if (!apiKey || !serverId) return; // Upewniamy się, że mamy apiKey i serverId
|
||||||
if (apiKey && serverId) {
|
if (!ptero) {
|
||||||
const pteroInstance = new Pterodactyl(serverId, apiKey);
|
console.log("tworze instancje ptero");
|
||||||
if (pathParam) {
|
const pteroInstance = await new Pterodactyl(serverId, apiKey);
|
||||||
setPath(pathParam);
|
|
||||||
}
|
|
||||||
pteroInstance.helpers.setWorkingDirectory(path);
|
|
||||||
setPtero(pteroInstance);
|
setPtero(pteroInstance);
|
||||||
await fetchFiles(pteroInstance);
|
|
||||||
|
pteroInstance.helpers.setWorkingDirectory(pathParam);
|
||||||
|
await fetchFiles(pteroInstance); // Wywołanie fetchFiles raz po ustawieniu instancji
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
setupApplication();
|
setupApplication();
|
||||||
}, [apiKey, serverId, setCredentials, path, fetchFiles]);
|
}, [apiKey, serverId, ptero, pathParam, fetchFiles]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -168,11 +164,11 @@ const Index = () => {
|
|||||||
<span>/</span>
|
<span>/</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{path
|
{pathParam
|
||||||
.split("/")
|
.split("/")
|
||||||
.filter((p) => p !== "")
|
.filter((p) => p !== "")
|
||||||
.map((element, index) => {
|
.map((element, index) => {
|
||||||
const tmp_path = path
|
const tmp_path = pathParam
|
||||||
.split("/")
|
.split("/")
|
||||||
.slice(0, index + 2)
|
.slice(0, index + 2)
|
||||||
.join("/");
|
.join("/");
|
||||||
@@ -223,7 +219,7 @@ const Index = () => {
|
|||||||
{file.attributes.is_file ? (
|
{file.attributes.is_file ? (
|
||||||
<a
|
<a
|
||||||
href={`/files/edit?serverid=${serverId}&path=${
|
href={`/files/edit?serverid=${serverId}&path=${
|
||||||
path != "/" ? path : ""
|
pathParam != "/" ? pathParam : ""
|
||||||
}/${file.attributes.name}`}
|
}/${file.attributes.name}`}
|
||||||
>
|
>
|
||||||
{file.attributes.name}
|
{file.attributes.name}
|
||||||
@@ -231,7 +227,7 @@ const Index = () => {
|
|||||||
) : (
|
) : (
|
||||||
<a
|
<a
|
||||||
href={`/files?serverid=${serverId}&path=${
|
href={`/files?serverid=${serverId}&path=${
|
||||||
path != "/" ? path : ""
|
pathParam != "/" ? pathParam : ""
|
||||||
}/${file.attributes.name}`}
|
}/${file.attributes.name}`}
|
||||||
>
|
>
|
||||||
{file.attributes.name}
|
{file.attributes.name}
|
||||||
|
|||||||
Reference in New Issue
Block a user