Refactor file loading and code retrieval logic

This commit refactors the code in the `Page` component to improve the file loading and code retrieval logic. It removes the hardcoded initial code value and replaces it with an empty string. It also updates the `useEffect` hook to properly handle the startup of the application and retrieve the code content using the `Pterodactyl` API. Additionally, it updates the rendering of the breadcrumbs and adds a save button to the file editor.

Refactor file directory change functionality

This commit refactors the `changeDirectory` function in the `Index` component of the `FilesEditor` module. The function is removed as it is no longer used and has been replaced with a more efficient approach to handle directory changes.
This commit is contained in:
2024-09-14 08:28:09 +00:00
parent faa45f7fcf
commit 25605200e1
2 changed files with 54 additions and 59 deletions

View File

@@ -13,26 +13,30 @@ function Page() {
const searchParams = useSearchParams(); const searchParams = useSearchParams();
const serverId = searchParams.get("serverid") || ""; const serverId = searchParams.get("serverid") || "";
const path = searchParams.get("path") || ""; const path = searchParams.get("path") || "";
const [code, setCode] = useState("dupa"); const [code, setCode] = useState("");
const pterodactyl = new Pterodactyl();
useEffect(() => { useEffect(
const startupApp = async () => { function () {
async function startupApp() {
const panelApp = new Panel(); const panelApp = new Panel();
const pterodactyl = new Pterodactyl();
const credentials = await panelApp.getCredentials(); const credentials = await panelApp.getCredentials();
pterodactyl.setApiKey(credentials.api_key); pterodactyl.setApiKey(credentials.api_key);
pterodactyl.setServerId(serverId); pterodactyl.setServerId(serverId);
setCode(await pterodactyl.files.getContent(path)); setCode(await pterodactyl.files.getContent(path));
}; }
if (serverId && path) { if (serverId && path) {
startupApp(); startupApp();
} }
}, [serverId, path]); },
[serverId, path]
);
return ( return (
<> <>
<div className="flex mb-4">
<BreadCrumbs> <BreadCrumbs>
<li> <li>
<div className="mr-2"> <div className="mr-2">
@@ -68,6 +72,8 @@ function Page() {
); );
})} })}
</BreadCrumbs> </BreadCrumbs>
<button className="ml-auto btn btn-accent">Save</button>
</div>
<TextEditor code={code} /> <TextEditor code={code} />
</> </>
); );

View File

@@ -100,17 +100,6 @@ const Index = () => {
setContextMenu(initialContextMenuState); setContextMenu(initialContextMenuState);
}, []); }, []);
const changeDirectory = useCallback(
(newPath: string) => {
if (pterodactyl) {
pterodactyl.helpers.setWorkingDirectory(newPath);
fetchFiles();
// setPath(newPath);
}
},
[pterodactyl, fetchFiles]
);
useEffect(() => { useEffect(() => {
if (!apiKey || !serverId) return; // Upewniamy się, że mamy apiKey i serverId if (!apiKey || !serverId) return; // Upewniamy się, że mamy apiKey i serverId
@@ -142,7 +131,7 @@ const Index = () => {
)} )}
{serverId && ( {serverId && (
<div className="flex p-4 gap-4"> <div className="flex gap-4">
<BreadCrumbs> <BreadCrumbs>
<li> <li>
<div className="mr-2"> <div className="mr-2">