Combine language menus into one
This commit is contained in:
parent
66d9b34562
commit
ce276c790a
@ -3,6 +3,6 @@
|
||||
"JwtKey": "SuperSecretKeyAndHeresItsPadding",
|
||||
"JwtIssuer": "http://localhost:5000",
|
||||
"JwtAudience": "http://localhost:5000",
|
||||
"AuthenticationRequired": false
|
||||
"AuthenticationRequired": true
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
@using Blazored.LocalStorage
|
||||
@using Microsoft.Extensions.Options
|
||||
@using TaikoWebUI.Settings
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IOptions<WebUiSettings> Settings
|
||||
@inject ILocalStorageService LocalStorage
|
||||
|
||||
<MudMenu Icon="@Icons.Material.Filled.Translate" Color="Color.Inherit" Size="Size.Small" Dense="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
<MudText Align="Align.Center" GutterBottom="true">@Localizer["Song Name"]</MudText>
|
||||
<MudDivider />
|
||||
@foreach (var culture in supportedCultures)
|
||||
{
|
||||
<MudMenuItem OnClick="() => RequestCultureChange(culture.Key)" OnTouch="() => RequestCultureChange(culture.Key)">@culture.Value</MudMenuItem>
|
||||
}
|
||||
</MudMenu>
|
||||
|
||||
@code {
|
||||
private readonly Dictionary<CultureInfo, string> supportedCultures = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await base.OnInitializedAsync();
|
||||
foreach (var language in Settings.Value.SupportedLanguages)
|
||||
{
|
||||
supportedCultures.Add(new CultureInfo(language.CultureCode), language.DisplayName);
|
||||
}
|
||||
|
||||
if (supportedCultures.Count == 0)
|
||||
{
|
||||
supportedCultures.Add(new CultureInfo("en-US"), "English");
|
||||
}
|
||||
|
||||
var currentSongNameLanguage = await LocalStorage.GetItemAsync<string>("songNameLanguage");
|
||||
|
||||
if (string.IsNullOrEmpty(currentSongNameLanguage))
|
||||
{
|
||||
await LocalStorage.SetItemAsync("songNameLanguage", "en-US");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RequestCultureChange(CultureInfo newCulture)
|
||||
{
|
||||
var currentSongNameLanguage = await LocalStorage.GetItemAsync<string>("songNameLanguage");
|
||||
|
||||
if (currentSongNameLanguage == newCulture.Name)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await LocalStorage.SetItemAsync("songNameLanguage", newCulture.Name);
|
||||
|
||||
NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true);
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
@using Microsoft.Extensions.Options
|
||||
@using TaikoWebUI.Settings
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IJSRuntime JsRuntime
|
||||
@inject IOptions<WebUiSettings> Settings
|
||||
|
||||
<MudMenu Icon="@Icons.Material.Filled.Language" Color="Color.Inherit" Size="Size.Small" Dense="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
<MudText Align="Align.Center" GutterBottom="true">@Localizer["UI"]</MudText>
|
||||
<MudDivider />
|
||||
@foreach (var culture in supportedCultures)
|
||||
{
|
||||
<MudMenuItem OnClick="() => RequestCultureChange(culture.Key)" OnTouch="() => RequestCultureChange(culture.Key)">@culture.Value</MudMenuItem>
|
||||
}
|
||||
</MudMenu>
|
||||
|
||||
@code {
|
||||
private Dictionary<CultureInfo, string> supportedCultures = new();
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
foreach (var language in Settings.Value.SupportedLanguages)
|
||||
{
|
||||
supportedCultures.Add(new CultureInfo(language.CultureCode), language.DisplayName);
|
||||
}
|
||||
|
||||
if (supportedCultures.Count == 0)
|
||||
{
|
||||
supportedCultures.Add(new CultureInfo("en-US"), "English");
|
||||
}
|
||||
}
|
||||
|
||||
private void RequestCultureChange(CultureInfo newCulture)
|
||||
{
|
||||
if (Equals(CultureInfo.CurrentCulture, newCulture))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var js = (IJSInProcessRuntime)JsRuntime;
|
||||
js.InvokeVoid("blazorCulture.set", newCulture.Name);
|
||||
NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true);
|
||||
}
|
||||
}
|
121
TaikoWebUI/Components/LanguageToggle.razor
Normal file
121
TaikoWebUI/Components/LanguageToggle.razor
Normal file
@ -0,0 +1,121 @@
|
||||
@using Blazored.LocalStorage
|
||||
@using Microsoft.Extensions.Options
|
||||
@using TaikoWebUI.Settings
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IJSRuntime JsRuntime
|
||||
@inject IOptions<WebUiSettings> Settings
|
||||
@inject ILocalStorageService LocalStorage
|
||||
|
||||
<MudMenu Icon="@Icons.Material.Filled.Translate" Color="Color.Inherit" Size="Size.Small" Dense="true" MaxHeight="300" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
<MudText Typo="Typo.overline" Align="Align.Left" GutterBottom="true" Style="padding: 0 16px;font-weight: bold;">@Localizer["UI"]</MudText>
|
||||
@foreach (var culture in supportedCultures)
|
||||
{
|
||||
<MudMenuItem Class="lang-menu-item" IconSize="Size.Small" Icon="@cultureStatuses["UI"][culture.Key]" OnClick="() => RequestUiCultureChange(culture.Key)" OnTouch="() => RequestUiCultureChange(culture.Key)">@culture.Value</MudMenuItem>
|
||||
}
|
||||
<MudDivider />
|
||||
<MudText Typo="Typo.overline" Align="Align.Left" GutterBottom="true" Style="padding: 0 16px;font-weight: bold;">@Localizer["Song List"]</MudText>
|
||||
@foreach (var culture in supportedCultures)
|
||||
{
|
||||
<MudMenuItem Class="lang-menu-item" IconSize="Size.Small" Icon="@cultureStatuses["SongName"][culture.Key]" OnClick="() => RequestSongNameCultureChange(culture.Key)" OnTouch="() => RequestSongNameCultureChange(culture.Key)">@culture.Value</MudMenuItem>
|
||||
}
|
||||
</MudMenu>
|
||||
|
||||
@code {
|
||||
private Dictionary<CultureInfo, string> supportedCultures = new();
|
||||
private Dictionary<string, Dictionary<CultureInfo, string>> cultureStatuses = new();
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
foreach (var language in Settings.Value.SupportedLanguages)
|
||||
{
|
||||
supportedCultures.Add(new CultureInfo(language.CultureCode), language.DisplayName);
|
||||
}
|
||||
|
||||
if (supportedCultures.Count == 0)
|
||||
{
|
||||
supportedCultures.Add(new CultureInfo("en-US"), "English");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var currentSongNameLanguage = await LocalStorage.GetItemAsync<string>("songNameLanguage");
|
||||
|
||||
if (string.IsNullOrEmpty(currentSongNameLanguage))
|
||||
{
|
||||
await LocalStorage.SetItemAsync("songNameLanguage", "en-US");
|
||||
}
|
||||
|
||||
foreach (var culture in supportedCultures.Keys)
|
||||
{
|
||||
var uiStatus = GetActiveUiStatus(culture);
|
||||
var songNameStatus = await GetActiveSongNameStatus(culture);
|
||||
|
||||
if (!cultureStatuses.ContainsKey("UI"))
|
||||
{
|
||||
cultureStatuses["UI"] = new Dictionary<CultureInfo, string>();
|
||||
}
|
||||
if (!cultureStatuses.ContainsKey("SongName"))
|
||||
{
|
||||
cultureStatuses["SongName"] = new Dictionary<CultureInfo, string>();
|
||||
}
|
||||
|
||||
cultureStatuses["UI"][culture] = uiStatus;
|
||||
cultureStatuses["SongName"][culture] = songNameStatus;
|
||||
}
|
||||
}
|
||||
|
||||
private void RequestUiCultureChange(CultureInfo newCulture)
|
||||
{
|
||||
if (Equals(CultureInfo.CurrentCulture, newCulture))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var js = (IJSInProcessRuntime)JsRuntime;
|
||||
js.InvokeVoid("blazorCulture.set", newCulture.Name);
|
||||
NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true);
|
||||
}
|
||||
|
||||
private async Task RequestSongNameCultureChange(CultureInfo newCulture)
|
||||
{
|
||||
var currentSongNameLanguage = await LocalStorage.GetItemAsync<string>("songNameLanguage");
|
||||
|
||||
if (currentSongNameLanguage == newCulture.Name)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await LocalStorage.SetItemAsync("songNameLanguage", newCulture.Name);
|
||||
|
||||
NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true);
|
||||
}
|
||||
|
||||
private async Task<string> GetActiveStatusAsync(string type, CultureInfo culture)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case "UI":
|
||||
return GetActiveUiStatus(culture);
|
||||
case "SongName":
|
||||
return await GetActiveSongNameStatus(culture);
|
||||
default:
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetActiveUiStatus(CultureInfo culture)
|
||||
{
|
||||
var currentUiLanguage = CultureInfo.CurrentCulture;
|
||||
return Equals(currentUiLanguage, culture) ? Icons.Material.Filled.Check : string.Empty;
|
||||
}
|
||||
|
||||
private async Task<string> GetActiveSongNameStatus(CultureInfo culture)
|
||||
{
|
||||
var currentSongNameLanguage = await LocalStorage.GetItemAsync<string>("songNameLanguage");
|
||||
return currentSongNameLanguage == culture.Name ? Icons.Material.Filled.Check : string.Empty;
|
||||
}
|
||||
}
|
@ -11,8 +11,7 @@
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="DrawerToggle" Size="Size.Small" />
|
||||
<MudSpacer />
|
||||
<MudStack Spacing="3" Row="true">
|
||||
<ChooseUILanguage />
|
||||
<ChooseSongNameLanguage />
|
||||
<LanguageToggle />
|
||||
<MudIconButton Icon="@DarkModeIcon" Size="Size.Small" Color="Color.Inherit" OnClick="ToggleDarkMode" />
|
||||
</MudStack>
|
||||
</MudAppBar>
|
||||
|
@ -74,6 +74,8 @@
|
||||
<_ContentIncludedByDefault Remove="Pages\Pages\PlayHistory.razor" />
|
||||
<_ContentIncludedByDefault Remove="Pages\Pages\Song.razor" />
|
||||
<_ContentIncludedByDefault Remove="Pages\Pages\SongList.razor" />
|
||||
<_ContentIncludedByDefault Remove="wwwroot\css\bootstrap\bootstrap.min.css" />
|
||||
<_ContentIncludedByDefault Remove="wwwroot\css\bootstrap\bootstrap.min.css.map" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"WebUiSettings": {
|
||||
"LoginRequired": "false",
|
||||
"LoginRequired": "true",
|
||||
"OnlyAdmin": "false",
|
||||
"BoundAccessCodeUpperLimit": "3",
|
||||
"RegisterWithLastPlayTime": "false",
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -7,7 +7,6 @@
|
||||
<title>TaikoWebUI</title>
|
||||
<base href="/" />
|
||||
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
|
||||
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet"/>
|
||||
<link href="css/app.css" rel="stylesheet"/>
|
||||
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
|
||||
<link href="style.overrides.css" rel="stylesheet" />
|
||||
|
@ -55,6 +55,10 @@
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.lang-menu-item .mud-list-item-icon {
|
||||
min-width: 26px;
|
||||
}
|
||||
|
||||
@media only screen and (min-width: 600px) {
|
||||
.ai-battle-td {
|
||||
display: revert;
|
||||
|
Loading…
x
Reference in New Issue
Block a user