1
0
mirror of synced 2025-01-19 00:04:05 +01:00

Moved all Breadcrumbs to AppBar

This commit is contained in:
Farewell_ 2024-08-13 17:07:39 +02:00
parent a5ba20c365
commit 833a1cb9d2
26 changed files with 139 additions and 102 deletions

View File

@ -1,9 +1,13 @@
@inherits LayoutComponentBase @inherits LayoutComponentBase
@inject Blazored.LocalStorage.ILocalStorageService LocalStorage @inject Blazored.LocalStorage.ILocalStorageService LocalStorage
@inject AuthService AuthService @inject AuthService AuthService
@inject BreadcrumbsStateContainer BreadcrumbsStateContainer
@using Microsoft.Extensions.Options; @using Microsoft.Extensions.Options;
@using TaikoWebUI.Settings; @using TaikoWebUI.Settings;
<MudThemeProvider IsDarkMode="@isDarkMode" Theme="@taikoWebUiTheme" /> <MudThemeProvider IsDarkMode="@isDarkMode" Theme="@taikoWebUiTheme" />
<MudDialogProvider /> <MudDialogProvider />
<MudSnackbarProvider /> <MudSnackbarProvider />
@ -11,6 +15,7 @@
<MudLayout> <MudLayout>
<MudAppBar Elevation="0"> <MudAppBar Elevation="0">
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="DrawerToggle" Size="Size.Small" /> <MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="DrawerToggle" Size="Size.Small" />
<MudBreadcrumbs Items="BreadcrumbsStateContainer.breadcrumbs" Class="p-0"></MudBreadcrumbs>
<MudSpacer /> <MudSpacer />
<MudStack Spacing="3" Row="true"> <MudStack Spacing="3" Row="true">
<LanguageToggle /> <LanguageToggle />
@ -46,11 +51,14 @@
{ {
title = UiSettings.Value.Title; title = UiSettings.Value.Title;
} }
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
await base.OnInitializedAsync();
BreadcrumbsStateContainer.OnChange += StateHasChanged;
var hasDrawerOpenEntry = await LocalStorage.ContainKeyAsync("drawerOpen"); var hasDrawerOpenEntry = await LocalStorage.ContainKeyAsync("drawerOpen");
if (hasDrawerOpenEntry) if (hasDrawerOpenEntry)
@ -73,16 +81,16 @@
} }
private async Task DrawerToggle() private async Task DrawerToggle()
{ {
drawerOpen = !drawerOpen; drawerOpen = !drawerOpen;
await LocalStorage.SetItemAsync("drawerOpen", drawerOpen); await LocalStorage.SetItemAsync("drawerOpen", drawerOpen);
} }
private async Task ToggleDarkMode() private async Task ToggleDarkMode()
{ {
isDarkMode = !isDarkMode; isDarkMode = !isDarkMode;
await LocalStorage.SetItemAsync("isDarkMode", isDarkMode); await LocalStorage.SetItemAsync("isDarkMode", isDarkMode);
} }
private string DarkModeIcon => isDarkMode ? Icons.Material.Filled.BrightnessLow : Icons.Material.Filled.Brightness2; private string DarkModeIcon => isDarkMode ? Icons.Material.Filled.BrightnessLow : Icons.Material.Filled.Brightness2;
@ -102,4 +110,9 @@
PrimaryDarken = Colors.Indigo.Accent1, PrimaryDarken = Colors.Indigo.Accent1,
}, },
}; };
public void Dispose()
{
BreadcrumbsStateContainer.OnChange -= StateHasChanged;
}
} }

View File

