Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Boilerplate push notification subscription (#10212) #10213

Merged
merged 3 commits into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected override async Task OnInitAsync()
//#if (signalR == true)
SubscribeToSignalREventsMessages();
//#endif
await PropagateUserId(firstRun: true, AuthenticationStateTask);
await PropagateAuthState(firstRun: true, AuthenticationStateTask);
}

await base.OnInitAsync();
Expand All @@ -96,7 +96,7 @@ private void NavigationManager_LocationChanged(object? sender, LocationChangedEv
/// This code manages the association of a user with sensitive services, such as SignalR, push notifications, App Insights, and others,
/// ensuring the user is correctly set or cleared as needed.
/// </summary>
public async Task PropagateUserId(bool firstRun, Task<AuthenticationState> task)
public async Task PropagateAuthState(bool firstRun, Task<AuthenticationState> task)
{
try
{
Expand Down Expand Up @@ -142,6 +142,10 @@ public async Task PropagateUserId(bool firstRun, Task<AuthenticationState> task)
//#endif

//#if (notification == true)
if (firstRun)
{
await Task.Delay(10_000, CurrentCancellationToken); // No rush to subscribe to push notifications.
}
await pushNotificationService.Subscribe(CurrentCancellationToken);
//#endif
}
Expand All @@ -153,7 +157,7 @@ public async Task PropagateUserId(bool firstRun, Task<AuthenticationState> task)

private void AuthenticationStateChanged(Task<AuthenticationState> task)
{
_ = PropagateUserId(firstRun: false, task);
_ = PropagateAuthState(firstRun: false, task);
}

//#if (signalR == true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public partial class MainLayout : IAsyncDisposable
private List<Action> unsubscribers = [];

[AutoInject] private Keyboard keyboard = default!;
[AutoInject] private IJSRuntime jsRuntime = default!;
[AutoInject] private AuthManager authManager = default!;
[AutoInject] private ThemeService themeService = default!;
[AutoInject] private PubSubService pubSubService = default!;
Expand All @@ -40,6 +41,15 @@ protected override async Task OnInitializedAsync()
{
try
{
var inPrerenderSession = jsRuntime.IsInitialized() is false;
isOnline = await prerenderStateService.GetValue<bool?>(nameof(isOnline), async () => isOnline ?? inPrerenderSession is true ? true : null);
// During pre-rendering, if any API calls are made, the `isOnline` value will be set
// using PubSub's `ClientPubSubMessages.IS_ONLINE_CHANGED`, depending on the success
// or failure of the API call. However, if a pre-rendered page has no HTTP API call
// dependencies, its value remains null.
// Even though Server.Web and Server.Api may be deployed on different servers,
// we can still assume that if the client is displaying a pre-rendered result, it is online.

InitializeNavPanelItems();

navigationManager.LocationChanged += NavigationManager_LocationChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<BitStack FillContent>
<BitStack Horizontal VerticalAlign="BitAlignment.Center" Gap="0.5rem">
<BitButton Variant="BitVariant.Text"
Href="@Urls.CategoriesPage"
Href="@Urls.ProductsPage"
IconName="@BitIconName.Back"
Title="@Localizer[nameof(AppStrings.Back)]" />
<BitText Typography="BitTypography.H5">
Expand Down
Loading