1
0
mirror of synced 2024-11-15 02:47:35 +01:00

Retain active high score difficulty tab

* The difficulty will no longer reset to Easy when navigating away from the High Scores page.

* Uses local storage to store the selected difficulty tab so you don't have to select it every time.
This commit is contained in:
shiibe 2024-03-26 23:08:12 -04:00
parent 10794f95fa
commit 61812406b8
6 changed files with 28 additions and 9 deletions

View File

@ -3,6 +3,7 @@
@inject LoginService LoginService
@inject IJSRuntime JSRuntime
@inject NavigationManager NavigationManager
@inject Blazored.LocalStorage.ILocalStorageService localStorage
@using TaikoWebUI.Utilities;
@page "/Users/{baid:int}/HighScores"
@ -36,7 +37,7 @@
else
{
<MudItem xs="12">
<MudTabs Elevation="0" Border="true" Rounded="true" ApplyEffectsToContainer="true" Outlined="true" Class="mb-10">
<MudTabs Elevation="0" Border="true" Rounded="true" ApplyEffectsToContainer="true" Outlined="true" Class="mb-10" ActivePanelIndexChanged="@(async (index) => await OnTabChanged(index))" ActivePanelIndex="@selectedDifficultyTab">
@foreach (var difficulty in Enum.GetValues<Difficulty>())
{
@if (difficulty is not Difficulty.None)

View File

@ -13,10 +13,10 @@ public partial class HighScores
private SongBestResponse? response;
private UserSetting? userSetting;
private Dictionary<Difficulty, List<SongBestData>> songBestDataMap = new();
private readonly List<BreadcrumbItem> breadcrumbs = new();
private int selectedDifficultyTab = 0;
protected override async Task OnInitializedAsync()
{
@ -45,6 +45,11 @@ public partial class HighScores
.CompareTo(GameDataService.GetMusicIndexBySongId(data2.SongId)));
}
// Set last selected tab from local storage
selectedDifficultyTab = await localStorage.GetItemAsync<int>($"HighScoresTab_{Baid}");
// Breadcrumbs
if (LoginService.IsLoggedIn && !LoginService.IsAdmin)
{
breadcrumbs.Add(new BreadcrumbItem("Dashboard", href: "/"));
@ -72,10 +77,9 @@ public partial class HighScores
}
}
private static bool IsAiDataPresent(SongBestData data)
private async Task OnTabChanged(int index)
{
var aiData = data.AiSectionBestData;
return aiData.Count > 0;
selectedDifficultyTab = index;
await localStorage.SetItemAsync($"HighScoresTab_{Baid}", selectedDifficultyTab);
}
}

View File

@ -66,9 +66,14 @@
Song Title / Artist
</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel T="MusicDetail" SortBy="context => context.Genre">
Genre
</MudTableSortLabel>
</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd>
<MudTd Style="width:400px">
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
<div>
<a href="@($"/Users/{Baid}/Songs/{context.SongId}")">
@ -91,6 +96,11 @@
</div>
</MudStack>
</MudTd>
<MudTd>
<MudChip Style="@ScoreUtils.GetGenreStyle(context.Genre)" Size="Size.Small">
@ScoreUtils.GetGenreTitle(context.Genre)
</MudChip>
</MudTd>
</RowTemplate>
<PagerContent>
<MudTablePager />

View File

@ -4,7 +4,7 @@ using TaikoWebUI.Shared.Models;
namespace TaikoWebUI.Pages;
public partial class Songs
public partial class SongList
{
[Parameter]
public int Baid { get; set; }

View File

@ -1,4 +1,5 @@
using System.Globalization;
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.JSInterop;
using MudBlazor.Services;
@ -25,6 +26,9 @@ builder.Services.AddSingleton<ScoreUtils>();
builder.Services.AddSingleton<StringUtil>();
builder.Services.AddBlazoredLocalStorage();
var host = builder.Build();
var gameDataService = host.Services.GetRequiredService<IGameDataService>();
@ -47,5 +51,4 @@ else
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
await host.RunAsync();

View File

@ -13,6 +13,7 @@
<ItemGroup>
<PackageReference Include="Autocomplete.Clients" Version="1.1.0" />
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageReference Include="CodeBeam.MudBlazor.Extensions" Version="6.5.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0-rc.1.23421.29" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0-rc.1.23421.29" PrivateAssets="all" />