Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add global loading indicator to save actions, refactoring (#98)

Leendert de Borst4ef0373d3191
diff --git a/src/AliasVault.WebApp/Auth/Pages/Login.razor b/src/AliasVault.WebApp/Auth/Pages/Login.razor
index 71c84aab8..8a24c0c89 100644
--- a/src/AliasVault.WebApp/Auth/Pages/Login.razor
+++ b/src/AliasVault.WebApp/Auth/Pages/Login.razor
@@ -9,20 +9,20 @@
Sign in to AliasVault
</h2>
-<FullScreenLoadingIndicator @ref="_loadingIndicator" />
-<ServerValidationErrors @ref="_serverValidationErrors" />
+<FullScreenLoadingIndicator @ref="LoadingIndicator" />
+<ServerValidationErrors @ref="ServerValidationErrors" />
-<EditForm Model="_loginModel" OnValidSubmit="HandleLogin" class="mt-8 space-y-6">
+<EditForm Model="LoginModel" OnValidSubmit="HandleLogin" class="mt-8 space-y-6">
<DataAnnotationsValidator/>
<div>
<label asp-for="Input.Email" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Your email</label>
- <InputTextField id="email" @bind-Value="_loginModel.Email" placeholder="[email protected]" />
- <ValidationMessage For="() => _loginModel.Email"/>
+ <InputTextField id="email" @bind-Value="LoginModel.Email" placeholder="[email protected]" />
+ <ValidationMessage For="() => LoginModel.Email"/>
</div>
<div>
<label asp-for="Input.Password" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Your password</label>
- <InputTextField id="password" @bind-Value="_loginModel.Password" type="password" placeholder="••••••••" />
- <ValidationMessage For="() => _loginModel.Password"/>
+ <InputTextField id="password" @bind-Value="LoginModel.Password" type="password" placeholder="••••••••" />
+ <ValidationMessage For="() => LoginModel.Password"/>
</div>
<div class="flex items-start">
@@ -42,9 +42,9 @@
</EditForm>
@code {
- private readonly LoginModel _loginModel = new();
- private FullScreenLoadingIndicator _loadingIndicator = new();
- private ServerValidationErrors _serverValidationErrors = new();
+ private readonly LoginModel LoginModel = new();
+ private FullScreenLoadingIndicator LoadingIndicator = new();
+ private ServerValidationErrors ServerValidationErrors = new();
/// <inheritdoc />
protected override async Task OnInitializedAsync()
@@ -59,22 +59,22 @@
private async Task HandleLogin()
{
- _loadingIndicator.Show();
- _serverValidationErrors.Clear();
+ LoadingIndicator.Show();
+ ServerValidationErrors.Clear();
try
{
- var errors = await ProcessLoginAsync(_loginModel.Email, _loginModel.Password);
+ var errors = await ProcessLoginAsync(LoginModel.Email, LoginModel.Password);
foreach (var error in errors)
{
- _serverValidationErrors.AddError(error);
+ ServerValidationErrors.AddError(error);
}
}
#if DEBUG
catch (Exception ex)
{
// If in debug mode show the actual exception.
- _serverValidationErrors.AddError(ex.ToString());
+ ServerValidationErrors.AddError(ex.ToString());
}
#else
catch
@@ -85,7 +85,7 @@
#endif
finally
{
- _loadingIndicator.Hide();
+ LoadingIndicator.Hide();
}
}
}
diff --git a/src/AliasVault.WebApp/Auth/Pages/Register.razor b/src/AliasVault.WebApp/Auth/Pages/Register.razor
index be9a371bf..7f79ba377 100644
--- a/src/AliasVault.WebApp/Auth/Pages/Register.razor
+++ b/src/AliasVault.WebApp/Auth/Pages/Register.razor
@@ -13,37 +13,37 @@
@using SecureRemotePassword
<h2 class="text-2xl font-bold text-gray-900 dark:text-white">
- Create a Free Account
+ Create a new AliasVault account
</h2>
-<FullScreenLoadingIndicator @ref="_loadingIndicator" />
-<ServerValidationErrors @ref="_serverValidationErrors" />
+<FullScreenLoadingIndicator @ref="LoadingIndicator" />
+<ServerValidationErrors @ref="ServerValidationErrors" />
-<EditForm Model="_registerModel" OnValidSubmit="HandleRegister" class="mt-8 space-y-6">
+<EditForm Model="RegisterModel" OnValidSubmit="HandleRegister" class="mt-8 space-y-6">
<DataAnnotationsValidator/>
<div>
<label asp-for="Input.Email" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Your email</label>
- <InputTextField id="email" @bind-Value="_registerModel.Email" placeholder="[email protected]" />
- <ValidationMessage For="() => _registerModel.Email"/>
+ <InputTextField id="email" @bind-Value="RegisterModel.Email" placeholder="[email protected]" />
+ <ValidationMessage For="() => RegisterModel.Email"/>
</div>
<div>
<label asp-for="Input.Password" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Your password</label>
- <InputTextField id="password" @bind-Value="_registerModel.Password" type="password" placeholder="••••••••" />
- <ValidationMessage For="() => _registerModel.Password"/>
+ <InputTextField id="password" @bind-Value="RegisterModel.Password" type="password" placeholder="••••••••" />
+ <ValidationMessage For="() => RegisterModel.Password"/>
</div>
<div>
<label asp-for="Input.Password" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Confirm password</label>
- <InputTextField id="password2" @bind-Value="_registerModel.PasswordConfirm" type="password" placeholder="••••••••" />
- <ValidationMessage For="() => _registerModel.PasswordConfirm"/>
+ <InputTextField id="password2" @bind-Value="RegisterModel.PasswordConfirm" type="password" placeholder="••••••••" />
+ <ValidationMessage For="() => RegisterModel.PasswordConfirm"/>
</div>
<div class="flex items-start">
<div class="flex items-center h-5">
- <InputCheckbox id="terms" @bind-Value="_registerModel.AcceptTerms" class="w-4 h-4 border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-primary-300 dark:focus:ring-primary-600 dark:ring-offset-gray-800 dark:bg-gray-700 dark:border-gray-600" />
+ <InputCheckbox id="terms" @bind-Value="RegisterModel.AcceptTerms" class="w-4 h-4 border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-primary-300 dark:focus:ring-primary-600 dark:ring-offset-gray-800 dark:bg-gray-700 dark:border-gray-600" />
</div>
<div class="ml-3 text-sm">
<label for="terms" class="font-medium text-gray-900 dark:text-white">I accept the <a href="#" class="text-primary-700 hover:underline dark:text-primary-500">Terms and Conditions</a></label>
- <ValidationMessage For="() => _registerModel.AcceptTerms"/>
+ <ValidationMessage For="() => RegisterModel.AcceptTerms"/>
</div>
</div>
@@ -54,24 +54,24 @@
</EditForm>
@code {
- private readonly RegisterModel _registerModel = new();
- private FullScreenLoadingIndicator _loadingIndicator = new();
- private ServerValidationErrors _serverValidationErrors = new();
+ private readonly RegisterModel RegisterModel = new();
+ private FullScreenLoadingIndicator LoadingIndicator = new();
+ private ServerValidationErrors ServerValidationErrors = new();
async Task HandleRegister()
{
- _loadingIndicator.Show();
- _serverValidationErrors.Clear();
+ LoadingIndicator.Show();
+ ServerValidationErrors.Clear();
try
{
var client = new SrpClient();
var salt = client.GenerateSalt();
- byte[] passwordHash = await Encryption.DeriveKeyFromPasswordAsync(_registerModel.Password, salt);
+ byte[] passwordHash = await Encryption.DeriveKeyFromPasswordAsync(RegisterModel.Password, salt);
var passwordHashString = BitConverter.ToString(passwordHash).Replace("-", string.Empty);
- var srpSignup = Cryptography.Srp.SignupPrepareAsync(client, salt, _registerModel.Email, passwordHashString);
+ var srpSignup = Cryptography.Srp.SignupPrepareAsync(client, salt, RegisterModel.Email, passwordHashString);
var result = await Http.PostAsJsonAsync("api/v1/Auth/register", srpSignup);
var responseContent = await result.Content.ReadAsStringAsync();
@@ -79,7 +79,7 @@
{
foreach (var error in LoginBase.ParseResponse(responseContent))
{
- _serverValidationErrors.AddError(error);
+ ServerValidationErrors.AddError(error);
}
StateHasChanged();
return;
@@ -107,7 +107,7 @@
}
finally
{
- _loadingIndicator.Hide();
+ LoadingIndicator.Hide();
}
}
}
diff --git a/src/AliasVault.WebApp/Auth/Pages/Unlock.razor b/src/AliasVault.WebApp/Auth/Pages/Unlock.razor
index 4b666695c..69576764f 100644
--- a/src/AliasVault.WebApp/Auth/Pages/Unlock.razor
+++ b/src/AliasVault.WebApp/Auth/Pages/Unlock.razor
@@ -13,15 +13,15 @@
Enter your master password in order to unlock your database.
</p>
-<FullScreenLoadingIndicator @ref="_loadingIndicator" />
+<FullScreenLoadingIndicator @ref="LoadingIndicator" />
<ServerValidationErrors @ref="_serverValidationErrors" />
-<EditForm Model="_unlockModel" OnValidSubmit="HandleLogin" class="mt-8 space-y-6">
+<EditForm Model="UnlockModel" OnValidSubmit="HandleLogin" class="mt-8 space-y-6">
<DataAnnotationsValidator/>
<div>
<label asp-for="Input.Password" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Your password</label>
- <InputTextField id="password" @bind-Value="_unlockModel.Password" type="password" placeholder="••••••••" />
- <ValidationMessage For="() => _unlockModel.Password"/>
+ <InputTextField id="password" @bind-Value="UnlockModel.Password" type="password" placeholder="••••••••" />
+ <ValidationMessage For="() => UnlockModel.Password"/>
</div>
<button type="submit" class="inline-flex items-center justify-center w-full px-5 py-3 text-base font-medium text-center text-white rounded-lg bg-primary-700 hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 sm:w-auto dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800">
@@ -36,8 +36,8 @@
@code {
private string? Email { get; set; }
- private readonly UnlockModel _unlockModel = new();
- private FullScreenLoadingIndicator _loadingIndicator = new();
+ private readonly UnlockModel UnlockModel = new();
+ private FullScreenLoadingIndicator LoadingIndicator = new();
private ServerValidationErrors _serverValidationErrors = new();
/// <inheritdoc />
@@ -70,12 +70,12 @@
return;
}
- _loadingIndicator.Show();
+ LoadingIndicator.Show();
_serverValidationErrors.Clear();
try
{
- var errors = await ProcessLoginAsync(Email, _unlockModel.Password);
+ var errors = await ProcessLoginAsync(Email, UnlockModel.Password);
foreach (var error in errors)
{
_serverValidationErrors.AddError(error);
@@ -97,7 +97,7 @@
#endif
finally
{
- _loadingIndicator.Hide();
+ LoadingIndicator.Hide();
}
}
}
diff --git a/src/AliasVault.WebApp/Main/Components/Email/RecentEmails.razor b/src/AliasVault.WebApp/Main/Components/Email/RecentEmails.razor
index f37d427a3..b84eeeb86 100644
--- a/src/AliasVault.WebApp/Main/Components/Email/RecentEmails.razor
+++ b/src/AliasVault.WebApp/Main/Components/Email/RecentEmails.razor
@@ -1,7 +1,7 @@
@using AliasVault.WebApp.Main.Models.Spamok
@inherits ComponentBase
@inject IHttpClientFactory HttpClientFactory
- s
+
@if (ShowComponent)
{
<div class="flex justify-between">
diff --git a/src/AliasVault.WebApp/Main/Components/Layout/Breadcrumb.razor b/src/AliasVault.WebApp/Main/Components/Layout/Breadcrumb.razor
index 5eb24c326..c435443bd 100644
--- a/src/AliasVault.WebApp/Main/Components/Layout/Breadcrumb.razor
+++ b/src/AliasVault.WebApp/Main/Components/Layout/Breadcrumb.razor
@@ -1,6 +1,6 @@
@inherits ComponentBase
-<nav class="flex mb-5" aria-label="RecentEmails">
+<nav class="flex mb-5">
<ol class="inline-flex items-center space-x-1 text-sm font-medium md:space-x-2">
<li class="inline-flex items-center">
<a href="/" class="inline-flex items-center text-gray-700 hover:text-primary-600 dark:text-gray-300 dark:hover:text-primary-500">
diff --git a/src/AliasVault.WebApp/Main/Components/Loading/FullScreenLoadingIndicator.razor b/src/AliasVault.WebApp/Main/Components/Loading/FullScreenLoadingIndicator.razor
index ac2305327..d8b2b0b94 100644
--- a/src/AliasVault.WebApp/Main/Components/Loading/FullScreenLoadingIndicator.razor
+++ b/src/AliasVault.WebApp/Main/Components/Loading/FullScreenLoadingIndicator.razor
@@ -1,12 +1,15 @@
-<div class="loading" style="display:@(IsVisible ? "block" : "none");">
- <div class="spinner">
- <div class="rect1"></div>
- <div class="rect2"></div>
- <div class="rect3"></div>
- <div class="rect4"></div>
- <div class="rect5"></div>
+@if (IsVisible)
+{
+ <div class="loading z-50">
+ <div class="spinner">
+ <div class="rect1"></div>
+ <div class="rect2"></div>
+ <div class="rect3"></div>
+ <div class="rect4"></div>
+ <div class="rect5"></div>
+ </div>
</div>
-</div>
+}
@code {
private bool IsVisible { get; set; }
diff --git a/src/AliasVault.WebApp/Main/Layout/MainLayout.razor b/src/AliasVault.WebApp/Main/Layout/MainLayout.razor
index d6398f22c..e8c698c68 100644
--- a/src/AliasVault.WebApp/Main/Layout/MainLayout.razor
+++ b/src/AliasVault.WebApp/Main/Layout/MainLayout.razor
@@ -1,8 +1,11 @@
@inherits LayoutComponentBase
+@implements IDisposable
+@inject GlobalLoadingService GlobalLoadingService
<CascadingAuthenticationState>
<AuthorizeView>
<Authorized>
+ <FullScreenLoadingIndicator @ref="LoadingIndicator" />
<TopMenu />
<div class="flex pt-16 overflow-hidden bg-gray-50 dark:bg-gray-900">
<div id="main-content" class="relative w-full max-w-screen-2xl mx-auto h-full overflow-y-auto bg-gray-50 dark:bg-gray-900">
@@ -22,5 +25,33 @@
</CascadingAuthenticationState>
@code {
- [CascadingParameter] private Task<AuthenticationState>? AuthState { get; set; }
+ [CascadingParameter]
+ private Task<AuthenticationState>? AuthState { get; set; }
+
+ private FullScreenLoadingIndicator LoadingIndicator = new();
+
+ /// <inheritdoc />
+ protected override void OnInitialized()
+ {
+ GlobalLoadingService.OnChange += OnChange;
+ }
+
+ /// <inheritdoc />
+ public void Dispose()
+ {
+ GlobalLoadingService.OnChange -= OnChange;
+ }
+
+ private void OnChange()
+ {
+ if (GlobalLoadingService.IsLoading)
+ {
+ LoadingIndicator.Show();
+ }
+ else
+ {
+ LoadingIndicator.Hide();
+ }
+ StateHasChanged();
+ }
}
diff --git a/src/AliasVault.WebApp/Main/Pages/Credentials/AddEdit.razor b/src/AliasVault.WebApp/Main/Pages/Credentials/AddEdit.razor
index 28fae16ee..e528df452 100644
--- a/src/AliasVault.WebApp/Main/Pages/Credentials/AddEdit.razor
+++ b/src/AliasVault.WebApp/Main/Pages/Credentials/AddEdit.razor
@@ -5,7 +5,6 @@
@using System.Globalization
@using AliasGenerators.Implementations
@using AliasGenerators.Password.Implementations
-@using AliasVault.Shared.Models
@if (EditMode)
{
@@ -167,12 +166,6 @@ else
</div>
</EditForm>
-
- @if (IsSaving)
- {
- <p>Saving...</p>
- }
-
}
@code {
@@ -186,7 +179,6 @@ else
private bool Loading { get; set; } = true;
private CredentialEdit Obj { get; set; } = new();
private bool IsIdentityLoading { get; set; }
- private bool IsSaving { get; set; }
/// <inheritdoc />
protected override void OnInitialized()
@@ -313,7 +305,7 @@ else
private async Task SaveAlias()
{
- IsSaving = true;
+ GlobalLoadingSpinner.Show();
StateHasChanged();
// Sanity check for unittest. Delete later if not needed.
@@ -330,7 +322,7 @@ else
Id = await CredentialService.InsertEntryAsync(CredentialEditToCredential(Obj));
}
- IsSaving = false;
+ GlobalLoadingSpinner.Hide();
StateHasChanged();
if (Id is null || Id == Guid.Empty)
diff --git a/src/AliasVault.WebApp/Main/Pages/Credentials/Delete.razor b/src/AliasVault.WebApp/Main/Pages/Credentials/Delete.razor
index 6d5a5a875..420cb702b 100644
--- a/src/AliasVault.WebApp/Main/Pages/Credentials/Delete.razor
+++ b/src/AliasVault.WebApp/Main/Pages/Credentials/Delete.razor
@@ -85,8 +85,11 @@ else
return;
}
+ GlobalLoadingSpinner.Show();
await CredentialService.DeleteEntryAsync(Id);
GlobalNotificationService.AddSuccessMessage("Credentials entry successfully deleted.");
+ GlobalLoadingSpinner.Hide();
+
NavigationManager.NavigateTo("/");
}
diff --git a/src/AliasVault.WebApp/Main/Pages/MainBase.cs b/src/AliasVault.WebApp/Main/Pages/MainBase.cs
index 33d44414e..e8a6fd575 100644
--- a/src/AliasVault.WebApp/Main/Pages/MainBase.cs
+++ b/src/AliasVault.WebApp/Main/Pages/MainBase.cs
@@ -42,6 +42,12 @@ public class MainBase : OwningComponentBase
[Inject]
public GlobalNotificationService GlobalNotificationService { get; set; } = null!;
+ /// <summary>
+ /// Gets or sets the GlobalLoadingService in order to manipulate the global loading spinner animation.
+ /// </summary>
+ [Inject]
+ public GlobalLoadingService GlobalLoadingSpinner { get; set; } = null!;
+
/// <summary>
/// Gets or sets the IJSRuntime.
/// </summary>
diff --git a/src/AliasVault.WebApp/Program.cs b/src/AliasVault.WebApp/Program.cs
index 4728ffc9a..69ba22814 100644
--- a/src/AliasVault.WebApp/Program.cs
+++ b/src/AliasVault.WebApp/Program.cs
@@ -49,6 +49,7 @@ builder.Services.AddScoped<AuthenticationStateProvider, AuthStateProvider>();
builder.Services.AddScoped<CredentialService>();
builder.Services.AddScoped<DbService>();
builder.Services.AddScoped<GlobalNotificationService>();
+builder.Services.AddScoped<GlobalLoadingService>();
builder.Services.AddSingleton<ClipboardCopyService>();
builder.Services.AddAuthorizationCore();
diff --git a/src/AliasVault.WebApp/Services/GlobalLoadingService.cs b/src/AliasVault.WebApp/Services/GlobalLoadingService.cs
new file mode 100644
index 000000000..95fcf5092
--- /dev/null
+++ b/src/AliasVault.WebApp/Services/GlobalLoadingService.cs
@@ -0,0 +1,47 @@
+//-----------------------------------------------------------------------
+// <copyright file="GlobalLoadingService.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.WebApp.Services;
+
+/// <summary>
+/// Global loading service that can be used to show or hide a global layout loading spinner.
+/// </summary>
+public class GlobalLoadingService
+{
+ private bool _isLoading;
+
+ /// <summary>
+ /// Occurs when the loading state changes.
+ /// </summary>
+ public event Action? OnChange;
+
+ /// <summary>
+ /// Gets or sets a value indicating whether the global loading spinner is currently visible.
+ /// </summary>
+ public bool IsLoading
+ {
+ get => _isLoading;
+ set
+ {
+ if (_isLoading != value)
+ {
+ _isLoading = value;
+ OnChange?.Invoke();
+ }
+ }
+ }
+
+ /// <summary>
+ /// Show the global loading spinner.
+ /// </summary>
+ public void Show() => IsLoading = true;
+
+ /// <summary>
+ /// Hide the global loading spinner.
+ /// </summary>
+ public void Hide() => IsLoading = false;
+}
diff --git a/src/AliasVault.WebApp/wwwroot/css/tailwind.css b/src/AliasVault.WebApp/wwwroot/css/tailwind.css
index 2542cb744..7d95f5a55 100644
--- a/src/AliasVault.WebApp/wwwroot/css/tailwind.css
+++ b/src/AliasVault.WebApp/wwwroot/css/tailwind.css
@@ -1087,6 +1087,11 @@ video {
background-color: rgb(37 99 235 / var(--tw-bg-opacity));
}
+.bg-gray-100 {
+ --tw-bg-opacity: 1;
+ background-color: rgb(243 244 246 / var(--tw-bg-opacity));
+}
+
.bg-gray-200 {
--tw-bg-opacity: 1;
background-color: rgb(229 231 235 / var(--tw-bg-opacity));
@@ -1147,11 +1152,6 @@ video {
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
}
-.bg-gray-100 {
- --tw-bg-opacity: 1;
- background-color: rgb(243 244 246 / var(--tw-bg-opacity));
-}
-
.bg-opacity-50 {
--tw-bg-opacity: 0.5;
}
@@ -1338,6 +1338,11 @@ video {
color: rgb(59 130 246 / var(--tw-text-opacity));
}
+.text-blue-600 {
+ --tw-text-opacity: 1;
+ color: rgb(37 99 235 / var(--tw-text-opacity));
+}
+
.text-blue-700 {
--tw-text-opacity: 1;
color: rgb(29 78 216 / var(--tw-text-opacity));
@@ -1378,6 +1383,11 @@ video {
color: rgb(34 197 94 / var(--tw-text-opacity));
}
+.text-green-600 {
+ --tw-text-opacity: 1;
+ color: rgb(22 163 74 / var(--tw-text-opacity));
+}
+
.text-green-800 {
--tw-text-opacity: 1;
color: rgb(22 101 52 / var(--tw-text-opacity));
@@ -1408,16 +1418,6 @@ video {
color: rgb(255 255 255 / var(--tw-text-opacity));
}
-.text-blue-600 {
- --tw-text-opacity: 1;
- color: rgb(37 99 235 / var(--tw-text-opacity));
-}
-
-.text-green-600 {
- --tw-text-opacity: 1;
- color: rgb(22 163 74 / var(--tw-text-opacity));
-}
-
.opacity-0 {
opacity: 0;
}