diff --git a/dashboard/src/components/FileViewer/FileList.tsx b/dashboard/src/components/FileViewer/FileList.tsx
index cfe63ba3..8bd06ce9 100644
--- a/dashboard/src/components/FileViewer/FileList.tsx
+++ b/dashboard/src/components/FileViewer/FileList.tsx
@@ -121,6 +121,11 @@ export default function FileList({
x: 0,
y: 0,
});
+ const [sortUpdate, setSortUpdate] = useState(false);
+ const [sortKey, setSortKey] = useState<{ key: string, direction: number}>({
+ key: '',
+ direction: -1 // 1 for asc, -1 for desc
+ })
const [showContextMenu, setShowContextMenu] = useState(false);
const [contextMenuCoords, setContextMenuCoords] = useState({ x: 0, y: 0 });
const [contextMenuFile, setContextMenuFile] = useState();
@@ -151,6 +156,31 @@ export default function FileList({
}
}, []);
+ useEffect(() => {
+ if (sortKey.key == '') return;
+ fileList?.sort((a, b) => {
+ const { direction, key } = sortKey;
+
+ // group directories together
+ if (a.file_type === 'Directory' && b.file_type !== 'Directory') return -1 * direction;
+ if (a.file_type !== 'Directory' && b.file_type === 'Directory') return 1 * direction;
+
+ const compare = (val1: string | number | null, val2: string | number | null) => {
+ if (!val1) return -1;
+ if (!val2) return 1;
+ return val1 < val2 ? -1 : 1;
+ };
+
+ let result = 0;
+ if (key === 'name') result = compare(a.name, b.name);
+ else if (key === 'date_modified') result = compare(a.modification_time, b.modification_time);
+ else if (key === 'size') result = compare(a.size, b.size);
+ return direction === 1 ? result : -result;
+ });
+ setSortUpdate(!sortUpdate);
+
+ }, [sortKey, fileList]);
+
const onMouseMove = (e: MouseEvent) => {
setMousePos({ x: e.clientX - absCoords.x, y: e.clientY - absCoords.y });
};
@@ -314,6 +344,21 @@ export default function FileList({
)}
+
+
setSortKey({ key: 'name', direction: sortKey.direction * -1})}>
+ Name
+
+
+
setSortKey({ key: 'date_modified', direction: sortKey.direction * -1})}>
+ Date modified
+
+
setSortKey({ key: 'size', direction: sortKey.direction * -1})}>
+ Size
+
+
{fileList?.map((file: ClientFile) => (
{file.modification_time || file.creation_time
- ? formatTimeAgo(
- Number(file.modification_time ?? file.creation_time) * 1000
- )
+ ? formatTimeAgo(Number(file.modification_time ?? file.creation_time) * 1000)
: 'Unknown Creation Time'}