Skip to content

Commit

Permalink
Merge pull request #406 from powerhouse-inc/319-organise-files-by-def…
Browse files Browse the repository at this point in the history
…ault-alphabetically-within-in-a-folder

feat: sort folders and files alphabetically
  • Loading branch information
gpuente authored Jul 4, 2024
2 parents f396a23 + 74aa081 commit b7c4d21
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/folder-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useFileOptions } from 'src/hooks/useFileOptions';
import { useFolderContent } from 'src/hooks/useFolderContent';
import { useFolderOptions } from 'src/hooks/useFolderOptions';
import { useOnDropEvent } from 'src/hooks/useOnDropEvent';
import { sortTreeItemsByLabel } from 'src/utils';
import { twMerge } from 'tailwind-merge';
import { ContentSection } from './content';
import FileContentView from './file-content-view';
Expand Down Expand Up @@ -86,7 +87,7 @@ export const FolderView: React.FC<IProps> = ({
)}
>
<FileContentView
files={files}
files={files.sort(sortTreeItemsByLabel)}
onFileDeleted={onFileDeleted}
decodedDriveID={decodedDriveID}
onFileSelected={onFileSelected}
Expand Down
8 changes: 6 additions & 2 deletions src/hooks/useDrivesContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import path from 'path';
import { useTranslation } from 'react-i18next';
import { useModal } from 'src/components/modal';
import { getLastIndexFromPath } from 'src/utils';
import { getLastIndexFromPath, sortTreeItemsByLabel } from 'src/utils';
import { v4 as uuid } from 'uuid';
import { useDocumentDriveServer } from './useDocumentDriveServer';
import { useNavigateToItemId } from './useNavigateToItemId';
Expand Down Expand Up @@ -337,7 +337,11 @@ export function useDrivesContainer() {
};
});

return [driveNode, ...fileItems, ...folderItems];
return [
driveNode,
...fileItems,
...folderItems.sort(sortTreeItemsByLabel),
];
}

return {
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './document-model';
export * from './file';
export * from './path';
export * from './tree-items';
4 changes: 4 additions & 0 deletions src/utils/tree-items.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { TreeItem } from '@powerhousedao/design-system';

export const sortTreeItemsByLabel = (a: TreeItem, b: TreeItem) =>
a.label.localeCompare(b.label);

0 comments on commit b7c4d21

Please sign in to comment.