@ -3,6 +3,7 @@
@inject IDialogService DialogService @inject IDialogService DialogService
@inject AuthService AuthService @inject AuthService AuthService
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject BreadcrumbsStateContainer BreadcrumbsStateContainer
@inject Utilities.StringUtil StringUtil; @inject Utilities.StringUtil StringUtil;
@if (AuthService.LoginRequired && (!AuthService.IsLoggedIn || (AuthService.GetLoggedInBaid() != Baid && !AuthService.IsAdmin))) { @if (AuthService.LoginRequired && (!AuthService.IsLoggedIn || (AuthService.GetLoggedInBaid() != Baid && !AuthService.IsAdmin))) {
@ -13,8 +14,6 @@
<MudProgressCircular Indeterminate="true" Size="Size.Large" Color="Color.Primary" /> <MudProgressCircular Indeterminate="true" Size="Size.Large" Color="Color.Primary" />
</MudContainer> </MudContainer>
} else { } else {
<MudBreadcrumbs Items="breadcrumbs" Class="p-0 mb-2"></MudBreadcrumbs>
<MudText Typo="Typo.h4">@Localizer["Access Codes"]</MudText>
<MudGrid Class="my-4 pb-10"> <MudGrid Class="my-4 pb-10">
<MudItem xs="12"> <MudItem xs="12">
<MudCard Outlined="true" Class="mb-6"> <MudCard Outlined="true" Class="mb-6">

View File

@ -14,8 +14,6 @@ public partial class AccessCode
private UserSetting? userSetting; private UserSetting? userSetting;
private readonly List<BreadcrumbItem> breadcrumbs = new();
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
await base.OnInitializedAsync(); await base.OnInitializedAsync();
@ -29,16 +27,12 @@ public partial class AccessCode
userSetting = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}"); userSetting = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}");
if (AuthService.IsLoggedIn && !AuthService.IsAdmin) BreadcrumbsStateContainer.breadcrumbs.Clear();
{ if (AuthService.IsLoggedIn && !AuthService.IsAdmin) BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/"));
breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); else BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
} BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true));
else BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Access Codes"], href: $"/Users/{Baid}/AccessCode", disabled: false));
{ BreadcrumbsStateContainer.NotifyStateChanged();
breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
}
breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true));
breadcrumbs.Add(new BreadcrumbItem(Localizer["Access Codes"], href: $"/Users/{Baid}/AccessCode", disabled: false));
} }
private async Task InitializeUser() private async Task InitializeUser()

View File

@ -2,6 +2,7 @@
@inject IDialogService DialogService @inject IDialogService DialogService
@inject AuthService AuthService @inject AuthService AuthService
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject BreadcrumbsStateContainer BreadcrumbsStateContainer
@page "/ChangePassword" @page "/ChangePassword"

View File

@ -16,6 +16,10 @@ public partial class ChangePassword
{ {
await AuthService.LoginWithAuthToken(); await AuthService.LoginWithAuthToken();
} }
BreadcrumbsStateContainer.breadcrumbs.Clear();
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Change Password"], href: "/"));
BreadcrumbsStateContainer.NotifyStateChanged();
} }
private async Task OnChangePassword() private async Task OnChangePassword()

View File

@ -6,6 +6,7 @@
@inject AuthService AuthService @inject AuthService AuthService
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject ILocalStorageService LocalStorage @inject ILocalStorageService LocalStorage
@inject BreadcrumbsStateContainer BreadcrumbsStateContainer
@page "/Users/{baid:int}/DaniDojo" @page "/Users/{baid:int}/DaniDojo"
@ -22,8 +23,7 @@
} }
else else
{ {
<MudBreadcrumbs Items="breadcrumbs" Class="p-0 mb-2"></MudBreadcrumbs>
<MudText Typo="Typo.h4">@Localizer["Dani Dojo"]</MudText>
<MudGrid Class="my-4 pb-10"> <MudGrid Class="my-4 pb-10">
<MudItem xs="12"> <MudItem xs="12">
<MudPaper Elevation="0" Outlined="true"> <MudPaper Elevation="0" Outlined="true">

View File

@ -17,12 +17,10 @@ public partial class DaniDojo
private Dictionary<uint, MusicDetail> musicDetailDictionary = new(); private Dictionary<uint, MusicDetail> musicDetailDictionary = new();
private ImmutableDictionary<uint, DanData> danMap = ImmutableDictionary<uint, DanData>.Empty; private ImmutableDictionary<uint, DanData> danMap = ImmutableDictionary<uint, DanData>.Empty;
private readonly List<BreadcrumbItem> breadcrumbs = new();
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
await base.OnInitializedAsync(); await base.OnInitializedAsync();
if (AuthService.LoginRequired && !AuthService.IsLoggedIn) if (AuthService.LoginRequired && !AuthService.IsLoggedIn)
{ {
await AuthService.LoginWithAuthToken(); await AuthService.LoginWithAuthToken();
@ -39,19 +37,16 @@ public partial class DaniDojo
SongNameLanguage = await LocalStorage.GetItemAsync<string>("songNameLanguage"); SongNameLanguage = await LocalStorage.GetItemAsync<string>("songNameLanguage");
userSetting = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}"); userSetting = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}");
musicDetailDictionary = await GameDataService.GetMusicDetailDictionary(); musicDetailDictionary = await GameDataService.GetMusicDetailDictionary();
if (AuthService.IsLoggedIn && !AuthService.IsAdmin) // Breadcrumbs
{ BreadcrumbsStateContainer.breadcrumbs.Clear();
breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); if (AuthService.IsLoggedIn && !AuthService.IsAdmin) BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/"));
} else BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
else BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true));
{ BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dani Dojo"], href: $"/Users/{Baid}/DaniDojo", disabled: false));
breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users")); BreadcrumbsStateContainer.NotifyStateChanged();
};
breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true));
breadcrumbs.Add(new BreadcrumbItem(Localizer["Dani Dojo"], href: $"/Users/{Baid}/DaniDojo", disabled: false));
} }
private string GetDanClearStateString(DanClearState danClearState) private string GetDanClearStateString(DanClearState danClearState)
@ -111,7 +106,7 @@ public partial class DaniDojo
private static uint GetSongBestFromData(DanConditionType type, DanBestData data, int songNumber) private static uint GetSongBestFromData(DanConditionType type, DanBestData data, int songNumber)
{ {
songNumber.Throw().IfOutOfRange(0, 2); songNumber.Throw().IfOutOfRange(0, 2);
return type switch return type switch
{ {
DanConditionType.SoulGauge => throw new ArgumentException("Soul gauge should not be here"), DanConditionType.SoulGauge => throw new ArgumentException("Soul gauge should not be here"),

View File

@ -1,15 +1,15 @@
@page "/" @page "/"
@inject HttpClient Http
@using Markdig @using Markdig
@inject HttpClient Http
@inject BreadcrumbsStateContainer BreadcrumbsStateContainer
<MudText Typo="Typo.h4">@Localizer["Dashboard"]</MudText>
<MudGrid Class="my-8"> <MudGrid Class="my-8">
<MudItem xs="12"> <MudItem xs="12">
<MudPaper Elevation="0" Outlined="true"> <MudPaper Elevation="0" Outlined="true">
<div class="markdown-container"> <div class="markdown-container">
@if (isLoading) @if (isLoading)
{ {
<MudCircularProgress /> <MudProgressCircular/>
} }
else else
{ {
@ -48,5 +48,9 @@
} }
isLoading = false; isLoading = false;
BreadcrumbsStateContainer.breadcrumbs.Clear();
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/"));
BreadcrumbsStateContainer.NotifyStateChanged();
} }
} }

View File

@ -4,13 +4,11 @@
@inject HttpClient Client @inject HttpClient Client
@inject AuthService AuthService @inject AuthService AuthService
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject BreadcrumbsStateContainer BreadcrumbsStateContainer
@inject Blazored.LocalStorage.ILocalStorageService LocalStorage @inject Blazored.LocalStorage.ILocalStorageService LocalStorage
@page "/Users/{baid:int}/HighScores" @page "/Users/{baid:int}/HighScores"
<MudBreadcrumbs Items="breadcrumbs" Class="p-0 mb-2"></MudBreadcrumbs>
<MudText Typo="Typo.h4">@Localizer["High Scores"]</MudText>
<MudGrid Class="my-8"> <MudGrid Class="my-8">
@if (response is null) @if (response is null)
{ {

View File

@ -8,8 +8,6 @@ public partial class HighScores
private SongBestResponse? response; private SongBestResponse? response;
private UserSetting? userSetting; private UserSetting? userSetting;
private Dictionary<Difficulty, List<SongBestData>> songBestDataMap = new(); private Dictionary<Difficulty, List<SongBestData>> songBestDataMap = new();
private readonly List<BreadcrumbItem> breadcrumbs = new();
private int selectedDifficultyTab; private int selectedDifficultyTab;
private Dictionary<uint, MusicDetail> musicDetailDictionary = new(); private Dictionary<uint, MusicDetail> musicDetailDictionary = new();
@ -51,16 +49,18 @@ public partial class HighScores
selectedDifficultyTab = await LocalStorage.GetItemAsync<int>($"highScoresTab"); selectedDifficultyTab = await LocalStorage.GetItemAsync<int>($"highScoresTab");
// Breadcrumbs // Breadcrumbs
BreadcrumbsStateContainer.breadcrumbs.Clear();
if (AuthService.IsLoggedIn && !AuthService.IsAdmin) if (AuthService.IsLoggedIn && !AuthService.IsAdmin)
{ {
breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/"));
} }
else else
{ {
breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users")); BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
}; };
breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true)); BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true));
breadcrumbs.Add(new BreadcrumbItem(Localizer["High Scores"], href: $"/Users/{Baid}/HighScores", disabled: false)); BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["High Scores"], href: $"/Users/{Baid}/HighScores", disabled: false));
BreadcrumbsStateContainer.NotifyStateChanged();
} }
private async Task OnFavoriteToggled(SongBestData data) private async Task OnFavoriteToggled(SongBestData data)

View File

@ -2,6 +2,7 @@
@inject IDialogService DialogService @inject IDialogService DialogService
@inject AuthService AuthService @inject AuthService AuthService
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject BreadcrumbsStateContainer BreadcrumbsStateContainer
@page "/Login" @page "/Login"

View File

@ -14,6 +14,10 @@ public partial class Login
{ {
await AuthService.LoginWithAuthToken(); await AuthService.LoginWithAuthToken();
} }
BreadcrumbsStateContainer.breadcrumbs.Clear();
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Login"], href: "/Login"));
BreadcrumbsStateContainer.NotifyStateChanged();
} }
private async Task OnLogin() private async Task OnLogin()

View File

