From 5966641b751fefa7f837659977833e21c73ef5eb Mon Sep 17 00:00:00 2001 From: Robert Marshall Date: Sat, 5 Jul 2025 21:24:30 +0100 Subject: [PATCH] Get branch details and sort by modification date --- .../ProjectNavigationViewComponent.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Website/ViewComponents/ProjectNavigationViewComponent.cs b/src/Website/ViewComponents/ProjectNavigationViewComponent.cs index 4e6b304..ffc5aaa 100644 --- a/src/Website/ViewComponents/ProjectNavigationViewComponent.cs +++ b/src/Website/ViewComponents/ProjectNavigationViewComponent.cs @@ -5,15 +5,22 @@ using Website.Data; namespace Website.ViewComponents { public class ProjectNavigationViewComponent :ViewComponent { - private readonly IGitApi _api; + private readonly IGitApi _gitApi; - public ProjectNavigationViewComponent(IGitApi api) { - _api = api; + public ProjectNavigationViewComponent(IGitApi gitApi) { + _gitApi = gitApi; } public async Task InvokeAsync() { - var repositories = await _api.GetRepositories("rob"); - return View(repositories.Take(5)); + var repos = await _gitApi.GetRepositories("rob"); + + var branchTasks = repos.Select(repo => _gitApi.GetBranches("rob", repo)); + var branchResults = await Task.WhenAll(branchTasks); + var branches = branchResults.SelectMany(branch => branch); + var sortedBranches = branches.OrderByDescending(branch => branch.Commit.Timestamp); + var sortedRepos = sortedBranches.DistinctBy(branch => branch.Repository).Select(branch => branch.Repository); + + return View(sortedRepos.Take(5)); } } } \ No newline at end of file