mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-05-07 14:56:02 -04:00
75 lines
2.0 KiB
Plaintext
75 lines
2.0 KiB
Plaintext
@implements IDisposable
|
|
@inject DbService DbService
|
|
|
|
<div class="ms-2">
|
|
@if (Loading)
|
|
{
|
|
<div class="flex items-center justify-center">
|
|
<SmallLoadingIndicator Title="@LoadingIndicatorMessage" />
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<SmallLoadingIndicator Title="@LoadingIndicatorMessage" Spinning="false" />
|
|
}
|
|
</div>
|
|
|
|
@code {
|
|
private bool Loading { get; set; } = false;
|
|
private string LoadingIndicatorMessage { get; set; } = "";
|
|
private bool DatabaseLoading { get; set; } = false;
|
|
|
|
/// <inheritdoc />
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await base.OnInitializedAsync();
|
|
DbService.GetState().StateChanged += OnDatabaseStateChanged;
|
|
|
|
UpdateLoadingIndicatorMessage();
|
|
}
|
|
|
|
private async void OnDatabaseStateChanged(object? sender, DbServiceState.DatabaseState newState)
|
|
{
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
UpdateLoadingIndicatorMessage();
|
|
|
|
if (newState.Status == DbServiceState.DatabaseStatus.SavingToServer)
|
|
{
|
|
// Show loading indicator for at least 0.5 seconds even if the save operation is faster.
|
|
await ShowLoadingIndicatorAsync();
|
|
}
|
|
}
|
|
|
|
private void UpdateLoadingIndicatorMessage()
|
|
{
|
|
var currentState = DbService.GetState().CurrentState;
|
|
|
|
var message = currentState.Status.ToString();
|
|
if (currentState.Message != string.Empty)
|
|
{
|
|
message = currentState.Message;
|
|
}
|
|
|
|
LoadingIndicatorMessage = "Vault status: " + message + " - " + currentState.LastUpdated;
|
|
StateHasChanged();
|
|
}
|
|
|
|
private async Task ShowLoadingIndicatorAsync()
|
|
{
|
|
Loading = true;
|
|
StateHasChanged();
|
|
await Task.Delay(800);
|
|
Loading = false;
|
|
StateHasChanged();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dispose method.
|
|
/// </summary>
|
|
public void Dispose()
|
|
{
|
|
DbService.GetState().StateChanged -= OnDatabaseStateChanged;
|
|
}
|
|
}
|