Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Github's sort order #201

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions src/js/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,6 @@ export const createRootElement = () => {
return element
}

const sorter = (a, b) => {
const isFileA = Boolean(a.href)
const isFileB = Boolean(b.href)
if (isFileA === isFileB) {
return (b.nodeLabel > a.nodeLabel) ? -1 : ((a.nodeLabel > b.nodeLabel) ? 1 : 0)
} else if (isFileA && !isFileB) {
return 1
} else {
return -1
}
}

const parseChangeNumber = (n) => {
if (!n.replace) return 0
const number = parseInt(n.replace(',', ''), 10)
Expand Down Expand Up @@ -115,9 +103,9 @@ export const folderConcat = (node) => {

export const createFileTree = (filter = EMPTY_FILTER) => {
const fileInfo = [...document.querySelectorAll('.file-info > a')]
const files = fileInfo.map(({ title, href }) => {
const files = fileInfo.map(({ title, href }, idx) => {
title = getCurrentFileLocation(title)
return { title, href, parts: title.split('/') }
return { title, href, parts: title.split('/'), idx }
})
const count = fileInfo.filter(({ href }) => href && href.includes('#diff')).length
const tree = {
Expand All @@ -126,7 +114,7 @@ export const createFileTree = (filter = EMPTY_FILTER) => {
diffElements: []
}

files.forEach(({ parts, href }) => {
files.forEach(({ parts, href, idx }) => {
let location = tree
if (filterItem(parts[parts.length - 1], filter)) {
parts.forEach((part, index) => {
Expand All @@ -140,6 +128,7 @@ export const createFileTree = (filter = EMPTY_FILTER) => {
const isDeleted = isDeletedForFileId(fileId)
tree.diffElements.push(diffElement)
node = {
idx,
nodeLabel: part,
list: [],
href: (index === parts.length - 1) ? href : null,
Expand All @@ -151,7 +140,7 @@ export const createFileTree = (filter = EMPTY_FILTER) => {
location.list.push(node)
}
}
location.list = location.list.sort(sorter)
location.list = location.list.sort((a, b) => a.idx - b.idx)
location = node
})
}
Expand Down