Fix sorting bug on branch dropdowns

b94151f231fe435f307badf8c5cfc488595c2681

Tucker McKnight <tucker@pangolin.lan> | Wed Dec 31 2025

Fix sorting bug on branch dropdowns

Sort order wasn't being respected when tying in the
search box.

Also make it sort by date in reverse order -- that is, newest
(largest date number) on top.
frontend/main.js:107
Before
106
107
108
109
110
111
  let branches = window.branchesWithHrefs.filter((branch) => {
    return branch.name.includes(searchTerm)
  })
  dropdownBranchesResults.innerHTML = branchesListItems(branches, window.defaultBranch, window.currentBranch)
})

let sortDirection = document.querySelector("[name=branchSort]:checked")?.value || 'date'
After
106
107
108
109
110
111
  let branches = window.branchesWithHrefs.filter((branch) => {
    return branch.name.includes(searchTerm)
  })
  dropdownBranchesResults.innerHTML = branchesListItems(branches, window.defaultBranch, window.currentBranch, sortDirection)
})

let sortDirection = document.querySelector("[name=branchSort]:checked")?.value || 'date'
js_templates/common/branchesListItems.ts:5
Before
4
5
6

7
8



9
10
11
  sortBy: 'name' | 'date',
): string => {
  return branches.toSorted((a, b) => {
⁣
    if (a[sortBy] < b[sortBy]) { return -1 }
    if (a[sortBy] > b[sortBy]) { return 1 }
⁣
⁣
⁣
    return 0
  }).map((branch) => {
    const currentBadge = currentBranch === branch.name
      ? '<div class="badge rounded-pill bg-secondary mx-1">current</div>'
After
4
5
6
7
8
9
10
11
12
13
14
15
  sortBy: 'name' | 'date',
): string => {
  return branches.toSorted((a, b) => {
    let comparison = 0
    if (a[sortBy] < b[sortBy]) { comparison = -1 }
    if (a[sortBy] > b[sortBy]) { comparison = 1 }
    // we want reverse order if sorting by date (making newest first)
    if (sortBy === 'date') { comparison = comparison * -1 }

    return comparison
  }).map((branch) => {
    const currentBadge = currentBranch === branch.name
      ? '<div class="badge rounded-pill bg-secondary mx-1">current</div>'