From 833a1cb9d21a36f0c7ebfea518d8c22639705f34 Mon Sep 17 00:00:00 2001 From: KIT! Date: Tue, 13 Aug 2024 17:07:39 +0200 Subject: [PATCH] Moved all Breadcrumbs to AppBar --- TaikoWebUI/Components/MainLayout.razor | 35 +++++++++++++------ TaikoWebUI/Pages/AccessCode.razor | 3 +- TaikoWebUI/Pages/AccessCode.razor.cs | 18 ++++------ TaikoWebUI/Pages/ChangePassword.razor | 1 + TaikoWebUI/Pages/ChangePassword.razor.cs | 4 +++ TaikoWebUI/Pages/DaniDojo.razor | 4 +-- TaikoWebUI/Pages/DaniDojo.razor.cs | 25 ++++++------- TaikoWebUI/Pages/Dashboard.razor | 10 ++++-- TaikoWebUI/Pages/HighScores.razor | 4 +-- TaikoWebUI/Pages/HighScores.razor.cs | 12 +++---- TaikoWebUI/Pages/Login.razor | 1 + TaikoWebUI/Pages/Login.razor.cs | 4 +++ TaikoWebUI/Pages/PlayHistory.razor | 10 +++--- TaikoWebUI/Pages/PlayHistory.razor.cs | 16 +++++++-- TaikoWebUI/Pages/Profile.razor | 3 +- TaikoWebUI/Pages/Profile.razor.cs | 16 ++++----- TaikoWebUI/Pages/Register.razor | 1 + TaikoWebUI/Pages/Register.razor.cs | 4 +++ TaikoWebUI/Pages/Song.razor | 2 +- TaikoWebUI/Pages/Song.razor.cs | 28 ++++++--------- TaikoWebUI/Pages/SongList.razor | 4 +-- TaikoWebUI/Pages/SongList.razor.cs | 12 +++---- TaikoWebUI/Pages/Users.razor | 2 +- TaikoWebUI/Pages/Users.razor.cs | 4 +++ TaikoWebUI/Program.cs | 1 + .../Services/BreadcrumbsStateContainer.cs | 17 +++++++++ 26 files changed, 139 insertions(+), 102 deletions(-) create mode 100644 TaikoWebUI/Services/BreadcrumbsStateContainer.cs diff --git a/TaikoWebUI/Components/MainLayout.razor b/TaikoWebUI/Components/MainLayout.razor index 2f7bc6c..7040648 100644 --- a/TaikoWebUI/Components/MainLayout.razor +++ b/TaikoWebUI/Components/MainLayout.razor @@ -1,9 +1,13 @@ @inherits LayoutComponentBase @inject Blazored.LocalStorage.ILocalStorageService LocalStorage @inject AuthService AuthService +@inject BreadcrumbsStateContainer BreadcrumbsStateContainer + @using Microsoft.Extensions.Options; @using TaikoWebUI.Settings; + + @@ -11,6 +15,7 @@ + @@ -46,11 +51,14 @@ { title = UiSettings.Value.Title; } - + protected override async Task OnInitializedAsync() { - - + await base.OnInitializedAsync(); + + BreadcrumbsStateContainer.OnChange += StateHasChanged; + + var hasDrawerOpenEntry = await LocalStorage.ContainKeyAsync("drawerOpen"); if (hasDrawerOpenEntry) @@ -73,16 +81,16 @@ } private async Task DrawerToggle() - { - drawerOpen = !drawerOpen; - await LocalStorage.SetItemAsync("drawerOpen", drawerOpen); - } + { + drawerOpen = !drawerOpen; + await LocalStorage.SetItemAsync("drawerOpen", drawerOpen); + } private async Task ToggleDarkMode() - { - isDarkMode = !isDarkMode; - await LocalStorage.SetItemAsync("isDarkMode", isDarkMode); - } + { + isDarkMode = !isDarkMode; + await LocalStorage.SetItemAsync("isDarkMode", isDarkMode); + } private string DarkModeIcon => isDarkMode ? Icons.Material.Filled.BrightnessLow : Icons.Material.Filled.Brightness2; @@ -102,4 +110,9 @@ PrimaryDarken = Colors.Indigo.Accent1, }, }; + + public void Dispose() + { + BreadcrumbsStateContainer.OnChange -= StateHasChanged; + } } \ No newline at end of file diff --git a/TaikoWebUI/Pages/AccessCode.razor b/TaikoWebUI/Pages/AccessCode.razor index 88f26b7..07437f4 100644 --- a/TaikoWebUI/Pages/AccessCode.razor +++ b/TaikoWebUI/Pages/AccessCode.razor @@ -3,6 +3,7 @@ @inject IDialogService DialogService @inject AuthService AuthService @inject NavigationManager NavigationManager +@inject BreadcrumbsStateContainer BreadcrumbsStateContainer @inject Utilities.StringUtil StringUtil; @if (AuthService.LoginRequired && (!AuthService.IsLoggedIn || (AuthService.GetLoggedInBaid() != Baid && !AuthService.IsAdmin))) { @@ -13,8 +14,6 @@ } else { - - @Localizer["Access Codes"] diff --git a/TaikoWebUI/Pages/AccessCode.razor.cs b/TaikoWebUI/Pages/AccessCode.razor.cs index 8c51583..940b50b 100644 --- a/TaikoWebUI/Pages/AccessCode.razor.cs +++ b/TaikoWebUI/Pages/AccessCode.razor.cs @@ -14,8 +14,6 @@ public partial class AccessCode private UserSetting? userSetting; - private readonly List breadcrumbs = new(); - protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); @@ -29,16 +27,12 @@ public partial class AccessCode userSetting = await Client.GetFromJsonAsync($"api/UserSettings/{Baid}"); - if (AuthService.IsLoggedIn && !AuthService.IsAdmin) - { - breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); - } - else - { - 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)); + 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["Access Codes"], href: $"/Users/{Baid}/AccessCode", disabled: false)); + BreadcrumbsStateContainer.NotifyStateChanged(); } private async Task InitializeUser() diff --git a/TaikoWebUI/Pages/ChangePassword.razor b/TaikoWebUI/Pages/ChangePassword.razor index 0bf738e..dbe9c53 100644 --- a/TaikoWebUI/Pages/ChangePassword.razor +++ b/TaikoWebUI/Pages/ChangePassword.razor @@ -2,6 +2,7 @@ @inject IDialogService DialogService @inject AuthService AuthService @inject NavigationManager NavigationManager +@inject BreadcrumbsStateContainer BreadcrumbsStateContainer @page "/ChangePassword" diff --git a/TaikoWebUI/Pages/ChangePassword.razor.cs b/TaikoWebUI/Pages/ChangePassword.razor.cs index 33570a3..99d83be 100644 --- a/TaikoWebUI/Pages/ChangePassword.razor.cs +++ b/TaikoWebUI/Pages/ChangePassword.razor.cs @@ -16,6 +16,10 @@ public partial class ChangePassword { await AuthService.LoginWithAuthToken(); } + + BreadcrumbsStateContainer.breadcrumbs.Clear(); + BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Change Password"], href: "/")); + BreadcrumbsStateContainer.NotifyStateChanged(); } private async Task OnChangePassword() diff --git a/TaikoWebUI/Pages/DaniDojo.razor b/TaikoWebUI/Pages/DaniDojo.razor index d4cde03..7c0a3e8 100644 --- a/TaikoWebUI/Pages/DaniDojo.razor +++ b/TaikoWebUI/Pages/DaniDojo.razor @@ -6,6 +6,7 @@ @inject AuthService AuthService @inject NavigationManager NavigationManager @inject ILocalStorageService LocalStorage +@inject BreadcrumbsStateContainer BreadcrumbsStateContainer @page "/Users/{baid:int}/DaniDojo" @@ -22,8 +23,7 @@ } else { - - @Localizer["Dani Dojo"] + diff --git a/TaikoWebUI/Pages/DaniDojo.razor.cs b/TaikoWebUI/Pages/DaniDojo.razor.cs index 960629f..d5480e0 100644 --- a/TaikoWebUI/Pages/DaniDojo.razor.cs +++ b/TaikoWebUI/Pages/DaniDojo.razor.cs @@ -17,12 +17,10 @@ public partial class DaniDojo private Dictionary musicDetailDictionary = new(); private ImmutableDictionary danMap = ImmutableDictionary.Empty; - private readonly List breadcrumbs = new(); - protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); - + if (AuthService.LoginRequired && !AuthService.IsLoggedIn) { await AuthService.LoginWithAuthToken(); @@ -39,19 +37,16 @@ public partial class DaniDojo SongNameLanguage = await LocalStorage.GetItemAsync("songNameLanguage"); userSetting = await Client.GetFromJsonAsync($"api/UserSettings/{Baid}"); - + musicDetailDictionary = await GameDataService.GetMusicDetailDictionary(); - if (AuthService.IsLoggedIn && !AuthService.IsAdmin) - { - breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); - } - else - { - breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users")); - }; - breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true)); - breadcrumbs.Add(new BreadcrumbItem(Localizer["Dani Dojo"], href: $"/Users/{Baid}/DaniDojo", disabled: false)); + // 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["Dani Dojo"], href: $"/Users/{Baid}/DaniDojo", disabled: false)); + BreadcrumbsStateContainer.NotifyStateChanged(); } private string GetDanClearStateString(DanClearState danClearState) @@ -111,7 +106,7 @@ public partial class DaniDojo private static uint GetSongBestFromData(DanConditionType type, DanBestData data, int songNumber) { songNumber.Throw().IfOutOfRange(0, 2); - + return type switch { DanConditionType.SoulGauge => throw new ArgumentException("Soul gauge should not be here"), diff --git a/TaikoWebUI/Pages/Dashboard.razor b/TaikoWebUI/Pages/Dashboard.razor index 29a5ef6..5cf86b9 100644 --- a/TaikoWebUI/Pages/Dashboard.razor +++ b/TaikoWebUI/Pages/Dashboard.razor @@ -1,15 +1,15 @@ @page "/" -@inject HttpClient Http @using Markdig +@inject HttpClient Http +@inject BreadcrumbsStateContainer BreadcrumbsStateContainer -@Localizer["Dashboard"]
@if (isLoading) { - + } else { @@ -48,5 +48,9 @@ } isLoading = false; + + BreadcrumbsStateContainer.breadcrumbs.Clear(); + BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); + BreadcrumbsStateContainer.NotifyStateChanged(); } } \ No newline at end of file diff --git a/TaikoWebUI/Pages/HighScores.razor b/TaikoWebUI/Pages/HighScores.razor index 9df98eb..846f03e 100644 --- a/TaikoWebUI/Pages/HighScores.razor +++ b/TaikoWebUI/Pages/HighScores.razor @@ -4,13 +4,11 @@ @inject HttpClient Client @inject AuthService AuthService @inject NavigationManager NavigationManager +@inject BreadcrumbsStateContainer BreadcrumbsStateContainer @inject Blazored.LocalStorage.ILocalStorageService LocalStorage @page "/Users/{baid:int}/HighScores" - -@Localizer["High Scores"] - @if (response is null) { diff --git a/TaikoWebUI/Pages/HighScores.razor.cs b/TaikoWebUI/Pages/HighScores.razor.cs index 7a2ceac..8529f3c 100644 --- a/TaikoWebUI/Pages/HighScores.razor.cs +++ b/TaikoWebUI/Pages/HighScores.razor.cs @@ -8,8 +8,6 @@ public partial class HighScores private SongBestResponse? response; private UserSetting? userSetting; private Dictionary> songBestDataMap = new(); - - private readonly List breadcrumbs = new(); private int selectedDifficultyTab; private Dictionary musicDetailDictionary = new(); @@ -51,16 +49,18 @@ public partial class HighScores selectedDifficultyTab = await LocalStorage.GetItemAsync($"highScoresTab"); // Breadcrumbs + BreadcrumbsStateContainer.breadcrumbs.Clear(); if (AuthService.IsLoggedIn && !AuthService.IsAdmin) { - breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); + BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); } 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)); - breadcrumbs.Add(new BreadcrumbItem(Localizer["High Scores"], href: $"/Users/{Baid}/HighScores", disabled: false)); + BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true)); + BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["High Scores"], href: $"/Users/{Baid}/HighScores", disabled: false)); + BreadcrumbsStateContainer.NotifyStateChanged(); } private async Task OnFavoriteToggled(SongBestData data) diff --git a/TaikoWebUI/Pages/Login.razor b/TaikoWebUI/Pages/Login.razor index 5c1fd49..741d27b 100644 --- a/TaikoWebUI/Pages/Login.razor +++ b/TaikoWebUI/Pages/Login.razor @@ -2,6 +2,7 @@ @inject IDialogService DialogService @inject AuthService AuthService @inject NavigationManager NavigationManager +@inject BreadcrumbsStateContainer BreadcrumbsStateContainer @page "/Login" diff --git a/TaikoWebUI/Pages/Login.razor.cs b/TaikoWebUI/Pages/Login.razor.cs index bc4a7e2..218bebb 100644 --- a/TaikoWebUI/Pages/Login.razor.cs +++ b/TaikoWebUI/Pages/Login.razor.cs @@ -14,6 +14,10 @@ public partial class Login { await AuthService.LoginWithAuthToken(); } + + BreadcrumbsStateContainer.breadcrumbs.Clear(); + BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Login"], href: "/Login")); + BreadcrumbsStateContainer.NotifyStateChanged(); } private async Task OnLogin() diff --git a/TaikoWebUI/Pages/PlayHistory.razor b/TaikoWebUI/Pages/PlayHistory.razor index 1882afd..c6d4819 100644 --- a/TaikoWebUI/Pages/PlayHistory.razor +++ b/TaikoWebUI/Pages/PlayHistory.razor @@ -6,12 +6,10 @@ @inject IJSRuntime JsRuntime @inject NavigationManager NavigationManager @inject ILocalStorageService LocalStorage +@inject BreadcrumbsStateContainer BreadcrumbsStateContainer @page "/Users/{baid:int}/PlayHistory" - -@Localizer["Play History"] - @if (response is null) { @@ -62,7 +60,7 @@ -
+
@CultureInfo.CurrentCulture.TextInfo.ToTitleCase(context[0].PlayTime.ToString(Localizer["DateFormat"])) @@ -104,7 +102,7 @@ @songHistoryData.MusicArtist
-
+ @*
-
+
*@ diff --git a/TaikoWebUI/Pages/PlayHistory.razor.cs b/TaikoWebUI/Pages/PlayHistory.razor.cs index c0d29a1..d9bae87 100644 --- a/TaikoWebUI/Pages/PlayHistory.razor.cs +++ b/TaikoWebUI/Pages/PlayHistory.razor.cs @@ -1,5 +1,6 @@ using System.Globalization; using Microsoft.JSInterop; +using SharedProject.Models; namespace TaikoWebUI.Pages; @@ -15,10 +16,9 @@ public partial class PlayHistory private string? songNameLanguage; private SongHistoryResponse? response; + private UserSetting? userSetting; private Dictionary> songHistoryDataMap = new(); - - private readonly List breadcrumbs = new(); private Dictionary musicDetailDictionary = new(); @@ -34,7 +34,17 @@ public partial class PlayHistory response = await Client.GetFromJsonAsync($"api/PlayHistory/{(uint)Baid}"); response.ThrowIfNull(); - + + userSetting = await Client.GetFromJsonAsync($"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("songNameLanguage"); musicDetailDictionary = await GameDataService.GetMusicDetailDictionary(); diff --git a/TaikoWebUI/Pages/Profile.razor b/TaikoWebUI/Pages/Profile.razor index 5b5f8ca..d71b68e 100644 --- a/TaikoWebUI/Pages/Profile.razor +++ b/TaikoWebUI/Pages/Profile.razor @@ -5,6 +5,7 @@ @inject AuthService AuthService @inject IJSRuntime JsRuntime @inject NavigationManager NavigationManager +@inject BreadcrumbsStateContainer BreadcrumbsStateContainer @if (response is not null) { @@ -21,8 +22,6 @@ } else { - - @Localizer["Profile"] diff --git a/TaikoWebUI/Pages/Profile.razor.cs b/TaikoWebUI/Pages/Profile.razor.cs index f27a956..6482792 100644 --- a/TaikoWebUI/Pages/Profile.razor.cs +++ b/TaikoWebUI/Pages/Profile.razor.cs @@ -169,8 +169,6 @@ public partial class Profile "Not Cleared", "Not Full Combo", "Not Donderful Combo" }; - private readonly List breadcrumbs = new(); - private Dictionary> songBestDataMap = new(); private Difficulty highestDifficulty = Difficulty.Easy; @@ -208,17 +206,19 @@ public partial class Profile musicDetailDictionary = await GameDataService.GetMusicDetailDictionary(); + BreadcrumbsStateContainer.breadcrumbs.Clear(); if (AuthService.IsLoggedIn && !AuthService.IsAdmin) { - breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); + BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); } 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)); - breadcrumbs.Add(new BreadcrumbItem(Localizer["Profile"], href: $"/Users/{Baid}/Profile", disabled: false)); - + BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem($"{response.MyDonName}", href: null, disabled: true)); + BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Profile"], href: $"/Users/{Baid}/Profile", disabled: false)); + BreadcrumbsStateContainer.NotifyStateChanged(); + costumeList = await GameDataService.GetCostumeList(); titleDictionary = await GameDataService.GetTitleDictionary(); lockedCostumeDataDictionary = await GameDataService.GetLockedCostumeDataDictionary(); @@ -374,7 +374,7 @@ public partial class Profile // Adjust breadcrumb if name is changed if (response != null) { - breadcrumbs[^2] = new BreadcrumbItem($"{response.MyDonName}", href: null, disabled: true); + BreadcrumbsStateContainer.breadcrumbs[^2] = new BreadcrumbItem($"{response.MyDonName}", href: null, disabled: true); } } diff --git a/TaikoWebUI/Pages/Register.razor b/TaikoWebUI/Pages/Register.razor index 4f00d99..01e4d3c 100644 --- a/TaikoWebUI/Pages/Register.razor +++ b/TaikoWebUI/Pages/Register.razor @@ -1,6 +1,7 @@ @inject IDialogService DialogService @inject AuthService AuthService @inject NavigationManager NavigationManager +@inject BreadcrumbsStateContainer BreadcrumbsStateContainer @page "/Register" diff --git a/TaikoWebUI/Pages/Register.razor.cs b/TaikoWebUI/Pages/Register.razor.cs index 5514ef0..68027fa 100644 --- a/TaikoWebUI/Pages/Register.razor.cs +++ b/TaikoWebUI/Pages/Register.razor.cs @@ -16,6 +16,10 @@ public partial class Register protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); + + BreadcrumbsStateContainer.breadcrumbs.Clear(); + BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Register"], href: "/Register")); + BreadcrumbsStateContainer.NotifyStateChanged(); } private async Task OnRegister() diff --git a/TaikoWebUI/Pages/Song.razor b/TaikoWebUI/Pages/Song.razor index a8b4a34..2dabfbb 100644 --- a/TaikoWebUI/Pages/Song.razor +++ b/TaikoWebUI/Pages/Song.razor @@ -7,6 +7,7 @@ @inject AuthService AuthService @inject NavigationManager NavigationManager @inject ILocalStorageService LocalStorage +@inject BreadcrumbsStateContainer BreadcrumbsStateContainer @if (AuthService.LoginRequired && (!AuthService.IsLoggedIn || (AuthService.GetLoggedInBaid() != Baid && !AuthService.IsAdmin))) { @@ -16,7 +17,6 @@ else { if (response is not null) { - @songTitle @songArtist diff --git a/TaikoWebUI/Pages/Song.razor.cs b/TaikoWebUI/Pages/Song.razor.cs index c447a6a..70e5476 100644 --- a/TaikoWebUI/Pages/Song.razor.cs +++ b/TaikoWebUI/Pages/Song.razor.cs @@ -11,7 +11,6 @@ public partial class Song private UserSetting? userSetting; private SongHistoryResponse? response; private List? songHistoryData; - private readonly List breadcrumbs = new(); private string songTitle = string.Empty; private string songArtist = string.Empty; @@ -19,7 +18,7 @@ public partial class Song protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); - + if (AuthService.LoginRequired && !AuthService.IsLoggedIn) { await AuthService.LoginWithAuthToken(); @@ -32,7 +31,7 @@ public partial class Song // Get user settings userSetting = await Client.GetFromJsonAsync($"api/UserSettings/{Baid}"); - + var musicDetailDictionary = await GameDataService.GetMusicDetailDictionary(); // Get song title and artist @@ -42,21 +41,14 @@ public partial class Song // Breadcrumbs var formattedSongTitle = songTitle; - if (formattedSongTitle.Length > 20) - { - formattedSongTitle = string.Concat(formattedSongTitle.AsSpan(0, 20), "..."); - } + if (formattedSongTitle.Length > 20) formattedSongTitle = string.Concat(formattedSongTitle.AsSpan(0, 20), "..."); - if (AuthService.IsLoggedIn && !AuthService.IsAdmin) - { - breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); - } - else - { - breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users")); - }; - 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)); + 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["Song List"], href: $"/Users/{Baid}/Songs", disabled: false)); + BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(formattedSongTitle, href: $"/Users/{Baid}/Songs/{SongId}", disabled: false)); + BreadcrumbsStateContainer.NotifyStateChanged(); } } \ No newline at end of file diff --git a/TaikoWebUI/Pages/SongList.razor b/TaikoWebUI/Pages/SongList.razor index 8b9f3d7..88b97ac 100644 --- a/TaikoWebUI/Pages/SongList.razor +++ b/TaikoWebUI/Pages/SongList.razor @@ -6,12 +6,10 @@ @inject AuthService AuthService @inject ILocalStorageService LocalStorage @inject NavigationManager NavigationManager +@inject BreadcrumbsStateContainer BreadcrumbsStateContainer @page "/Users/{baid:int}/Songs" - -@Localizer["Song List"] - @if (response is null) { diff --git a/TaikoWebUI/Pages/SongList.razor.cs b/TaikoWebUI/Pages/SongList.razor.cs index d581e3e..aa50ea5 100644 --- a/TaikoWebUI/Pages/SongList.razor.cs +++ b/TaikoWebUI/Pages/SongList.razor.cs @@ -11,8 +11,6 @@ public partial class SongList private SongBestResponse? response; private UserSetting? userSetting; - - private readonly List breadcrumbs = new(); private Dictionary musicDetailDictionary = new(); @@ -38,16 +36,18 @@ public partial class SongList if (best.SongId == song.Value.SongId) song.Value.IsFavorite = best.IsFavorite; + BreadcrumbsStateContainer.breadcrumbs.Clear(); if (AuthService.IsLoggedIn && !AuthService.IsAdmin) { - breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); + BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); } 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)); - breadcrumbs.Add(new BreadcrumbItem(Localizer["Song List"], href: $"/Users/{Baid}/Songs", disabled: false)); + BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true)); + BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Song List"], href: $"/Users/{Baid}/Songs", disabled: false)); + BreadcrumbsStateContainer.NotifyStateChanged(); } private bool FilterSongs(MusicDetail musicDetail) diff --git a/TaikoWebUI/Pages/Users.razor b/TaikoWebUI/Pages/Users.razor index ac087c7..80dbdc9 100644 --- a/TaikoWebUI/Pages/Users.razor +++ b/TaikoWebUI/Pages/Users.razor @@ -1,12 +1,12 @@ @inject HttpClient Client @inject AuthService AuthService @inject NavigationManager NavigationManager +@inject BreadcrumbsStateContainer BreadcrumbsStateContainer @using TaikoWebUI.Components; @page "/Users" -@Localizer["Users"] @if (!AuthService.LoginRequired || (AuthService.LoginRequired && AuthService.IsAdmin)) { diff --git a/TaikoWebUI/Pages/Users.razor.cs b/TaikoWebUI/Pages/Users.razor.cs index c6729f8..718ee73 100644 --- a/TaikoWebUI/Pages/Users.razor.cs +++ b/TaikoWebUI/Pages/Users.razor.cs @@ -32,6 +32,10 @@ public partial class Users { await GetUsersData(); } + + BreadcrumbsStateContainer.breadcrumbs.Clear(); + BreadcrumbsStateContainer.breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users")); + BreadcrumbsStateContainer.NotifyStateChanged(); } private async Task OnPageChange(int page) diff --git a/TaikoWebUI/Program.cs b/TaikoWebUI/Program.cs index f23faad..1f9de19 100644 --- a/TaikoWebUI/Program.cs +++ b/TaikoWebUI/Program.cs @@ -35,6 +35,7 @@ builder.Services.AddLocalization(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); +builder.Services.AddSingleton(); builder.Services.AddBlazoredLocalStorage(); var host = builder.Build(); diff --git a/TaikoWebUI/Services/BreadcrumbsStateContainer.cs b/TaikoWebUI/Services/BreadcrumbsStateContainer.cs new file mode 100644 index 0000000..a27e44d --- /dev/null +++ b/TaikoWebUI/Services/BreadcrumbsStateContainer.cs @@ -0,0 +1,17 @@ +namespace TaikoWebUI.Services +{ + public class BreadcrumbsStateContainer + { + public List breadcrumbs = new(); + + public event Action? OnChange; + + public void SetBreadcrumbs(List _breadcrumbs) + { + breadcrumbs = _breadcrumbs; + NotifyStateChanged(); + } + + public void NotifyStateChanged() => OnChange?.Invoke(); + } +}