@ -6,12 +6,10 @@
@inject IJSRuntime JsRuntime @inject IJSRuntime JsRuntime
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject ILocalStorageService LocalStorage @inject ILocalStorageService LocalStorage
@inject BreadcrumbsStateContainer BreadcrumbsStateContainer
@page "/Users/{baid:int}/PlayHistory" @page "/Users/{baid:int}/PlayHistory"
<MudBreadcrumbs Items="breadcrumbs" Class="p-0 mb-2"></MudBreadcrumbs>
<MudText Typo="Typo.h4">@Localizer["Play History"]</MudText>
<MudGrid Class="my-8"> <MudGrid Class="my-8">
@if (response is null) @if (response is null)
{ {
@ -62,7 +60,7 @@
</MudTh> </MudTh>
</HeaderContent> </HeaderContent>
<RowTemplate> <RowTemplate>
<div class="mt-4 mb-1"> <div class="mt-4 mb-1 ml-4">
<MudText Typo="Typo.subtitle2"> <MudText Typo="Typo.subtitle2">
@CultureInfo.CurrentCulture.TextInfo.ToTitleCase(context[0].PlayTime.ToString(Localizer["DateFormat"])) @CultureInfo.CurrentCulture.TextInfo.ToTitleCase(context[0].PlayTime.ToString(Localizer["DateFormat"]))
</MudText> </MudText>
@ -104,7 +102,7 @@
<MudText Typo="Typo.caption">@songHistoryData.MusicArtist</MudText> <MudText Typo="Typo.caption">@songHistoryData.MusicArtist</MudText>
</a> </a>
</div> </div>
<div> @* <div>
<MudToggleIconButton Toggled="@songHistoryData.IsFavorite" <MudToggleIconButton Toggled="@songHistoryData.IsFavorite"
ToggledChanged="@(async () => await OnFavoriteToggled(songHistoryData))" ToggledChanged="@(async () => await OnFavoriteToggled(songHistoryData))"
Icon="@Icons.Material.Filled.FavoriteBorder" Color="@Color.Secondary" Icon="@Icons.Material.Filled.FavoriteBorder" Color="@Color.Secondary"
@ -112,7 +110,7 @@
Size="Size.Small" Size="Size.Small"
ToggledSize="Size.Small" ToggledSize="Size.Small"
Title="Add to favorites" ToggledTitle="Remove from favorites" /> Title="Add to favorites" ToggledTitle="Remove from favorites" />
</div> </div> *@
</MudStack> </MudStack>
</MudTd> </MudTd>

View File

@ -1,5 +1,6 @@
using System.Globalization; using System.Globalization;
using Microsoft.JSInterop; using Microsoft.JSInterop;
using SharedProject.Models;
namespace TaikoWebUI.Pages; namespace TaikoWebUI.Pages;
@ -15,10 +16,9 @@ public partial class PlayHistory
private string? songNameLanguage; private string? songNameLanguage;
private SongHistoryResponse? response; private SongHistoryResponse? response;
private UserSetting? userSetting;
private Dictionary<DateTime, List<SongHistoryData>> songHistoryDataMap = new(); private Dictionary<DateTime, List<SongHistoryData>> songHistoryDataMap = new();
private readonly List<BreadcrumbItem> breadcrumbs = new();
private Dictionary<uint, MusicDetail> musicDetailDictionary = new(); private Dictionary<uint, MusicDetail> musicDetailDictionary = new();
@ -34,7 +34,17 @@ public partial class PlayHistory
response = await Client.GetFromJsonAsync<SongHistoryResponse>($"api/PlayHistory/{(uint)Baid}"); response = await Client.GetFromJsonAsync<SongHistoryResponse>($"api/PlayHistory/{(uint)Baid}");
response.ThrowIfNull(); response.ThrowIfNull();
userSetting = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}");
//breadcrumbs
BreadcrumbsStateContainer.breadcrumbs.Clear();
if (AuthService.IsLoggedIn && !AuthService.IsAdmin) BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/"));
else BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true));
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Play History"], href: $"/Users/{Baid}/PlayHistory", disabled: false));
BreadcrumbsStateContainer.NotifyStateChanged();
songNameLanguage = await LocalStorage.GetItemAsync<string>("songNameLanguage"); songNameLanguage = await LocalStorage.GetItemAsync<string>("songNameLanguage");
musicDetailDictionary = await GameDataService.GetMusicDetailDictionary(); musicDetailDictionary = await GameDataService.GetMusicDetailDictionary();

View File

