From a0ee74d672f51358d090c2a2355c4b4a5698204d Mon Sep 17 00:00:00 2001 From: przeq piciel Date: Sun, 1 Sep 2024 09:33:14 +0000 Subject: [PATCH] add sorting functionality --- app/components/Pterodactyl/files.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/components/Pterodactyl/files.tsx b/app/components/Pterodactyl/files.tsx index 864a49c..de27784 100644 --- a/app/components/Pterodactyl/files.tsx +++ b/app/components/Pterodactyl/files.tsx @@ -44,6 +44,14 @@ export default function files(pterodactyl: any) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); + const sortedFileList = data.data.sort((a: File, b: File) => { + // Sort directories before files + if (!a.attributes.is_file && b.attributes.is_file) return -1; + if (a.attributes.is_file && !b.attributes.is_file) return 1; + // Sort alphabetically by name + return a.attributes.name.localeCompare(b.attributes.name); + }); + return data.data; } catch (error) { console.error("Error fetching data:", error);