diff --git a/app/MindWork AI Studio/Components/ConfigurationBase.razor b/app/MindWork AI Studio/Components/ConfigurationBase.razor new file mode 100644 index 0000000..e69de29 diff --git a/app/MindWork AI Studio/Components/ConfigurationBase.razor.cs b/app/MindWork AI Studio/Components/ConfigurationBase.razor.cs new file mode 100644 index 0000000..9f0f047 --- /dev/null +++ b/app/MindWork AI Studio/Components/ConfigurationBase.razor.cs @@ -0,0 +1,29 @@ +using AIStudio.Settings; + +using Microsoft.AspNetCore.Components; + +namespace AIStudio.Components; + +/// +/// A base class for configuration options. +/// +public partial class ConfigurationBase : ComponentBase +{ + /// + /// The description of the option, i.e., the name. Should be + /// as short as possible. + /// + [Parameter] + public string OptionDescription { get; set; } = string.Empty; + + /// + /// A helpful text that explains the option in more detail. + /// + [Parameter] + public string OptionHelp { get; set; } = string.Empty; + + [Inject] + public SettingsManager SettingsManager { get; init; } = null!; + + protected const string MARGIN_CLASS = "mb-6"; +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/ConfigurationOption.razor b/app/MindWork AI Studio/Components/ConfigurationOption.razor new file mode 100644 index 0000000..f8de2b9 --- /dev/null +++ b/app/MindWork AI Studio/Components/ConfigurationOption.razor @@ -0,0 +1,7 @@ +@inherits ConfigurationBase + + + + @(this.State() ? this.LabelOn : this.LabelOff) + + \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/ConfigurationOption.razor.cs b/app/MindWork AI Studio/Components/ConfigurationOption.razor.cs new file mode 100644 index 0000000..f2c6593 --- /dev/null +++ b/app/MindWork AI Studio/Components/ConfigurationOption.razor.cs @@ -0,0 +1,39 @@ +using Microsoft.AspNetCore.Components; + +namespace AIStudio.Components; + +/// +/// Configuration component for any boolean option. +/// +public partial class ConfigurationOption : ConfigurationBase +{ + /// + /// Text to display when the option is true. + /// + [Parameter] + public string LabelOn { get; set; } = string.Empty; + + /// + /// Text to display when the option is false. + /// + [Parameter] + public string LabelOff { get; set; } = string.Empty; + + /// + /// The boolean state of the option. + /// + [Parameter] + public Func State { get; set; } = () => false; + + /// + /// An action which is called when the option is changed. + /// + [Parameter] + public Action StateUpdate { get; set; } = _ => { }; + + private async Task OptionChanged(bool updatedState) + { + this.StateUpdate(updatedState); + await this.SettingsManager.StoreSettings(); + } +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/ConfigurationSelect.razor b/app/MindWork AI Studio/Components/ConfigurationSelect.razor new file mode 100644 index 0000000..852f7c6 --- /dev/null +++ b/app/MindWork AI Studio/Components/ConfigurationSelect.razor @@ -0,0 +1,11 @@ +@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/ConfigurationSelect.razor.cs b/app/MindWork AI Studio/Components/ConfigurationSelect.razor.cs new file mode 100644 index 0000000..8a0f9a7 --- /dev/null +++ b/app/MindWork AI Studio/Components/ConfigurationSelect.razor.cs @@ -0,0 +1,36 @@ +using Microsoft.AspNetCore.Components; + +namespace AIStudio.Components; + +/// +/// Configuration component for selecting a value from a list. +/// +/// The type of the value to select. +public partial class ConfigurationSelect : ConfigurationBase +{ + /// + /// The data to select from. + /// + [Parameter] + public IEnumerable> Data { get; set; } = []; + + /// + /// The selected value. + /// + [Parameter] + public Func SelectedValue { get; set; } = () => default!; + + /// + /// An action that is called when the selection changes. + /// + [Parameter] + public Action SelectionUpdate { get; set; } = _ => { }; + + private async Task OptionChanged(T updatedValue) + { + this.SelectionUpdate(updatedValue); + await this.SettingsManager.StoreSettings(); + } + + private static string GetClass => $"{MARGIN_CLASS} rounded-lg"; +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/ConfigurationSelectData.cs b/app/MindWork AI Studio/Components/ConfigurationSelectData.cs new file mode 100644 index 0000000..1fb9a57 --- /dev/null +++ b/app/MindWork AI Studio/Components/ConfigurationSelectData.cs @@ -0,0 +1,24 @@ +using AIStudio.Settings; + +namespace AIStudio.Components; + +/// +/// A data structure to map a name to a value. +/// +/// The name of the value, to be displayed in the UI. +/// The value to be stored. +/// The type of the value to store. +public readonly record struct ConfigurationSelectData(string Name, T Value); + +/// +/// A static factory class to get the lists of selectable values. +/// +public static class ConfigurationSelectDataFactory +{ + public static IEnumerable> GetSendBehaviorData() + { + yield return new("No key is sending the input", SendBehavior.NO_KEY_IS_SENDING); + yield return new("Modifier key + enter is sending the input", SendBehavior.MODIFER_ENTER_IS_SENDING); + yield return new("Enter is sending the input", SendBehavior.ENTER_IS_SENDING); + } +} \ No newline at end of file