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

Commit e9395e8

Browse files
Adding functionality to refresh user repository list
1 parent 00da02c commit e9395e8

File tree

6 files changed

+45
-24
lines changed

6 files changed

+45
-24
lines changed

src/GitHub.App/SampleData/Dialog/Clone/SelectPageViewModelDesigner.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
using System.Collections.Generic;
33
using System.ComponentModel;
44
using System.Linq;
5+
using System.Reactive;
56
using System.Threading.Tasks;
67
using System.Windows.Data;
78
using GitHub.Models;
89
using GitHub.ViewModels;
910
using GitHub.ViewModels.Dialog.Clone;
11+
using ReactiveUI;
1012

1113
namespace GitHub.SampleData.Dialog.Clone
1214
{
@@ -39,6 +41,7 @@ public SelectPageViewModelDesigner()
3941
public ICollectionView ItemsView { get; }
4042
public IRepositoryItemViewModel SelectedItem { get; set; }
4143
public RepositoryModel Repository { get; }
44+
public ReactiveCommand<Unit, Unit> Refresh { get; }
4245

4346
public void Initialize(IConnection connection)
4447
{

src/GitHub.App/Services/RepositoryCloneService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public RepositoryCloneService(
6464
}
6565

6666
/// <inheritdoc/>
67-
public async Task<ViewerRepositoriesModel> ReadViewerRepositories(HostAddress address)
67+
public async Task<ViewerRepositoriesModel> ReadViewerRepositories(HostAddress address, bool refresh = false)
6868
{
6969
if (readViewerRepositories == null)
7070
{
@@ -107,7 +107,7 @@ public async Task<ViewerRepositoriesModel> ReadViewerRepositories(HostAddress ad
107107
}
108108

109109
var graphql = await graphqlFactory.CreateConnection(address).ConfigureAwait(false);
110-
var result = await graphql.Run(readViewerRepositories).ConfigureAwait(false);
110+
var result = await graphql.Run(readViewerRepositories, cacheDuration: TimeSpan.FromHours(1), refresh: refresh).ConfigureAwait(false);
111111
return result;
112112
}
113113

src/GitHub.App/ViewModels/Dialog/Clone/RepositorySelectViewModel.cs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.ComponentModel.Composition;
55
using System.Globalization;
66
using System.Linq;
7+
using System.Reactive;
78
using System.Reactive.Linq;
89
using System.Threading.Tasks;
910
using System.Windows.Data;
@@ -30,7 +31,6 @@ public class RepositorySelectViewModel : ViewModelBase, IRepositorySelectViewMod
3031
string filter;
3132
bool isEnabled;
3233
bool isLoading;
33-
bool loadingStarted;
3434
IReadOnlyList<IRepositoryItemViewModel> items;
3535
ICollectionView itemsView;
3636
ObservableAsPropertyHelper<RepositoryModel> repository;
@@ -57,6 +57,12 @@ public RepositorySelectViewModel(IRepositoryCloneService service, IGitHubContext
5757
.ToProperty(this, x => x.Repository);
5858

5959
this.WhenAnyValue(x => x.Filter).Subscribe(_ => ItemsView?.Refresh());
60+
61+
Refresh = ReactiveCommand.CreateFromTask(async () =>
62+
{
63+
await this.LoadItems(true);
64+
return Unit.Default;
65+
});
6066
}
6167

6268
public Exception Error
@@ -101,6 +107,8 @@ public IRepositoryItemViewModel SelectedItem
101107
set => this.RaiseAndSetIfChanged(ref selectedItem, value);
102108
}
103109

110+
public ReactiveCommand<Unit, Unit> Refresh { get; }
111+
104112
public RepositoryModel Repository => repository.Value;
105113

106114
public void Initialize(IConnection connection)
@@ -111,18 +119,36 @@ public void Initialize(IConnection connection)
111119
IsEnabled = true;
112120
}
113121

114-
public async Task Activate()
122+
public async Task Activate() => this.LoadItems(false);
123+
124+
static string GroupName(KeyValuePair<string, IReadOnlyList<RepositoryListItemModel>> group, int max)
125+
{
126+
var name = group.Key;
127+
if (group.Value.Count == max)
128+
{
129+
name += $" ({string.Format(CultureInfo.InvariantCulture, Resources.MostRecentlyPushed, max)})";
130+
}
131+
132+
return name;
133+
}
134+
135+
async Task LoadItems(bool refresh)
115136
{
116-
if (connection == null || loadingStarted) return;
137+
if (connection == null && !IsLoading) return;
117138

118139
Error = null;
119140
IsLoading = true;
120-
loadingStarted = true;
121141

122142
try
123143
{
144+
if (refresh)
145+
{
146+
Items = new List<IRepositoryItemViewModel>();
147+
ItemsView = CollectionViewSource.GetDefaultView(Items);
148+
}
149+
124150
var results = await log.TimeAsync(nameof(service.ReadViewerRepositories),
125-
() => service.ReadViewerRepositories(connection.HostAddress));
151+
() => service.ReadViewerRepositories(connection.HostAddress, refresh));
126152

127153
var yourRepositories = results.Repositories
128154
.Where(r => r.Owner == results.Owner)
@@ -163,17 +189,6 @@ public async Task Activate()
163189
}
164190
}
165191

