private void RestorePizza(PizzaAuthenticationState pizzaState) { if (pizzaState.Order != null) { OrderState.ReplaceOrder(pizzaState.Order); } }
protected override async Task OnInitializedAsync() { var authState = await AuthenticationStateTask; if (!authState.User.Identity.IsAuthenticated) { // The server won't accept orders from unauthenticated users, so avoid // an error by making them log in at this point await LocalStorage.SetAsync(JSRuntime, "currentorder", OrderState.Order); NavigationManager.NavigateTo("user/signin?redirectUri=/checkout", true); } // Try to recover any temporary saved order if (!OrderState.Order.Pizzas.Any()) { var savedOrder = await LocalStorage.GetAsync <Order>(JSRuntime, "currentorder"); if (savedOrder != null) { OrderState.ReplaceOrder(savedOrder); await LocalStorage.DeleteAsync(JSRuntime, "currentorder"); } else { // There's nothing check out - go to home NavigationManager.NavigateTo(""); } } // In the background, ask if they want to be notified about order updates _ = RequestNotificationSubscriptionAsync(); }