@ -5,6 +5,7 @@
@inject AuthService AuthService @inject AuthService AuthService
@inject IJSRuntime JsRuntime @inject IJSRuntime JsRuntime
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject BreadcrumbsStateContainer BreadcrumbsStateContainer
@if (response is not null) @if (response is not null)
{ {
@ -21,8 +22,6 @@
} }
else else
{ {
<MudBreadcrumbs Items="breadcrumbs" Class="p-0 mb-2"></MudBreadcrumbs>
<MudText Typo="Typo.h4">@Localizer["Profile"]</MudText>
<MudGrid Class="my-4 pb-10"> <MudGrid Class="my-4 pb-10">
<MudItem xs="12" md="8"> <MudItem xs="12" md="8">
<MudPaper Elevation="0" Outlined="true"> <MudPaper Elevation="0" Outlined="true">

View File

@ -169,8 +169,6 @@ public partial class Profile
"Not Cleared", "Not Full Combo", "Not Donderful Combo" "Not Cleared", "Not Full Combo", "Not Donderful Combo"
}; };
private readonly List<BreadcrumbItem> breadcrumbs = new();
private Dictionary<Difficulty, List<SongBestData>> songBestDataMap = new(); private Dictionary<Difficulty, List<SongBestData>> songBestDataMap = new();
private Difficulty highestDifficulty = Difficulty.Easy; private Difficulty highestDifficulty = Difficulty.Easy;
@ -208,17 +206,19 @@ public partial class Profile
musicDetailDictionary = await GameDataService.GetMusicDetailDictionary(); musicDetailDictionary = await GameDataService.GetMusicDetailDictionary();
BreadcrumbsStateContainer.breadcrumbs.Clear();
if (AuthService.IsLoggedIn && !AuthService.IsAdmin) if (AuthService.IsLoggedIn && !AuthService.IsAdmin)
{ {
breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/"));
} }
else else
{ {
breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users")); BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
} }
breadcrumbs.Add(new BreadcrumbItem($"{response.MyDonName}", href: null, disabled: true)); BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem($"{response.MyDonName}", href: null, disabled: true));
breadcrumbs.Add(new BreadcrumbItem(Localizer["Profile"], href: $"/Users/{Baid}/Profile", disabled: false)); BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Profile"], href: $"/Users/{Baid}/Profile", disabled: false));
BreadcrumbsStateContainer.NotifyStateChanged();
costumeList = await GameDataService.GetCostumeList(); costumeList = await GameDataService.GetCostumeList();
titleDictionary = await GameDataService.GetTitleDictionary(); titleDictionary = await GameDataService.GetTitleDictionary();
lockedCostumeDataDictionary = await GameDataService.GetLockedCostumeDataDictionary(); lockedCostumeDataDictionary = await GameDataService.GetLockedCostumeDataDictionary();
@ -374,7 +374,7 @@ public partial class Profile
// Adjust breadcrumb if name is changed // Adjust breadcrumb if name is changed
if (response != null) if (response != null)
{ {
breadcrumbs[^2] = new BreadcrumbItem($"{response.MyDonName}", href: null, disabled: true); BreadcrumbsStateContainer.breadcrumbs[^2] = new BreadcrumbItem($"{response.MyDonName}", href: null, disabled: true);
} }
} }

View File

@ -1,6 +1,7 @@
@inject IDialogService DialogService @inject IDialogService DialogService
@inject AuthService AuthService @inject AuthService AuthService
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject BreadcrumbsStateContainer BreadcrumbsStateContainer
@page "/Register" @page "/Register"

View File

@ -16,6 +16,10 @@ public partial class Register
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
await base.OnInitializedAsync(); await base.OnInitializedAsync();
BreadcrumbsStateContainer.breadcrumbs.Clear();
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Register"], href: "/Register"));
BreadcrumbsStateContainer.NotifyStateChanged();
} }
private async Task OnRegister() private async Task OnRegister()

View File

