loading file into text editor

This commit is contained in:
2024-09-13 21:00:08 +00:00
parent 437701ffac
commit faa45f7fcf
6 changed files with 97 additions and 36 deletions

View File

@@ -57,7 +57,7 @@ const Index = () => {
initialRenamePopupState
);
const [selectedFile, setSelectedFile] = useState<FileProps | null>(null);
const [ptero, setPtero] = useState<Pterodactyl | null>(null);
const pterodactyl = useMemo(() => new Pterodactyl(), []);
const urlParams = useSearchParams();
const serverId = urlParams.get("serverid");
const pathParam = urlParams.get("path") || "/";
@@ -71,21 +71,21 @@ const Index = () => {
setRenamePopup(initialRenamePopupState);
}, []);
const fetchFiles = useCallback(async (ptero: Pterodactyl) => {
const fetchFiles = useCallback(async () => {
console.log("chwytam pliki");
const files = await ptero.files.fetchFiles();
const files = await pterodactyl.files.fetchFiles();
setFileList(files);
}, []);
}, [pterodactyl]);
const handleRenameFile = useCallback(
async (file: FileProps, newName: string) => {
if (ptero) {
await ptero.files.rename(file, newName);
await fetchFiles(ptero);
if (pterodactyl) {
await pterodactyl.files.rename(file, newName);
await fetchFiles();
setRenamePopup(initialRenamePopupState);
}
},
[ptero, fetchFiles]
[pterodactyl, fetchFiles]
);
const handleClickContextMenu = useCallback(
@@ -102,29 +102,24 @@ const Index = () => {
const changeDirectory = useCallback(
(newPath: string) => {
if (ptero) {
ptero.helpers.setWorkingDirectory(newPath);
fetchFiles(ptero);
if (pterodactyl) {
pterodactyl.helpers.setWorkingDirectory(newPath);
fetchFiles();
// setPath(newPath);
}
},
[ptero, fetchFiles]
[pterodactyl, fetchFiles]
);
useEffect(() => {
const setupApplication = () => {
if (!apiKey || !serverId) return; // Upewniamy się, że mamy apiKey i serverId
if (!ptero) {
const pteroInstance = new Pterodactyl(serverId, apiKey);
setPtero(pteroInstance);
if (!apiKey || !serverId) return; // Upewniamy się, że mamy apiKey i serverId
pteroInstance.helpers.setWorkingDirectory(pathParam);
fetchFiles(pteroInstance); // Wywołanie fetchFiles raz po ustawieniu instancji
}
};
pterodactyl.setApiKey(apiKey);
pterodactyl.setServerId(serverId);
pterodactyl.helpers.setWorkingDirectory(pathParam);
setupApplication();
}, [apiKey, serverId, ptero, pathParam, fetchFiles]);
fetchFiles(); // Wywołanie fetchFiles raz po ustawieniu instancji
}, [apiKey, serverId, pterodactyl, pathParam, fetchFiles]);
return (
<>