diff --git a/Pkmds.Web/Components/Pages/Home.razor.cs b/Pkmds.Web/Components/Pages/Home.razor.cs index a9de5ec3..de7922ae 100644 --- a/Pkmds.Web/Components/Pages/Home.razor.cs +++ b/Pkmds.Web/Components/Pages/Home.razor.cs @@ -4,13 +4,14 @@ public partial class Home { private bool IsUpdateAvailable { get; set; } = false; - protected override void OnInitialized() => RefreshService.OnAppStateChanged += StateHasChanged; + protected override void OnInitialized() + { + RefreshService.OnAppStateChanged += StateHasChanged; + RefreshService.OnUpdateAvailable += ShowUpdateMessage; + } public void Dispose() => RefreshService.OnAppStateChanged -= StateHasChanged; - private async Task RefreshApp() => await JSRuntime.InvokeVoidAsync("location.reload"); - - [JSInvokable(nameof(ShowUpdateMessage))] public void ShowUpdateMessage() { // Display the alert when an update is available diff --git a/Pkmds.Web/Services/IRefreshService.cs b/Pkmds.Web/Services/IRefreshService.cs index 3d183005..43dbd164 100644 --- a/Pkmds.Web/Services/IRefreshService.cs +++ b/Pkmds.Web/Services/IRefreshService.cs @@ -8,6 +8,8 @@ public interface IRefreshService event Action? OnPartyStateChanged; + event Action? OnUpdateAvailable; + void Refresh(); void RefreshBoxState(); @@ -15,4 +17,6 @@ public interface IRefreshService void RefreshPartyState(); void RefreshBoxAndPartyState(); + + void ShowUpdateMessage(); } diff --git a/Pkmds.Web/Services/RefreshService.cs b/Pkmds.Web/Services/RefreshService.cs index d946177e..3565152c 100644 --- a/Pkmds.Web/Services/RefreshService.cs +++ b/Pkmds.Web/Services/RefreshService.cs @@ -5,6 +5,7 @@ public record RefreshService(IAppState AppState) : IRefreshService public event Action? OnAppStateChanged; public event Action? OnBoxStateChanged; public event Action? OnPartyStateChanged; + public event Action? OnUpdateAvailable; public void Refresh() => OnAppStateChanged?.Invoke(); @@ -17,4 +18,7 @@ public void RefreshBoxAndPartyState() RefreshBoxState(); RefreshPartyState(); } + + [JSInvokable("ShowUpdateMessage")] + public void ShowUpdateMessage() => OnUpdateAvailable?.Invoke(); }