mirror of
https://github.com/bewcloud/bewcloud.git
synced 2026-03-11 08:54:49 +00:00
Keep .Trash at the top, ignore sort
This commit is contained in:
parent
8643075b7f
commit
dbb91a9c1a
1 changed files with 41 additions and 4 deletions
|
|
@ -44,6 +44,17 @@ export function sortEntriesByName(entryA: Deno.DirEntry, entryB: Deno.DirEntry)
|
|||
}
|
||||
|
||||
export function sortDirectoriesByName(directoryA: Directory, directoryB: Directory) {
|
||||
// Always put .Trash directory first
|
||||
const fullPathA = `${directoryA.parent_path}${directoryA.directory_name}/`;
|
||||
const fullPathB = `${directoryB.parent_path}${directoryB.directory_name}/`;
|
||||
|
||||
if (fullPathA === TRASH_PATH || directoryA.directory_name === '.Trash') {
|
||||
return -1;
|
||||
}
|
||||
if (fullPathB === TRASH_PATH || directoryB.directory_name === '.Trash') {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const nameA = directoryA.directory_name.toLocaleLowerCase();
|
||||
const nameB = directoryB.directory_name.toLocaleLowerCase();
|
||||
|
||||
|
|
@ -59,6 +70,14 @@ export function sortDirectoriesByName(directoryA: Directory, directoryB: Directo
|
|||
}
|
||||
|
||||
export function sortFilesByName(fileA: DirectoryFile, fileB: DirectoryFile) {
|
||||
// Always put .Trash file first (if it exists)
|
||||
if (fileA.file_name === '.Trash') {
|
||||
return -1;
|
||||
}
|
||||
if (fileB.file_name === '.Trash') {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const nameA = fileA.file_name.toLocaleLowerCase();
|
||||
const nameB = fileB.file_name.toLocaleLowerCase();
|
||||
|
||||
|
|
@ -74,7 +93,18 @@ export function sortFilesByName(fileA: DirectoryFile, fileB: DirectoryFile) {
|
|||
}
|
||||
|
||||
export function sortDirectories(directories: Directory[], options: SortOptions): Directory[] {
|
||||
const sorted = [...directories].sort((a, b) => {
|
||||
// Separate .Trash folder from other directories
|
||||
const trashDir = directories.find(dir =>
|
||||
`${dir.parent_path}${dir.directory_name}/` === TRASH_PATH ||
|
||||
dir.directory_name === '.Trash'
|
||||
);
|
||||
const otherDirs = directories.filter(dir =>
|
||||
`${dir.parent_path}${dir.directory_name}/` !== TRASH_PATH &&
|
||||
dir.directory_name !== '.Trash'
|
||||
);
|
||||
|
||||
// Sort the non-trash directories
|
||||
const sorted = [...otherDirs].sort((a, b) => {
|
||||
let result = 0;
|
||||
|
||||
switch (options.sortBy) {
|
||||
|
|
@ -92,11 +122,17 @@ export function sortDirectories(directories: Directory[], options: SortOptions):
|
|||
return options.sortOrder === 'desc' ? -result : result;
|
||||
});
|
||||
|
||||
return sorted;
|
||||
// Return with .Trash folder first (if it exists), followed by sorted directories
|
||||
return trashDir ? [trashDir, ...sorted] : sorted;
|
||||
}
|
||||
|
||||
export function sortFiles(files: DirectoryFile[], options: SortOptions): DirectoryFile[] {
|
||||
const sorted = [...files].sort((a, b) => {
|
||||
// Separate .Trash file from other files (if it exists)
|
||||
const trashFile = files.find(file => file.file_name === '.Trash');
|
||||
const otherFiles = files.filter(file => file.file_name !== '.Trash');
|
||||
|
||||
// Sort the non-trash files
|
||||
const sorted = [...otherFiles].sort((a, b) => {
|
||||
let result = 0;
|
||||
|
||||
switch (options.sortBy) {
|
||||
|
|
@ -114,5 +150,6 @@ export function sortFiles(files: DirectoryFile[], options: SortOptions): Directo
|
|||
return options.sortOrder === 'desc' ? -result : result;
|
||||
});
|
||||
|
||||
return sorted;
|
||||
// Return with .Trash file first (if it exists), followed by sorted files
|
||||
return trashFile ? [trashFile, ...sorted] : sorted;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue