Skip to content

Commit

Permalink
Try to fix JS interop for update alert
Browse files Browse the repository at this point in the history
  • Loading branch information
codemonkey85 committed Nov 22, 2024
1 parent 2a19402 commit c2111c6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Pkmds.Web/Components/Pages/Home.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Pkmds.Web/Services/IRefreshService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ public interface IRefreshService

event Action? OnPartyStateChanged;

event Action? OnUpdateAvailable;

void Refresh();

void RefreshBoxState();

void RefreshPartyState();

void RefreshBoxAndPartyState();

void ShowUpdateMessage();
}
4 changes: 4 additions & 0 deletions Pkmds.Web/Services/RefreshService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -17,4 +18,7 @@ public void RefreshBoxAndPartyState()
RefreshBoxState();
RefreshPartyState();
}

[JSInvokable("ShowUpdateMessage")]
public void ShowUpdateMessage() => OnUpdateAvailable?.Invoke();
}

0 comments on commit c2111c6

Please sign in to comment.