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