diff --git a/LANCommander.Launcher/UI/Components/Library/LibraryItemFilter.razor b/LANCommander.Launcher/UI/Components/Library/LibraryItemFilter.razor index 35650bcc..5225555f 100644 --- a/LANCommander.Launcher/UI/Components/Library/LibraryItemFilter.razor +++ b/LANCommander.Launcher/UI/Components/Library/LibraryItemFilter.razor @@ -41,22 +41,22 @@ - + - + - + - + - + - + diff --git a/LANCommander.Launcher/UI/Pages/Depot/Components/DepotFilter.razor b/LANCommander.Launcher/UI/Pages/Depot/Components/DepotFilter.razor index 68021815..1a522f8b 100644 --- a/LANCommander.Launcher/UI/Pages/Depot/Components/DepotFilter.razor +++ b/LANCommander.Launcher/UI/Pages/Depot/Components/DepotFilter.razor @@ -36,25 +36,25 @@ - + - + - + - + - + - + - + diff --git a/LANCommander.Server/UI/Components/TaxonomyInput.razor b/LANCommander.Server/UI/Components/TaxonomyInput.razor index 6214c715..29cee97e 100644 --- a/LANCommander.Server/UI/Components/TaxonomyInput.razor +++ b/LANCommander.Server/UI/Components/TaxonomyInput.razor @@ -8,8 +8,8 @@ OptionLabelSelector="t => t.Name" /> @code { - [Parameter] public BaseDatabaseService DataService { get; set; } - [Parameter] public ICollection Values { get; set; } + [Parameter] public required BaseDatabaseService DataService { get; set; } + [Parameter] public required ICollection? Values { get; set; } [Parameter] public EventCallback> ValuesChanged { get; set; } ICollection _entities = new List(); @@ -21,7 +21,10 @@ async Task Add(string name) { - var taxonomy = Activator.CreateInstance(typeof(TTaxonomy)) as TTaxonomy; + var taxonomy = (TTaxonomy?)Activator.CreateInstance(typeof(TTaxonomy)); + + if (taxonomy == null) + throw new InvalidOperationException($"Could not create instance of type {nameof(TTaxonomy)}"); taxonomy.Name = name; diff --git a/LANCommander.UI/Components/TagsInput/TagsInput.razor b/LANCommander.UI/Components/TagsInput/TagsInput.razor index 5c5044e1..c92d4b9c 100644 --- a/LANCommander.UI/Components/TagsInput/TagsInput.razor +++ b/LANCommander.UI/Components/TagsInput/TagsInput.razor @@ -14,43 +14,30 @@ @code { - [Parameter] public IEnumerable? DataSource { get; set; } = []; - [Parameter] public Func? OptionLabelSelector { get; set; } + [Parameter] public required IEnumerable DataSource { get; set; } + [Parameter] public required Func OptionLabelSelector { get; set; } [Parameter] public Func>? OnCreateTag { get; set; } - [Parameter] public ICollection? Values { get; set; } = []; - [Parameter] public EventCallback?> ValuesChanged { get; set; } + [Parameter] public required ICollection? Values { get; set; } + [Parameter] public EventCallback> ValuesChanged { get; set; } - Dictionary _items = new(); + Dictionary _items = []; IEnumerable _selectedItems = []; bool _loading; bool _locked; - protected override void OnInitialized() - { - GenerateOptions(); - } - - protected override void OnParametersSet() - { - if (Values is null) - Values = []; - } + protected override void OnInitialized() => GenerateOptions(); void GenerateOptions() { - _items = []; + _items.Clear(); - if (OptionLabelSelector != null) - { - if (DataSource != null) - foreach (var item in DataSource.DistinctBy(OptionLabelSelector)) - _items[OptionLabelSelector.Invoke(item)] = item; + foreach (var item in DataSource.DistinctBy(OptionLabelSelector)) + _items[OptionLabelSelector.Invoke(item)] = item; - _selectedItems = Values?.Select(v => OptionLabelSelector.Invoke(v)) ?? []; - } + _selectedItems = Values?.Select(v => OptionLabelSelector.Invoke(v)) ?? []; } async Task OnValuesChanged(IEnumerable values)