@using TaikoWebUI.Shared.Models @using System.Collections.Immutable @inject IGameDataService GameDataService ID Title @{ // Disable nullable warnings, which seems to be a false positive # pragma warning disable CS8602 } @context.TitleId @context.TitleName @{ #pragma warning restore CS8602 } Selected Title: @selectedTitle?.TitleName Cancel Ok @code { [CascadingParameter] MudDialogInstance MudDialog { get; set; } = null!; [Parameter] public UserSetting UserSetting { get; set; } = new(); private IEnumerable 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 { TitleName = UserSetting.Title }; if (titleSet.Contains(currentTitle)) { titleSet.TryGetValue(new Title { TitleName = UserSetting.Title }, out selectedTitle); } } private bool Filter(Title? title) { if (title is null) { return false; } 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(); }