You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm looking for a way to specify the sort direction when sorting by name/modified. Can we do something like this?
import{compareAsc,compareDesc}from'date-fns';functionlastModifiedSort(allFiles,direction='asc'){constfolders=[];letfiles=[];for(letfileIndex=0;fileIndex<allFiles.length;fileIndex++){constfile=allFiles[fileIndex];constkeyFolders=(file.newKey||file.key).split('/');if(file.children){folders.push(file);}else{file.name=keyFolders[keyFolders.length-1];files.push(file);}}// Sort files based on directionif(direction==='asc'){files=files.sort(compareAsc);}else{files=files.sort(compareDesc);}for(letfolderIndex=0;folderIndex<folders.length;folderIndex++){constfolder=folders[folderIndex];folder.children=lastModifiedSort(folder.children,direction);}letsortedFiles=[];sortedFiles=sortedFiles.concat(folders);sortedFiles=sortedFiles.concat(files);returnsortedFiles;}exportdefaultfunction(files,direction){returnlastModifiedSort(files,direction);}
Typescript equivalent:
import{compareAsc,compareDesc}from'date-fns';// Define an enum for sorting directionenumSortDirection{ASCENDING='asc',DESCENDING='desc'}functionsortByLastModified(payload,direction: SortDirection=SortDirection.ASCENDING){constfolders=[];letfiles=[];for(letfileIndex=0;fileIndex<payload.length;fileIndex++){constfile=payload[fileIndex];constkeyFolders=(file.newKey||file.key).split('/');if(file.children){folders.push(file);}else{file.name=keyFolders[keyFolders.length-1];files.push(file);}}// Sort files based on directionif(direction===SortDirection.ASCENDING){files=files.sort(compareAsc);}else{files=files.sort(compareDesc);}for(letfolderIndex=0;folderIndex<folders.length;folderIndex++){constfolder=folders[folderIndex];folder.children=sortByLastModified(folder.children,direction);}letsortedFiles=[];sortedFiles=sortedFiles.concat(folders);sortedFiles=sortedFiles.concat(files);returnsortedFiles;}export{sortByLastModified,SortDirection};
The text was updated successfully, but these errors were encountered:
I'm looking for a way to specify the sort direction when sorting by name/modified. Can we do something like this?
Typescript equivalent:
The text was updated successfully, but these errors were encountered: