Make branch listing sort more stable

This commit is contained in:
Caleb Owens 2024-08-07 11:18:49 +02:00
parent 565c5c218f
commit d8d44f8c56
2 changed files with 11 additions and 1 deletions

View File

@ -6,6 +6,7 @@
import BranchListingSidebarEntry from '$lib/navigation/BranchListingSidebarEntry.svelte'; import BranchListingSidebarEntry from '$lib/navigation/BranchListingSidebarEntry.svelte';
import PullRequestSidebarEntry from '$lib/navigation/PullRequestSidebarEntry.svelte'; import PullRequestSidebarEntry from '$lib/navigation/PullRequestSidebarEntry.svelte';
import { import {
getEntryName,
getEntryUpdatedDate, getEntryUpdatedDate,
getEntryWorkspaceStatus, getEntryWorkspaceStatus,
type SidebarEntrySubject type SidebarEntrySubject
@ -49,7 +50,12 @@
); );
output.sort((a, b) => { output.sort((a, b) => {
return getEntryUpdatedDate(b).getTime() - getEntryUpdatedDate(a).getTime(); const timeDifference = getEntryUpdatedDate(b).getTime() - getEntryUpdatedDate(a).getTime();
if (timeDifference !== 0) {
return timeDifference;
}
return getEntryName(a).localeCompare(getEntryName(b));
}); });
sidebarEntries = output; sidebarEntries = output;

View File

@ -15,6 +15,10 @@ export function getEntryUpdatedDate(entry: SidebarEntrySubject) {
return entry.type === 'branchListing' ? entry.subject.updatedAt : entry.subject.modifiedAt; return entry.type === 'branchListing' ? entry.subject.updatedAt : entry.subject.modifiedAt;
} }
export function getEntryName(entry: SidebarEntrySubject) {
return entry.type === 'branchListing' ? entry.subject.name : entry.subject.title;
}
export function getEntryWorkspaceStatus(entry: SidebarEntrySubject) { export function getEntryWorkspaceStatus(entry: SidebarEntrySubject) {
return entry.type === 'branchListing' ? entry.subject.virtualBranch?.inWorkspace : undefined; return entry.type === 'branchListing' ? entry.subject.virtualBranch?.inWorkspace : undefined;
} }