166-
static string GroupName(KeyValuePair<string, IReadOnlyList<RepositoryListItemModel>> group, int max)
167-
{
168-
var name = group.Key;
169-
if (group.Value.Count == max)
170-
{
171-
name += $" ({string.Format(CultureInfo.InvariantCulture, Resources.MostRecentlyPushed, max)})";
172-
}
173-
174-
return name;
175-
}
176-
177192
bool FilterItem(object obj)
178193
{
179194
if (obj is IRepositoryItemViewModel item && !string.IsNullOrWhiteSpace(Filter))

src/GitHub.Exports.Reactive/Services/IRepositoryCloneService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ Task CloneOrOpenRepository(
6767
/// </returns>
6868
bool DestinationFileExists(string path);
6969

70-
Task<ViewerRepositoriesModel> ReadViewerRepositories(HostAddress address);
70+
Task<ViewerRepositoriesModel> ReadViewerRepositories(HostAddress address, bool refresh = false);
7171
}
7272
}

src/GitHub.Exports.Reactive/ViewModels/Dialog/Clone/IRepositorySelectViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
4+
using System.Reactive;
45
using System.Threading.Tasks;
56
using GitHub.Models;
7+
using ReactiveUI;
68

79
namespace GitHub.ViewModels.Dialog.Clone
810
{
@@ -14,6 +16,7 @@ public interface IRepositorySelectViewModel : IRepositoryCloneTabViewModel
1416
IReadOnlyList<IRepositoryItemViewModel> Items { get; }
1517
ICollectionView ItemsView { get; }
1618
IRepositoryItemViewModel SelectedItem { get; set; }
19+
ReactiveCommand<Unit, Unit> Refresh { get; }
1720

1821
void Initialize(IConnection connection);
1922
}

src/GitHub.VisualStudio.UI/Views/Dialog/Clone/SelectPageView.xaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
</UserControl.Resources>
2222

2323
<DockPanel>
24-
<ghfvs:PromptTextBox DockPanel.Dock="Top"
25-
Margin="0,4"
26-
PromptText="Search or enter a URL"
27-
Text="{Binding Filter, UpdateSourceTrigger=PropertyChanged, Delay=300}"/>
28-
24+
<DockPanel DockPanel.Dock="Top" Margin="0,4">
25+
<Button DockPanel.Dock="Right" Command="{Binding Refresh}">Refresh</Button>
26+
<ghfvs:PromptTextBox PromptText="Search or enter a URL"
27+
Text="{Binding Filter, UpdateSourceTrigger=PropertyChanged, Delay=300}"/>
28+
</DockPanel>
2929
<Grid>
3030
<ListView BorderThickness="0"
3131
ItemsSource="{Binding ItemsView}"

0 commit comments

Comments
 (0)