diff --git a/app/MindWork AI Studio/Components/ConfigurationMultiSelect.razor b/app/MindWork AI Studio/Components/ConfigurationMultiSelect.razor new file mode 100644 index 00000000..0ab1b73d --- /dev/null +++ b/app/MindWork AI Studio/Components/ConfigurationMultiSelect.razor @@ -0,0 +1,23 @@ +@inherits ConfigurationBase +@typeparam T + + + @foreach (var data in this.Data) + { + + @data.Name + + } + \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/ConfigurationMultiSelect.razor.cs b/app/MindWork AI Studio/Components/ConfigurationMultiSelect.razor.cs new file mode 100644 index 00000000..73bc0999 --- /dev/null +++ b/app/MindWork AI Studio/Components/ConfigurationMultiSelect.razor.cs @@ -0,0 +1,54 @@ +using AIStudio.Settings; + +using Microsoft.AspNetCore.Components; + +namespace AIStudio.Components; + +/// +/// Configuration component for selecting many values from a list. +/// +/// The type of the value to select. +public partial class ConfigurationMultiSelect : ConfigurationBase +{ + /// + /// The data to select from. + /// + [Parameter] + public IEnumerable> Data { get; set; } = []; + + /// + /// The selected values. + /// + [Parameter] + public Func> SelectedValues { get; set; } = () => []; + + /// + /// An action that is called when the selection changes. + /// + [Parameter] + public Action> SelectionUpdate { get; set; } = _ => { }; + + private async Task OptionChanged(IEnumerable? updatedValues) + { + if(updatedValues is null) + this.SelectionUpdate([]); + else + this.SelectionUpdate(updatedValues.Where(n => n is not null).ToHashSet()!); + + await this.SettingsManager.StoreSettings(); + await this.InformAboutChange(); + } + + private static string GetClass => $"{MARGIN_CLASS} rounded-lg"; + + private string GetMultiSelectionText(List? selectedValues) + { + if(selectedValues is null || selectedValues.Count == 0) + return "No preview features selected."; + + if(selectedValues.Count == 1) + return $"You have selected 1 preview feature."; + + return $"You have selected {selectedValues.Count} preview features."; + } +} \ No newline at end of file