Added admin page navigation
This commit is contained in:
46
src/HopFrame.Web/Components/Layout/HopFrameNavigation.razor
Normal file
46
src/HopFrame.Web/Components/Layout/HopFrameNavigation.razor
Normal file
@@ -0,0 +1,46 @@
|
||||
@using System.Text
|
||||
@using HopFrame.Core.Config
|
||||
@using HopFrame.Core.Services
|
||||
<FluentHeader Class="hopframe-header">
|
||||
<a href="/admin" style="text-decoration: none; color: @Color.Neutral.ToAttributeValue()">HopFrame</a>
|
||||
<FluentSpacer/>
|
||||
|
||||
@if (Config.DisplayUserInfo) {
|
||||
<FluentPersona Name="@_displayName" Initials="@_initials" ImageSize="32px" TextPosition="TextPosition.Start"/>
|
||||
}
|
||||
|
||||
</FluentHeader>
|
||||
|
||||
@inject HopFrameConfig Config
|
||||
@inject IServiceProvider Provider
|
||||
|
||||
@code {
|
||||
|
||||
private string? _displayName;
|
||||
private string? _initials;
|
||||
|
||||
protected override async Task OnInitializedAsync() {
|
||||
if (Config.DisplayUserInfo) {
|
||||
var handler = Provider.GetService(Config.AuthHandler!) as IHopFrameAuthHandler;
|
||||
_displayName = await handler!.GetCurrentUserDisplayNameAsync();
|
||||
_initials = GetInitials(_displayName);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetInitials(string input) {
|
||||
if (string.IsNullOrEmpty(input))
|
||||
return string.Empty;
|
||||
|
||||
StringBuilder initials = new StringBuilder();
|
||||
string[] words = input.Split([' ', '.', '_'], StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (string word in words) {
|
||||
if (!string.IsNullOrEmpty(word) && char.IsLetter(word[0]))
|
||||
initials.Append(word[0]);
|
||||
}
|
||||
|
||||
return initials.ToString().ToUpper();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user