Files
FoodsharingOnboarding/FoodsharingSiegen.Server/Shared/NavMenu.razor.cs
2025-03-28 08:55:49 +01:00

76 lines
2.1 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
{
#region Dependencies
[Inject]
private IOptions<AppSettings> AppSettingsContainer { get; set; } = null!;
[Inject]
protected AuthService AuthService { get; set; } = null!;
[Inject]
private IWebHostEnvironment Env { get; set; } = null!;
[Inject]
private IJSRuntime JsRuntime { get; set; } = null!;
#endregion
#region Private Properties
/// <summary>
/// Gets the value of the current user (ab)
/// </summary>
private User CurrentUser => AuthService.User ?? new User();
private string? Version { get; set; }
#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();
var filePath = Path.Combine(Env.WebRootPath, "buildinfo.txt");
if (File.Exists(filePath)) Version = await File.ReadAllTextAsync(filePath);
await base.OnInitializedAsync();
}
#endregion
#region Private Method NavLinkClickedAsync
private async Task NavLinkClickedAsync()
{
await JsRuntime.InvokeVoidAsync("eval", "document.getElementById('menu-toggler').checked=false;");
}
#endregion
}
}