Skip to content

Commit 55606bb

Browse files
committed
torrent file list alphabetical sort
1 parent 00d6eaf commit 55606bb

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

client/pages/torrent/[infoHash].js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ export const Info = ({ title, items }) => (
8080
const WrapExpandable = ({ wrap, children }) =>
8181
wrap ? <details>{children}</details> : children;
8282

83+
const sortName = (a, b) => {
84+
if (a.name > b.name) return 1;
85+
if (a.name < b.name) return -1;
86+
return 0;
87+
};
88+
8389
const FileItem = ({ file, depth = 0 }) => {
8490
return (
8591
<Box as="li" pl={`${depth * 22}px`} css={{ lineHeight: 1.75 }}>
@@ -112,7 +118,7 @@ const FileItem = ({ file, depth = 0 }) => {
112118
</Box>
113119
{!!file.children.length && (
114120
<Box as="ul" pl={0} css={{ listStyle: "none" }}>
115-
{file.children.map((child) => (
121+
{file.children.sort(sortName).map((child) => (
116122
<FileItem
117123
key={`file-${child.name}-${depth}`}
118124
file={child}
@@ -676,7 +682,7 @@ const Torrent = ({ token, torrent = {}, userId, userRole, uid }) => {
676682
Files
677683
</Text>
678684
<Box as="ul" pl={0} css={{ listStyle: "none" }}>
679-
{parsedFiles.map((file, i) => (
685+
{parsedFiles.sort(sortName).map((file, i) => (
680686
<FileItem key={`file-${i}`} file={file} />
681687
))}
682688
</Box>

0 commit comments

Comments
 (0)