@ -7,6 +7,7 @@
@inject AuthService AuthService @inject AuthService AuthService
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject ILocalStorageService LocalStorage @inject ILocalStorageService LocalStorage
@inject BreadcrumbsStateContainer BreadcrumbsStateContainer
@if (AuthService.LoginRequired && (!AuthService.IsLoggedIn || (AuthService.GetLoggedInBaid() != Baid && !AuthService.IsAdmin))) @if (AuthService.LoginRequired && (!AuthService.IsLoggedIn || (AuthService.GetLoggedInBaid() != Baid && !AuthService.IsAdmin)))
{ {
@ -16,7 +17,6 @@ else
{ {
if (response is not null) if (response is not null)
{ {
<MudBreadcrumbs Items="breadcrumbs" Class="p-0 mb-3"></MudBreadcrumbs>
<MudText Typo="Typo.h5">@songTitle</MudText> <MudText Typo="Typo.h5">@songTitle</MudText>
<MudText Typo="Typo.body2">@songArtist</MudText> <MudText Typo="Typo.body2">@songArtist</MudText>
<MudGrid Class="my-4 pb-10"> <MudGrid Class="my-4 pb-10">

View File

@ -11,7 +11,6 @@ public partial class Song
private UserSetting? userSetting; private UserSetting? userSetting;
private SongHistoryResponse? response; private SongHistoryResponse? response;
private List<SongHistoryData>? songHistoryData; private List<SongHistoryData>? songHistoryData;
private readonly List<BreadcrumbItem> breadcrumbs = new();
private string songTitle = string.Empty; private string songTitle = string.Empty;
private string songArtist = string.Empty; private string songArtist = string.Empty;
@ -19,7 +18,7 @@ public partial class Song
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
await base.OnInitializedAsync(); await base.OnInitializedAsync();
if (AuthService.LoginRequired && !AuthService.IsLoggedIn) if (AuthService.LoginRequired && !AuthService.IsLoggedIn)
{ {
await AuthService.LoginWithAuthToken(); await AuthService.LoginWithAuthToken();
@ -32,7 +31,7 @@ public partial class Song
// Get user settings // Get user settings
userSetting = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}"); userSetting = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}");
var musicDetailDictionary = await GameDataService.GetMusicDetailDictionary(); var musicDetailDictionary = await GameDataService.GetMusicDetailDictionary();
// Get song title and artist // Get song title and artist
@ -42,21 +41,14 @@ public partial class Song
// Breadcrumbs // Breadcrumbs
var formattedSongTitle = songTitle; var formattedSongTitle = songTitle;
if (formattedSongTitle.Length > 20) if (formattedSongTitle.Length > 20) formattedSongTitle = string.Concat(formattedSongTitle.AsSpan(0, 20), "...");
{
formattedSongTitle = string.Concat(formattedSongTitle.AsSpan(0, 20), "...");
}
if (AuthService.IsLoggedIn && !AuthService.IsAdmin) BreadcrumbsStateContainer.breadcrumbs.Clear();
{ if (AuthService.IsLoggedIn && !AuthService.IsAdmin) BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/"));
breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); else BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
} BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true));
else BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Song List"], href: $"/Users/{Baid}/Songs", disabled: false));
{ BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(formattedSongTitle, href: $"/Users/{Baid}/Songs/{SongId}", disabled: false));
breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users")); BreadcrumbsStateContainer.NotifyStateChanged();
};
breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true));
breadcrumbs.Add(new BreadcrumbItem(Localizer["Song List"], href: $"/Users/{Baid}/Songs", disabled: false));
breadcrumbs.Add(new BreadcrumbItem(formattedSongTitle, href: $"/Users/{Baid}/Songs/{SongId}", disabled: false));
} }
} }

View File

