//----------------------------------------------------------------------- // // Copyright (c) aliasvault. All rights reserved. // Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information. // //----------------------------------------------------------------------- namespace AliasVault.Client.Services; /// /// Global loading service that can be used to show or hide a global layout loading spinner. /// public sealed class GlobalLoadingService { private bool _isLoading; private string _loadingMessage = string.Empty; /// /// Occurs when the loading state changes. /// public event Action? OnChange; /// /// Gets or sets a value indicating whether the global loading spinner is currently visible. /// public bool IsLoading { get => _isLoading; set { if (_isLoading != value) { _isLoading = value; OnChange?.Invoke(); } } } /// /// Gets the current loading message. /// public string LoadingMessage { get => _loadingMessage; private set { if (_loadingMessage != value) { _loadingMessage = value; OnChange?.Invoke(); } } } /// /// Show the global loading spinner. /// /// Optional message to display below the loading spinner. public void Show(string? message = null) { LoadingMessage = message ?? string.Empty; IsLoading = true; } /// /// Hide the global loading spinner. /// public void Hide() { IsLoading = false; LoadingMessage = string.Empty; } }