Skip to content

Commit

Permalink
added alphabetical ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasgauvin committed May 26, 2024
1 parent 889bd8d commit 75fcc5c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/models/DirectoryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class DirectoryNode {
this.blobUrl = blobUrl;
this.replacedImages = replacedImages || {};
this.frontmatter = frontmatter || null;

this.sortChildrenAlphabetically();
}

getId(): string {
Expand Down Expand Up @@ -89,6 +91,10 @@ class DirectoryNode {
}
}

sortChildrenAlphabetically() {
this.children.sort((a, b) => a.name.localeCompare(b.name));
}

async loadFileContent(): Promise<string | null> {
this.getFullPath();

Expand Down Expand Up @@ -226,6 +232,12 @@ class DirectoryNode {
return child;
}
});

this.parent.sortChildrenAlphabetically();


console.log("renamed file, updated children", this.parent.children);
console.log(this.parent.children);
}
}

Expand Down Expand Up @@ -279,6 +291,11 @@ class DirectoryNode {
return child;
}
});

this.parent.sortChildrenAlphabetically();

console.log("renamed file, updated children", this.parent.children);
console.log(this.parent.children)
}
}

Expand Down Expand Up @@ -556,6 +573,8 @@ class DirectoryNode {
//add the new file to the parent
this.children.push(newFileNode);

this.sortChildrenAlphabetically();

return newFileNode;
}

Expand Down Expand Up @@ -611,6 +630,8 @@ class DirectoryNode {
//add the new file to the parent
this.children.push(newFolderNode);

this.sortChildrenAlphabetically();

return newFolderNode;
}
}
Expand Down Expand Up @@ -717,6 +738,8 @@ export const createDirectoryNode = async (

directoryNode.children = entries;

directoryNode.sortChildrenAlphabetically();

return directoryNode;
};

Expand Down

0 comments on commit 75fcc5c

Please sign in to comment.