@ -6,12 +6,10 @@
@inject AuthService AuthService @inject AuthService AuthService
@inject ILocalStorageService LocalStorage @inject ILocalStorageService LocalStorage
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject BreadcrumbsStateContainer BreadcrumbsStateContainer
@page "/Users/{baid:int}/Songs" @page "/Users/{baid:int}/Songs"
<MudBreadcrumbs Items="breadcrumbs" Class="p-0 mb-2"></MudBreadcrumbs>
<MudText Typo="Typo.h4">@Localizer["Song List"]</MudText>
<MudGrid Class="my-8"> <MudGrid Class="my-8">
@if (response is null) @if (response is null)
{ {

View File

@ -11,8 +11,6 @@ public partial class SongList
private SongBestResponse? response; private SongBestResponse? response;
private UserSetting? userSetting; private UserSetting? userSetting;
private readonly List<BreadcrumbItem> breadcrumbs = new();
private Dictionary<uint, MusicDetail> musicDetailDictionary = new(); private Dictionary<uint, MusicDetail> musicDetailDictionary = new();
@ -38,16 +36,18 @@ public partial class SongList
if (best.SongId == song.Value.SongId) if (best.SongId == song.Value.SongId)
song.Value.IsFavorite = best.IsFavorite; song.Value.IsFavorite = best.IsFavorite;
BreadcrumbsStateContainer.breadcrumbs.Clear();
if (AuthService.IsLoggedIn && !AuthService.IsAdmin) if (AuthService.IsLoggedIn && !AuthService.IsAdmin)
{ {
breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/"));
} }
else else
{ {
breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users")); BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
}; };
breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true)); BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true));
breadcrumbs.Add(new BreadcrumbItem(Localizer["Song List"], href: $"/Users/{Baid}/Songs", disabled: false)); BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Song List"], href: $"/Users/{Baid}/Songs", disabled: false));
BreadcrumbsStateContainer.NotifyStateChanged();
} }
private bool FilterSongs(MusicDetail musicDetail) private bool FilterSongs(MusicDetail musicDetail)

View File

@ -1,12 +1,12 @@
@inject HttpClient Client @inject HttpClient Client
@inject AuthService AuthService @inject AuthService AuthService
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject BreadcrumbsStateContainer BreadcrumbsStateContainer
@using TaikoWebUI.Components; @using TaikoWebUI.Components;
@page "/Users" @page "/Users"
<MudText Typo="Typo.h4">@Localizer["Users"]</MudText>
<MudGrid Class="my-8"> <MudGrid Class="my-8">
@if (!AuthService.LoginRequired || (AuthService.LoginRequired && AuthService.IsAdmin)) { @if (!AuthService.LoginRequired || (AuthService.LoginRequired && AuthService.IsAdmin)) {
<MudItem xs="12"> <MudItem xs="12">

View File

@ -32,6 +32,10 @@ public partial class Users
{ {
await GetUsersData(); await GetUsersData();
} }
BreadcrumbsStateContainer.breadcrumbs.Clear();
BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users"));
BreadcrumbsStateContainer.NotifyStateChanged();
} }
private async Task OnPageChange(int page) private async Task OnPageChange(int page)

View File

@ -35,6 +35,7 @@ builder.Services.AddLocalization();
builder.Services.AddSingleton<MudLocalizer, ResXMudLocalizer>(); builder.Services.AddSingleton<MudLocalizer, ResXMudLocalizer>();
builder.Services.AddSingleton<ScoreUtils>(); builder.Services.AddSingleton<ScoreUtils>();
builder.Services.AddSingleton<StringUtil>(); builder.Services.AddSingleton<StringUtil>();
builder.Services.AddSingleton<BreadcrumbsStateContainer>();
builder.Services.AddBlazoredLocalStorage(); builder.Services.AddBlazoredLocalStorage();
var host = builder.Build(); var host = builder.Build();

View File

@ -0,0 +1,17 @@
namespace TaikoWebUI.Services
{
public class BreadcrumbsStateContainer
{
public List<BreadcrumbItem> breadcrumbs = new();
public event Action? OnChange;
public void SetBreadcrumbs(List<BreadcrumbItem> _breadcrumbs)
{
breadcrumbs = _breadcrumbs;
NotifyStateChanged();
}
public void NotifyStateChanged() => OnChange?.Invoke();
}
}