Skip to content

Commit 6b60b54

Browse files
committed
sort bug fix
1 parent ccd74de commit 6b60b54

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

resources/js/Pages/Drive/Components/FileBrowserSection.jsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
22
memo,
33
useCallback,
4+
useContext,
45
useEffect,
56
useRef,
67
useState,
7-
useContext,
88
} from "react";
99
import { useNavigate } from "react-router-dom";
1010
import { Grid, List, StepBackIcon } from "lucide-react";
@@ -19,7 +19,7 @@ import DownloadButton from "@/Pages/Drive/Components/DownloadButton.jsx";
1919
import ShowShareModalButton from "@/Pages/Drive/Components/Shares/ShowShareModalButton.jsx";
2020
import DeleteButton from "@/Pages/Drive/Components/DeleteButton.jsx";
2121
import UploadMenu from "@/Pages/Drive/Components/UploadMenu.jsx";
22-
import { usePage, router } from "@inertiajs/react";
22+
import { router, usePage } from "@inertiajs/react";
2323
import RenameModal from "@/Pages/Drive/Components/FileList/RenameModal.jsx";
2424
import CutButton from "./CutButton.jsx";
2525
import PasteButton from "./PasteButton.jsx";
@@ -45,7 +45,8 @@ const FileBrowserSection = memo(({ files, path, token, isAdmin, slug }) => {
4545
const [fileToRename, setFileToRename] = useState(new Set());
4646
const [isRenameModalOpen, setIsRenameModalOpen] = useState(false);
4747

48-
const { cutFiles, setCutFiles, cutPath, setCutPath } = useContext(CutFilesContext);
48+
const { cutFiles, setCutFiles, cutPath, setCutPath } =
49+
useContext(CutFilesContext);
4950

5051
const handleCut = () => {
5152
setCutFiles?.(new Set(selectedFiles));
@@ -120,8 +121,13 @@ const FileBrowserSection = memo(({ files, path, token, isAdmin, slug }) => {
120121

121122
function sortArrayByKey(arr, key, direction) {
122123
return [...arr].sort((a, b) => {
123-
const valA = a[key]?.toLowerCase?.() || a[key] || "";
124-
const valB = b[key]?.toLowerCase?.() || b[key] || "";
124+
let valA =
125+
a[key]?.toLowerCase?.() || (a[key] != null ? a[key] : "");
126+
let valB =
127+
b[key]?.toLowerCase?.() || (b[key] != null ? b[key] : "");
128+
// empty string are for folders sizes
129+
valA = valA === "" ? -1 : valA;
130+
valB = valB === "" ? -1 : valB;
125131

126132
if (direction === "desc") {
127133
return valA > valB ? -1 : valA < valB ? 1 : 0;

resources/js/Pages/Drive/Components/FileList/TxtViewer.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const TxtViewer = ({
6666
}
6767
if (response.data?.message.includes("success")) {
6868
setSavedMessage("Changes saved successfully!");
69-
let src = "/fetch-file/" + previewFile.id ;
69+
let src = "/fetch-file/" + previewFile.id;
7070
appendParamsToTxtFileUrl(src);
7171
} else {
7272
setSavedMessage("Error: " + response.data?.message);
@@ -99,7 +99,7 @@ const TxtViewer = ({
9999
};
100100

101101
useEffect(() => {
102-
let src = "/fetch-file/" + previewFile.id ;
102+
let src = "/fetch-file/" + previewFile.id;
103103
appendParamsToTxtFileUrl(src);
104104
}, [previewFile, slug]);
105105

@@ -146,7 +146,10 @@ const TxtViewer = ({
146146
onClick={startEditing}
147147
/>
148148
) : (
149-
<pre className={`w-[70vw] ${isAdmin ? "cursor-pointer" : ""}`} onClick={startEditing}>
149+
<pre
150+
className={`w-[70vw] ${isAdmin ? "cursor-pointer" : ""}`}
151+
onClick={startEditing}
152+
>
150153
{content || (isAdmin ? "Click to edit..." : "Empty File")}
151154
</pre>
152155
)}

0 commit comments

Comments
 (0)