Files
FoodsharingOnboarding/FoodsharingSiegen.Server/Shared/NavMenu.razor.cs
Andre Beging 4d646ad7f6 Add JS toggle logic to close menu on nav link click
Introduced IJSRuntime to handle JavaScript calls and implemented `NavLinkClickedAsync` to automatically uncheck the menu toggle on navigation. Updated all NavLinks to trigger this logic, improving user experience by closing the menu after a link is clicked.
2025-03-27 17:48:03 +01:00

63 lines
1.8 KiB
C#

using FoodsharingSiegen.Contracts.Entity;
using FoodsharingSiegen.Contracts.Model;
using FoodsharingSiegen.Server.Auth;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Options;
using Microsoft.JSInterop;
namespace FoodsharingSiegen.Server.Shared
{
/// <summary>
/// The nav menu class (a. beging, 07.02.2023)
/// </summary>
public partial class NavMenu
{
[Inject]
private IJSRuntime JsRuntime { get; set; } = null!;
#region Dependencies
[Inject]
private IOptions<AppSettings> AppSettingsContainer { get; set; } = null!;
[Inject]
protected AuthService AuthService { get; set; } = null!;
#endregion
#region Private Properties
/// <summary>
/// Gets the value of the current user (ab)
/// </summary>
private User CurrentUser => AuthService.User ?? new User();
#endregion
#region Protected Properties
/// Provides application-specific settings used to configure the behavior and display of the application.
/// The AppSettings class encapsulates information such as the application title and other configurable parameters.
protected AppSettings AppSettings => AppSettingsContainer.Value;
#endregion
#region Override OnInitializedAsync
/// <summary>
/// Ons the initialized (a. beging, 07.02.2023)
/// </summary>
protected override async Task OnInitializedAsync()
{
await AuthService.Initialize();
await base.OnInitializedAsync();
}
#endregion
private async Task NavLinkClickedAsync()
{
await JsRuntime.InvokeVoidAsync("eval", "document.getElementById('menu-toggler').checked=false;");
}
}
}