From 5e518a2ad32028591db574e9e470a2bf5d35fbc2 Mon Sep 17 00:00:00 2001 From: monoid Date: Tue, 14 Feb 2023 21:42:56 +0900 Subject: [PATCH] add compasibility --- islands/DirList.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/islands/DirList.tsx b/islands/DirList.tsx index 40af353..a139525 100644 --- a/islands/DirList.tsx +++ b/islands/DirList.tsx @@ -37,12 +37,18 @@ interface DirListProps { } const natsortCompare = natsort(); +function toSorted(arr: T[], compareFn: (a:T,b:T) => number): T[]{ + const ret = Array.from(arr); + ret.sort(compareFn); + return ret; +} + export function DirList(props: DirListProps) { const data = props; const [files, setFiles] = useState( - data.files.toSorted( + toSorted(data.files,( (a,b)=> natsortCompare(a.name,b.name) - ) + )) ); return (