Refactored dialog options

This commit is contained in:
Thorsten Sommer 2024-06-30 13:59:29 +02:00
parent 548d1eef26
commit a9e89e13e6
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 22 additions and 19 deletions

View File

@ -0,0 +1,17 @@
namespace AIStudio.Components.CommonDialogs;
public static class DialogOptions
{
public static readonly MudBlazor.DialogOptions FULLSCREEN = new()
{
CloseOnEscapeKey = true,
FullWidth = true, MaxWidth = MaxWidth.Medium,
};
public static readonly MudBlazor.DialogOptions FULLSCREEN_NO_HEADER = new()
{
NoHeader = true,
CloseOnEscapeKey = true,
FullWidth = true, MaxWidth = MaxWidth.Medium,
};
}

View File

@ -3,6 +3,8 @@ using AIStudio.Provider;
using AIStudio.Settings; using AIStudio.Settings;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using DialogOptions = AIStudio.Components.CommonDialogs.DialogOptions;
// ReSharper disable ClassNeverInstantiated.Global // ReSharper disable ClassNeverInstantiated.Global
namespace AIStudio.Components.Pages; namespace AIStudio.Components.Pages;
@ -18,22 +20,6 @@ public partial class Settings : ComponentBase
[Inject] [Inject]
public IJSRuntime JsRuntime { get; init; } = null!; public IJSRuntime JsRuntime { get; init; } = null!;
private static readonly DialogOptions DIALOG_OPTIONS = new()
{
CloseOnEscapeKey = true,
FullWidth = true, MaxWidth = MaxWidth.Medium,
};
#region Overrides of ComponentBase
protected override async Task OnInitializedAsync()
{
await this.SettingsManager.LoadSettings();
await base.OnInitializedAsync();
}
#endregion
#region Provider related #region Provider related
private async Task AddProvider() private async Task AddProvider()
@ -43,7 +29,7 @@ public partial class Settings : ComponentBase
{ x => x.IsEditing, false }, { x => x.IsEditing, false },
}; };
var dialogReference = await this.DialogService.ShowAsync<ProviderDialog>("Add Provider", dialogParameters, DIALOG_OPTIONS); var dialogReference = await this.DialogService.ShowAsync<ProviderDialog>("Add Provider", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result; var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled) if (dialogResult.Canceled)
return; return;
@ -67,7 +53,7 @@ public partial class Settings : ComponentBase
{ x => x.IsEditing, true }, { x => x.IsEditing, true },
}; };
var dialogReference = await this.DialogService.ShowAsync<ProviderDialog>("Edit Provider", dialogParameters, DIALOG_OPTIONS); var dialogReference = await this.DialogService.ShowAsync<ProviderDialog>("Edit Provider", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result; var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled) if (dialogResult.Canceled)
return; return;
@ -90,7 +76,7 @@ public partial class Settings : ComponentBase
{ "Message", $"Are you sure you want to delete the provider '{provider.InstanceName}'?" }, { "Message", $"Are you sure you want to delete the provider '{provider.InstanceName}'?" },
}; };
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>("Delete Provider", dialogParameters, DIALOG_OPTIONS); var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>("Delete Provider", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result; var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled) if (dialogResult.Canceled)
return; return;