From 0cab371c4738d76ba41393238763b1e3de2cf801 Mon Sep 17 00:00:00 2001 From: Mattias Granlund Date: Mon, 10 Jul 2023 17:20:24 +0200 Subject: [PATCH] Sort branches, files, and hunks on load --- src/lib/vbranches/ipc.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib/vbranches/ipc.ts b/src/lib/vbranches/ipc.ts index 69d4ca0ad..7180d83d7 100644 --- a/src/lib/vbranches/ipc.ts +++ b/src/lib/vbranches/ipc.ts @@ -4,7 +4,7 @@ import { Branch, BranchData, Target } from './types'; export async function listVirtualBranches(params: { projectId: string }): Promise { const result = await invoke('list_virtual_branches', params); - return plainToInstance(Branch, result); + return sortBranches(plainToInstance(Branch, result)); } export async function create(params: { @@ -74,3 +74,16 @@ export async function createvBranchFromBranch(params: { projectId: string; branc export async function fetchFromTarget(params: { projectId: string }) { return invoke('fetch_from_target', params); } + +function sortBranches(branches: Branch[]): Branch[] { + branches.sort((a, b) => a.order - b.order); + branches.forEach((branch) => { + const files = branch.files; + files.sort((a, b) => b.modifiedAt.getTime() - a.modifiedAt.getTime()); + files.forEach((file) => { + const hunks = file.hunks; + hunks.sort((a, b) => b.modifiedAt.getTime() - a.modifiedAt.getTime()); + }); + }); + return branches; +}