1
0
mirror of synced 2024-12-20 18:35:54 +01:00
TaikoLocalServer/TaikoWebUI/Pages/Dialogs/ChooseTitleDialog.razor

105 lines
3.4 KiB
Plaintext
Raw Normal View History

2022-09-15 11:47:46 +02:00
@using TaikoWebUI.Shared.Models
@using System.Collections.Immutable
@inject IGameDataService GameDataService
<MudDialog>
<DialogContent>
2022-09-15 17:57:39 +02:00
<MudTable Items="@titles" Filter="@Filter" @bind-SelectedItem="@selectedTitle" Height="40vh" Hover="true">
2022-09-15 13:05:36 +02:00
<ColGroup>
2022-09-15 17:57:39 +02:00
<col style="width: 50px;" />
2022-09-15 13:05:36 +02:00
<col />
</ColGroup>
2022-09-15 11:47:46 +02:00
<ToolBarContent>
<MudTextField @bind-Value="searchString" Placeholder="Search" Adornment="Adornment.Start" Immediate="true"
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0">
</MudTextField>
</ToolBarContent>
<HeaderContent>
<MudTh>
<MudTableSortLabel SortBy="@(new Func<Title, object>(x => x.TitleId))">
2022-09-15 17:57:39 +02:00
ID
2022-09-15 11:47:46 +02:00
</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel SortBy="@(new Func<Title, object>(x => x.TitleName))">
2022-09-15 17:59:40 +02:00
Title
2022-09-15 11:47:46 +02:00
</MudTableSortLabel>
</MudTh>
</HeaderContent>
<RowTemplate>
2022-09-16 15:48:16 +02:00
@{
// Disable nullable warnings, which seems to be a false positive
# pragma warning disable CS8602
}
2022-09-15 13:05:36 +02:00
<MudTd DataLabel="Id" Class="cursor-pointer">@context.TitleId</MudTd>
2022-09-15 17:59:40 +02:00
<MudTd DataLabel="Title" Class="cursor-pointer">@context.TitleName</MudTd>
2022-09-16 15:48:16 +02:00
@{
#pragma warning restore CS8602
}
2022-09-15 11:47:46 +02:00
</RowTemplate>
<PagerContent>
<MudTablePager/>
2022-09-15 11:47:46 +02:00
</PagerContent>
</MudTable>
2022-09-15 17:57:39 +02:00
<MudText Class="mt-4 d-block" Typo="Typo.caption"><b>Selected Title:</b> @selectedTitle?.TitleName</MudText>
2022-09-15 11:47:46 +02:00
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel">Cancel</MudButton>
<MudButton Color="Color.Primary" OnClick="Submit">Ok</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter]
MudDialogInstance MudDialog { get; set; } = null!;
[Parameter]
public UserSetting UserSetting { get; set; } = new();
private IEnumerable<Title> titles = new List<Title>();
private Title? selectedTitle;
private string searchString = string.Empty;
protected override void OnInitialized()
{
base.OnInitialized();
var titleSet = GameDataService.GetTitles();
titles = titleSet.ToImmutableList().Sort((title, title1) => title.TitleId.CompareTo(title1.TitleId));
var currentTitle = new Title
2022-09-15 11:47:46 +02:00
{
TitleName = UserSetting.Title
};
if (titleSet.Contains(currentTitle))
{
titleSet.TryGetValue(new Title
{
TitleName = UserSetting.Title
}, out selectedTitle);
}
2022-09-15 11:47:46 +02:00
}
2022-09-16 15:48:16 +02:00
private bool Filter(Title? title)
2022-09-15 11:47:46 +02:00
{
2022-09-16 15:48:16 +02:00
if (title is null)
{
return false;
}
2022-09-15 11:47:46 +02:00
return string.IsNullOrEmpty(searchString) ||
title.TitleName.Contains(searchString, StringComparison.InvariantCultureIgnoreCase);
}
private void Submit()
{
if (selectedTitle is not null)
{
UserSetting.Title = selectedTitle.TitleName;
}
MudDialog.Close(DialogResult.Ok(true));
}
private void Cancel() => MudDialog.Cancel();
}