@inherits LayoutComponentBase @inject GPW.CORE.Services.UserStateService UState @inject ILogger Log GPW.CORE.Smart (Client)
@Body
@if (dataLoaded) { }
An unhandled error has occurred. Reload 🗙
@code { private readonly Guid _instanceId = Guid.NewGuid(); private bool _subscribed; private bool isIpLocal = false; private bool dataLoaded = true; private UserDTO? currUser; private ConfigDTO? currConfig; private int idxDip { get => (currUser != null && currUser?.IdxDip != null) ? (int)currUser?.IdxDip : 0; } protected override void OnInitialized() { Log.LogInformation("MainLayout OnInitialized client instance {Id}", _instanceId); } protected override async Task OnAfterRenderAsync(bool firstRender) { if (!firstRender) return; Log.LogInformation("MainLayout OnAfterRenderAsync firstRender client instance {Id}, CurrentUser {User}", _instanceId, UState.CurrentUser?.Utente ?? ""); if (!_subscribed) { UState.OnChange += UState_OnChange; _subscribed = true; Log.LogInformation("MainLayout subscribed to UserState in client instance {Id}", _instanceId); } if (UState.CurrentUser != null) { currUser = UState.CurrentUser; await InvokeAsync(StateHasChanged); } } private void UState_OnChange() { _ = InvokeAsync(() => { Log.LogInformation("MainLayout UState_OnChange client instance {Id} invoked", _instanceId); currUser = UState.CurrentUser; StateHasChanged(); }); } public void Dispose() { if (_subscribed) { UState.OnChange -= UState_OnChange; _subscribed = false; Log.LogInformation("MainLayout unsubscribed in Dispose client instance {Id}", _instanceId); } } [Inject] private HttpClient Http { get; set; } = null!; [Inject] private NavigationManager NavMan { get; set; } = null!; private async Task ReturnHome() { Console.WriteLine("MainLayout.ReturnHome (Client)"); var done = await Http.PostAsync("api/cache/flush", null); NavMan.NavigateTo("Home", true); // => Task.CompletedTask; } private async Task ForceReset() { Console.WriteLine("MainLayout.ForceReset (Client)"); var done = await Http.PostAsync("api/cache/flush", null); string nextPage = NavMan.ToBaseRelativePath(NavMan.Uri); // tengo solo parte finale... if (nextPage.Contains("/")) { nextPage = nextPage.Substring(nextPage.LastIndexOf("/") + 1); } await Task.Delay(1); NavMan.NavigateTo($"ForceReset?nextPage={nextPage}", true); // => Task.CompletedTask; } }