Skip to content

Commit 1cfeb16

Browse files
feat: adding loading icons to login
1 parent e4d6250 commit 1cfeb16

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/TwitchStreamingTools/ViewModels/Pages/AccountViewModel.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,21 @@ public class AccountViewModel : PageViewModelBase, IDisposable {
5656
/// </summary>
5757
private readonly ITwitchAccountService _twitchAccountService;
5858

59+
/// <summary>
60+
/// True if currently downloading the logged in user's profile photo, false otherwise.
61+
/// </summary>
62+
private bool _downloadingProfileImage;
63+
5964
/// <summary>
6065
/// True if we have a valid OAuth token, false otherwise.
6166
/// </summary>
6267
private bool _hasValidOAuthToken;
6368

69+
/// <summary>
70+
/// True if currently in the logging in process, false otherwise.
71+
/// </summary>
72+
private bool _loggingIn;
73+
6474
/// <summary>
6575
/// The profile image of the logged in user.
6676
/// </summary>
@@ -110,6 +120,22 @@ public Bitmap? ProfileImage {
110120
/// </summary>
111121
public ReactiveCommand<Unit, Unit> OnLogout { get; }
112122

123+
/// <summary>
124+
/// True if currently in the logging in process, false otherwise.
125+
/// </summary>
126+
public bool LoggingIn {
127+
get => _loggingIn;
128+
set => this.RaiseAndSetIfChanged(ref _loggingIn, value);
129+
}
130+
131+
/// <summary>
132+
/// True if currently downloading the logged in user's profile photo, false otherwise.
133+
/// </summary>
134+
public bool DownloadingProfileImage {
135+
get => _downloadingProfileImage;
136+
set => this.RaiseAndSetIfChanged(ref _downloadingProfileImage, value);
137+
}
138+
113139
/// <summary>
114140
/// True if we have a valid OAuth token, false otherwise.
115141
/// </summary>
@@ -157,18 +183,21 @@ public override async void OnLoaded() {
157183
private async Task LoadProfileImage() {
158184
// Try to get the file locally.
159185
string? profileImagePath = string.Format(PROFILE_IMAGE_FILENAME, _configuration.TwitchUsername);
186+
profileImagePath = Path.Combine(PROFILE_IMAGE_FOLDER, profileImagePath);
160187
if (File.Exists(profileImagePath)) {
161188
ProfileImage = new Bitmap(profileImagePath);
162189
return;
163190
}
164191

165192
// If we couldn't find the file, download it.
193+
DownloadingProfileImage = true;
166194
profileImagePath = await DownloadUserImage().ConfigureAwait(false);
167195
if (null == profileImagePath) {
168196
return;
169197
}
170198

171199
ProfileImage = new Bitmap(profileImagePath);
200+
DownloadingProfileImage = false;
172201
}
173202

174203
/// <summary>
@@ -213,6 +242,7 @@ private void OnCredentialsStatusChanged(bool valid) {
213242
/// Launches the computer's default browser to generate an OAuth token.
214243
/// </summary>
215244
private async void PerformLogin() {
245+
LoggingIn = true;
216246
try {
217247
CancellationToken token = CancellationToken.None;
218248

@@ -252,6 +282,9 @@ private async void PerformLogin() {
252282
catch (Exception ex) {
253283
_logger.Error("Failed to launch browser to login", ex);
254284
}
285+
finally {
286+
LoggingIn = false;
287+
}
255288
}
256289

257290
/// <summary>

src/TwitchStreamingTools/Views/Pages/AccountView.axaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:pages="clr-namespace:TwitchStreamingTools.ViewModels.Pages"
6+
xmlns:controls="clr-namespace:TwitchStreamingTools.Controls"
67
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
78
x:Class="TwitchStreamingTools.Views.Pages.AccountView"
89
x:DataType="pages:AccountViewModel">
@@ -24,16 +25,19 @@
2425
DockPanel.Dock="Top"
2526
Spacing="15">
2627
<Image Width="200" Source="/Assets/twitch-wordart.png" />
28+
<controls:Loading IsVisible="{Binding !LoggingIn}" Width="50" Height="50" />
2729
<Button IsVisible="{Binding !HasValidOAuthToken}"
30+
IsEnabled="{Binding !LoggingIn}"
2831
Command="{Binding OnPerformLogin}"
2932
HorizontalAlignment="Center"
3033
VerticalContentAlignment="Top">
3134
Login
3235
</Button>
33-
<Border CornerRadius="75" Width="150" ClipToBounds="True">
34-
<Image Source="{Binding ProfileImage}" />
35-
</Border>
3636
<StackPanel IsVisible="{Binding HasValidOAuthToken}" Spacing="5">
37+
<controls:Loading IsVisible="{Binding DownloadingProfileImage}" />
38+
<Border CornerRadius="75" Width="150" ClipToBounds="True" IsVisible="{Binding !DownloadingProfileImage}">
39+
<Image Source="{Binding ProfileImage}" />
40+
</Border>
3741
<Grid>
3842
<Grid.ColumnDefinitions>
3943
<ColumnDefinition Width="Auto" />

0 commit comments

Comments
 (0)