Masque le menu pendant l'authentification mobile

This commit is contained in:
2026-04-14 23:03:02 +02:00
parent 260b839f93
commit c23dcc8484
3 changed files with 32 additions and 1 deletions

View File

@@ -6,6 +6,7 @@
@using Microsoft.AspNetCore.Components.Authorization @using Microsoft.AspNetCore.Components.Authorization
@implements IDisposable @implements IDisposable
@inject AppAuthenticationStateProvider AuthenticationStateProvider @inject AppAuthenticationStateProvider AuthenticationStateProvider
@inject BrowserBridge Browser
@inject HttpClient Http @inject HttpClient Http
@inject NavigationManager Navigation @inject NavigationManager Navigation
@@ -168,6 +169,7 @@
private AuthMode Mode = AuthMode.Login; private AuthMode Mode = AuthMode.Login;
private string DisplayName = "Utilisateur connecte"; private string DisplayName = "Utilisateur connecte";
private string DisplayMeta = "Session active"; private string DisplayMeta = "Session active";
private bool _syncMenuAfterRender;
private string CurrentPath private string CurrentPath
{ {
@@ -184,6 +186,17 @@
await RefreshAuthenticationStateAsync(); await RefreshAuthenticationStateAsync();
} }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!_syncMenuAfterRender)
{
return;
}
_syncMenuAfterRender = false;
await Browser.SyncMenuAsync();
}
private string BuildNavLinkClass(string[] paths) private string BuildNavLinkClass(string[] paths)
=> IsCurrentPage(paths) ? "site-menu-link is-active" : "site-menu-link"; => IsCurrentPage(paths) ? "site-menu-link is-active" : "site-menu-link";
@@ -197,12 +210,14 @@
{ {
ShowAuthModal = true; ShowAuthModal = true;
SwitchToLogin(); SwitchToLogin();
RequestMenuSync();
} }
private void OpenRegisterModal() private void OpenRegisterModal()
{ {
ShowAuthModal = true; ShowAuthModal = true;
SwitchToRegister(); SwitchToRegister();
RequestMenuSync();
} }
private void CloseAuthModal() private void CloseAuthModal()
@@ -214,6 +229,7 @@
ShowAuthModal = false; ShowAuthModal = false;
FormError = null; FormError = null;
RequestMenuSync();
} }
private void SwitchToLogin() private void SwitchToLogin()
@@ -300,6 +316,7 @@
FormError = null; FormError = null;
ResetForms(); ResetForms();
await RefreshAuthenticationStateAsync(); await RefreshAuthenticationStateAsync();
RequestMenuSync();
} }
catch (HttpRequestException) catch (HttpRequestException)
{ {
@@ -344,6 +361,9 @@
private void HandleAuthenticationStateChanged(Task<AuthenticationState> authenticationStateTask) private void HandleAuthenticationStateChanged(Task<AuthenticationState> authenticationStateTask)
=> _ = InvokeAsync(RefreshAuthenticationStateAsync); => _ = InvokeAsync(RefreshAuthenticationStateAsync);
private void RequestMenuSync()
=> _syncMenuAfterRender = true;
private async Task RefreshAuthenticationStateAsync() private async Task RefreshAuthenticationStateAsync()
{ {
try try

View File

@@ -10,6 +10,9 @@ public sealed class BrowserBridge(IJSRuntime jsRuntime)
public ValueTask SetBodyStateAsync(string? page, string? bodyClass) public ValueTask SetBodyStateAsync(string? page, string? bodyClass)
=> jsRuntime.InvokeVoidAsync("chesscubingPage.setBodyState", page, bodyClass ?? string.Empty); => jsRuntime.InvokeVoidAsync("chesscubingPage.setBodyState", page, bodyClass ?? string.Empty);
public ValueTask SyncMenuAsync()
=> jsRuntime.InvokeVoidAsync("chesscubingMenu.sync");
public ValueTask<string?> ReadMatchJsonAsync(string storageKey, string windowNameKey) public ValueTask<string?> ReadMatchJsonAsync(string storageKey, string windowNameKey)
=> jsRuntime.InvokeAsync<string?>("chesscubingStorage.getMatchState", storageKey, windowNameKey); => jsRuntime.InvokeAsync<string?>("chesscubingStorage.getMatchState", storageKey, windowNameKey);

View File

@@ -46,6 +46,14 @@
document.body.classList.toggle("site-menu-hidden", hidden); document.body.classList.toggle("site-menu-hidden", hidden);
} }
function shouldHideMenuForModal(modal) {
if (!modal) {
return false;
}
return window.matchMedia("(max-width: 900px)").matches && modal.querySelector(".auth-modal-card") !== null;
}
function syncMenuVisibility() { function syncMenuVisibility() {
menuAnimationFrame = 0; menuAnimationFrame = 0;
@@ -58,7 +66,7 @@
const modalIsOpen = document.querySelector(".modal:not(.hidden)"); const modalIsOpen = document.querySelector(".modal:not(.hidden)");
if (modalIsOpen) { if (modalIsOpen) {
setMenuHidden(false); setMenuHidden(shouldHideMenuForModal(modalIsOpen));
menuLastScrollY = window.scrollY || window.pageYOffset || 0; menuLastScrollY = window.scrollY || window.pageYOffset || 0;
return; return;
} }