Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 08b5d74

Browse files
committed
Add ordering and filtering and things to the repo list
1 parent d8e51fe commit 08b5d74

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

src/GitHub.App/Services/ModelService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ public IObservable<AccountCacheItem> GetUserFromCache()
134134
return Observable.Defer(() => hostCache.GetObject<AccountCacheItem>("user"));
135135
}
136136

137+
/// <summary>
138+
/// Gets a collection of Pull Requests. If you want to refresh existing data, pass a collection in
139+
/// </summary>
140+
/// <param name="repo"></param>
141+
/// <param name="collection"></param>
142+
/// <returns></returns>
137143
public ITrackingCollection<IPullRequestModel> GetPullRequests(ISimpleRepositoryModel repo,
138144
ITrackingCollection<IPullRequestModel> collection)
139145
{
@@ -360,7 +366,7 @@ public RepositoryCacheItem(Repository apiRepository)
360366
CloneUrl = apiRepository.CloneUrl;
361367
Private = apiRepository.Private;
362368
Fork = apiRepository.Fork;
363-
Key = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", Owner, Name);
369+
Key = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", Owner.Login, Name);
364370
CreatedAt = apiRepository.CreatedAt;
365371
UpdatedAt = apiRepository.UpdatedAt;
366372
Timestamp = apiRepository.UpdatedAt;

src/GitHub.App/ViewModels/RepositoryCloneViewModel.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using Rothko;
2222
using System.Collections.ObjectModel;
2323
using GitHub.Collections;
24+
using GitHub.UI;
2425

2526
namespace GitHub.ViewModels
2627
{
@@ -64,21 +65,23 @@ public RepositoryCloneViewModel(
6465
this.usageTracker = usageTracker;
6566

6667
Title = string.Format(CultureInfo.CurrentCulture, Resources.CloneTitle, repositoryHost.Title);
68+
IsLoading = true;
6769

68-
var col = new TrackingCollection<IRepositoryModel>(filter: FilterRepository);
69-
col = repositoryHost.ModelService.GetRepositories(col) as TrackingCollection<IRepositoryModel>;
70-
col.OriginalCompleted.Subscribe(
71-
_ => {}
70+
Repositories = new TrackingCollection<IRepositoryModel>();
71+
repositories.ProcessingDelay = TimeSpan.Zero;
72+
repositories.Comparer = OrderedComparer<IRepositoryModel>.OrderBy(x => x.Owner).ThenBy(x => x.Name).Compare;
73+
repositories.Filter = FilterRepository;
74+
repositories.NewerComparer = OrderedComparer<IRepositoryModel>.OrderByDescending(x => x.UpdatedAt).Compare;
75+
76+
repositories.OriginalCompleted.Subscribe(
77+
_ => { }
7278
, ex =>
73-
{
74-
LoadingFailed = true;
75-
log.Error("Error while loading repositories", ex);
76-
},
79+
{
80+
LoadingFailed = true;
81+
log.Error("Error while loading repositories", ex);
82+
},
7783
() => IsLoading = false
7884
);
79-
col.Subscribe(_ => IsLoading = true, () => {});
80-
81-
Repositories = col;
8285

8386
filterTextIsEnabled = this.WhenAny(x => x.Repositories.Count, x => x.Value > 0)
8487
.ToProperty(this, x => x.FilterTextIsEnabled);
@@ -90,7 +93,7 @@ public RepositoryCloneViewModel(
9093
this.WhenAny(x => x.FilterText, x => x.Value)
9194
.DistinctUntilChanged(StringComparer.OrdinalIgnoreCase)
9295
.Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler)
93-
.Subscribe(_ => col.Filter = FilterRepository);
96+
.Subscribe(_ => repositories.Filter = FilterRepository);
9497

9598
var baseRepositoryPath = this.WhenAny(
9699
x => x.BaseRepositoryPath,
@@ -214,14 +217,14 @@ public string BaseRepositoryPath
214217
/// </summary>
215218
public IReactiveCommand<Unit> CloneCommand { get; private set; }
216219

217-
ObservableCollection<IRepositoryModel> repositories;
220+
TrackingCollection<IRepositoryModel> repositories;
218221
/// <summary>
219222
/// List of repositories as returned by the server
220223
/// </summary>
221224
public ObservableCollection<IRepositoryModel> Repositories
222225
{
223226
get { return repositories; }
224-
private set { this.RaiseAndSetIfChanged(ref repositories, value); }
227+
private set { repositories = value as TrackingCollection<IRepositoryModel>; this.RaisePropertyChanged(); }
225228
}
226229

227230
IRepositoryModel selectedRepository;

src/GitHub.VisualStudio/UI/Views/Controls/RepositoryCloneControl.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
Margin="10"
150150
DockPanel.Dock="Top"
151151
PromptText="{x:Static prop:Resources.filterTextPromptText}"
152-
Text="{Binding FilterText}"
152+
Text="{Binding FilterText, UpdateSourceTrigger=PropertyChanged}"
153153
IsEnabled="{Binding FilterTextIsEnabled, Mode=OneWay}"/>
154154

155155
<ui:GitHubProgressBar x:Name="loadingProgressBar"

0 commit comments

Comments
 (0)