Better Loading Interactions · CodeHubApp/CodeHub@9c2cd6c · GitHub
Skip to content
This repository was archived by the owner on Jul 2, 2022. It is now read-only.

Commit 9c2cd6c

Browse files
committed
Better Loading Interactions
1 parent 5562ab7 commit 9c2cd6c

10 files changed

Lines changed: 59 additions & 17 deletions

File tree

‎CodeHub.Core/Interactions.cs‎

Lines changed: 16 additions & 5 deletions

‎CodeHub.Core/Utils/OctokitClientFactory.cs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ public static class OctokitClientFactory
1313
public static readonly string[] Scopes = { "user", "repo", "gist", "notifications" };
1414
public static readonly ProductHeaderValue UserAgent = new ProductHeaderValue("CodeHub");
1515

16-
public static GitHubClient Create(Uri domain, Credentials credentials)
16+
public static GitHubClient Create(
17+
Uri domain,
18+
Credentials credentials,
19+
TimeSpan? requestTimeout = null)
1720
{
1821
var networkActivityService = Locator.Current.GetService<INetworkActivityService>();
1922
var client = new HttpClientAdapter(CreateMessageHandler);
@@ -25,7 +28,10 @@ public static GitHubClient Create(Uri domain, Credentials credentials)
2528
new InMemoryCredentialStore(credentials),
2629
httpClient,
2730
new SimpleJsonSerializer());
28-
return new GitHubClient(connection);
31+
32+
var gitHubClient = new GitHubClient(connection);
33+
gitHubClient.SetRequestTimeout(requestTimeout ?? TimeSpan.FromSeconds(20));
34+
return gitHubClient;
2935
}
3036
}
3137
}

‎CodeHub.Core/ViewModels/App/FeedbackComposerViewModel.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public FeedbackComposerViewModel(
7979

8080
SubmitCommand
8181
.ThrownExceptions
82-
.Select(x => new UserError("There was a problem trying to post your feedback: " + x.Message))
82+
.Select(ex => new UserError("There was a problem trying to post your feedback.", ex))
8383
.SelectMany(Interactions.Errors.Handle)
8484
.Subscribe();
8585

‎CodeHub.iOS/ViewControllers/Application/FeedbackViewController.cs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace CodeHub.iOS.ViewControllers.Application
1515
public class FeedbackViewController : TableViewController
1616
{
1717
private readonly UISearchBar _repositorySearchBar = new UISearchBar(new CGRect(0, 0, 320, 44));
18-
private readonly LoadingIndicatorView _loading = new LoadingIndicatorView();
1918

2019
private readonly Lazy<UIView> _emptyView = new Lazy<UIView>((() =>
2120
new EmptyListView(Octicon.IssueOpened.ToEmptyListImage(), "There are no open issues.")));

‎CodeHub.iOS/ViewControllers/PullRequests/PullRequestDiffViewController.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public PullRequestDiffViewController(
6161

6262
loadComments
6363
.ThrownExceptions
64-
.Select(error => new UserError("Unable to load comments: " + error.Message))
64+
.Select(error => new UserError("Unable to load comments.", error))
6565
.SelectMany(Interactions.Errors.Handle)
6666
.Subscribe();
6767

‎CodeHub.iOS/ViewControllers/Source/BranchesViewController.cs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using CodeHub.Core;
1111
using System.Linq;
1212
using System.Reactive;
13+
using CodeHub.iOS.Views;
1314

1415
namespace CodeHub.iOS.ViewControllers.Source
1516
{
@@ -32,15 +33,19 @@ public BranchesViewController(
3233

3334
loadBranches
3435
.ThrownExceptions
35-
.Select(error => new UserError("Unable to load branches: " + error.Message))
36+
.Do(_ => TableView.TableFooterView = new UIView())
37+
.Select(error => new UserError("Unable to load branches.", error))
3638
.SelectMany(Interactions.Errors.Handle)
3739
.Subscribe();
3840

39-
loadBranches.Subscribe(ItemsLoaded);
41+
loadBranches
42+
.Do(_ => TableView.TableFooterView = null)
43+
.Subscribe(ItemsLoaded);
4044

4145
Appearing
4246
.Take(1)
4347
.Select(_ => Unit.Default)
48+
.Do(_ => TableView.TableFooterView = new LoadingIndicatorView())
4449
.InvokeReactiveCommand(loadBranches);
4550
}
4651

‎CodeHub.iOS/ViewControllers/Source/CommitDiffViewController.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public CommitDiffViewController(
5858

5959
loadComments
6060
.ThrownExceptions
61-
.Select(error => new UserError("Unable to load comments: " + error.Message))
61+
.Select(error => new UserError("Unable to load comments.", error))
6262
.SelectMany(Interactions.Errors.Handle)
6363
.Subscribe();
6464

‎CodeHub.iOS/ViewControllers/Source/FileSourceViewController.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public FileSourceViewController(
122122
private UserError HandleLoadError(Exception error)
123123
{
124124
LoadContent("");
125-
return new UserError("Unable to load selected file.");
125+
return new UserError("Unable to load selected file.", error);
126126
}
127127

128128
private async Task Load(CancellationToken cancelToken)

‎CodeHub.iOS/ViewControllers/Source/SourceTreeViewController.cs‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public SourceTreeViewController(
5959

6060
loadContents
6161
.ThrownExceptions
62+
.Do(_ => TableView.TableFooterView = new UIView())
6263
.Select(HandleLoadError)
6364
.SelectMany(Interactions.Errors.Handle)
6465
.Subscribe();
@@ -74,14 +75,29 @@ public SourceTreeViewController(
7475
.Select(_ => _sha)
7576
.Where(x => !string.IsNullOrEmpty(x))
7677
.DistinctUntilChanged()
78+
.Do(_ => SetLoading(true))
7779
.InvokeReactiveCommand(loadContents);
7880

7981
loadContents
82+
.Do(_ => SetLoading(false))
8083
.Subscribe(SetElements);
8184

8285
NavigationItem.TitleView = _titleView;
8386
}
8487

88+
private void SetLoading(bool isLoading)
89+
{
90+
if (isLoading)
91+
{
92+
Root.Reset();
93+
TableView.TableFooterView = new LoadingIndicatorView();
94+
}
95+
else
96+
{
97+
TableView.TableFooterView = null;
98+
}
99+
}
100+
85101
private UserError HandleLoadError(Exception error)
86102
{
87103
Root.Reset();
@@ -90,7 +106,7 @@ private UserError HandleLoadError(Exception error)
90106
if (apiException?.StatusCode == System.Net.HttpStatusCode.NotFound)
91107
return new UserError($"The current directory does not exist under the selected Git reference ({_sha})");
92108

93-
return new UserError("Unable to load source tree: " + error.Message);
109+
return new UserError("Unable to load source tree.", error);
94110
}
95111

96112
public override void ViewWillAppear(bool animated)

‎CodeHub.iOS/ViewControllers/Source/TagsViewController.cs‎

Lines changed: 7 additions & 2 deletions

0 commit comments

Comments
 (0)