Permalink
Browse files

Rewrite repo selection screen

Build the correct code to fetch the data we need to build the repo
selection screen - this is tricky because of the disparity between orgs
and users, even though they're both "a thing that can have repos"

This
commit also makes data stream as it comes in, instead of waiting until
everything shows up.
  • Loading branch information...
1 parent ac28d97 commit 4ff8bc6ced6d3443bd55dbbb468c532d688a711b @paulcbetts committed Apr 4, 2012
@@ -32,19 +32,17 @@ public void RepoSelectionIntegrationSmokeTest()
(new TestScheduler()).With(sched => {
var fixture = mock.Get<IRepoSelectionViewModel>();
- ReactiveCollection<OrganizationTileViewModel> repos = null;
- fixture.ObservableForProperty(x => x.Organizations).Subscribe(x => repos = x.Value);
sched.Start();
- foreach(var v in repos) {
+ foreach(var v in fixture.Organizations) {
v.Model.Should().NotBeNull();
this.Log().Info(v.Model.login);
v.Repositories.Count.Should().BeGreaterThan(0);
}
- repos.Count.Should().BeGreaterThan(0);
+ fixture.Organizations.Count.Should().BeGreaterThan(0);
});
}
}
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Reactive;
using System.Reactive.Linq;
+using System.Reactive.Subjects;
using System.Windows.Media;
using Ninject;
using ReactiveUI.Routing;
@@ -38,37 +40,48 @@ public OrganizationTileViewModel(GitHubOrgInfo model, IObservable<List<GitHubRep
public interface IRepoSelectionViewModel : IRoutableViewModel
{
ReactiveCollection<OrganizationTileViewModel> Organizations { get; }
+ IObservable<Unit> FinishedLoading { get; }
}
public class RepoSelectionViewModel : ReactiveObject, IRepoSelectionViewModel
{
- ObservableAsPropertyHelper<ReactiveCollection<OrganizationTileViewModel>> _Organizations;
- public ReactiveCollection<OrganizationTileViewModel> Organizations {
- get { return _Organizations.Value; }
- }
-
public string UrlPathSegment {
get { return "repos"; }
}
public IScreen HostScreen { get; protected set; }
+ public IObservable<Unit> FinishedLoading { get; protected set; }
+
+ public ReactiveCollection<OrganizationTileViewModel> Organizations { get; protected set; }
+
[Inject]
public RepoSelectionViewModel(IScreen hostScreen, IGitHubApi api)
{
HostScreen = hostScreen;
- var repos = api.GetReposForUser();
+ var orgs = api.GetOrganizationsForUser();
+ var userInfo = getUserAsOrgInfo(api);
+
+ var repoTable = orgs.SelectMany(x => x.ToObservable())
+ .Select(x => new { Key = x, Value = api.GetReposFromOrganization(x) })
+ .Concat(userInfo.Select(x => new { Key = x, Value = api.GetReposForUser() }));
- api.GetOrganizationsForUser()
- .Select(x => createOrgViewModels(x, repos))
- .ToProperty(this, x => x.Organizations);
+ Organizations = repoTable.Select(x => new OrganizationTileViewModel(x.Key, x.Value)).CreateCollection();
+
+ FinishedLoading = repoTable.Aggregate(Unit.Default, (acc, x) => Unit.Default);
}
ReactiveCollection<OrganizationTileViewModel> createOrgViewModels(IEnumerable<GitHubOrgInfo> gitHubOrgInfos, IObservable<List<GitHubRepo>> repos)
{
return new ReactiveCollection<OrganizationTileViewModel>(
gitHubOrgInfos.Select(x => new OrganizationTileViewModel(x, repos)));
}
+
+ IObservable<GitHubOrgInfo> getUserAsOrgInfo(IGitHubApi api)
+ {
+ return api.GetCurrentUser()
+ .Select( x => new GitHubOrgInfo() {login = x.login, avatar_url = x.avatar_url, url = x.url});
+ }
}
}

0 comments on commit 4ff8bc6

Please sign in to comment.