fix: Show progress circular on CaddyReverseProxiesPage when saving and restarting from editor
All checks were successful
Caddy Manager CI build / docker (push) Successful in 39s

This commit is contained in:
2025-07-12 08:42:12 +07:00
parent a1811169f7
commit 25e58b622d
4 changed files with 36 additions and 15 deletions

View File

@@ -28,7 +28,7 @@
@bind-SelectedValues="_selectedCaddyConfigurations">
@foreach (var (index, caddyConfig) in _availableCaddyConfigurations.Index())
{
<CaddyReverseProxyItem FileName="@caddyConfig"/>
<CaddyReverseProxyItem FileName="@caddyConfig" OnCaddyRestartRequired="@RestartCaddy"/>
@if (index < _availableCaddyConfigurations.Count - 1)
{

View File

@@ -42,11 +42,11 @@ public partial class CaddyReverseProxiesPage : ComponentBase
private async Task NewReverseProxy()
{
var dialog = await DialogService.ShowAsync<CaddyfileEditor.CaddyfileEditor>("New configuration",
options: new DialogOptions
options: new MudBlazor.DialogOptions
{
FullWidth = true,
MaxWidth = MaxWidth.Medium
}, parameters: new DialogParameters
MaxWidth = MudBlazor.MaxWidth.Medium
}, parameters: new MudBlazor.DialogParameters
{
{ "FileName", string.Empty }
});
@@ -56,6 +56,7 @@ public partial class CaddyReverseProxiesPage : ComponentBase
if (result is { Data: bool, Canceled: false } && (bool)result.Data)
{
Refresh();
await RestartCaddy();
}
}
@@ -127,6 +128,8 @@ public partial class CaddyReverseProxiesPage : ComponentBase
_isProcessing = true;
StateHasChanged();
Snackbar.Add("Restarting Caddy container", Severity.Info);
// Added a small delay for debugging purposes to ensure UI renders
await Task.Delay(100);
await DockerService.RestartCaddyContainerAsync();
Snackbar.Add("Caddy container restarted successfully", Severity.Success);
_isProcessing = false;

View File

@@ -16,6 +16,12 @@ public partial class CaddyReverseProxyItem : ComponentBase
/// </summary>
[Parameter]
public string FileName { get; set; } = string.Empty;
/// <summary>
/// Callback to refresh the Caddy reverse proxies on the main page
/// </summary>
[Parameter]
public EventCallback OnCaddyRestartRequired { get; set; }
/// <summary>
/// Dialog service for showing the Caddy file editor dialog
@@ -63,8 +69,13 @@ public partial class CaddyReverseProxyItem : ComponentBase
{ "FileName", FileName }
});
await dialog.Result;
var result = await dialog.Result;
if (result is { Data: bool, Canceled: false } && (bool)result.Data)
{
await OnCaddyRestartRequired.InvokeAsync();
}
Refresh();
}
}

View File

@@ -78,11 +78,12 @@ public partial class CaddyfileEditor : ComponentBase
if (response.Success)
{
Snackbar.Add($"{FileName} Caddy configuration saved successfully", Severity.Success);
MudDialog.Close(DialogResult.Ok(true));
MudDialog.Close(DialogResult.Ok(false)); // Indicate successful save but no restart
}
else
{
Snackbar.Add(response.Message, Severity.Error);
MudDialog.Close(DialogResult.Ok(false)); // Indicate failed save
}
}
@@ -99,18 +100,24 @@ public partial class CaddyfileEditor : ComponentBase
/// </summary>
private async Task SaveAndRestart()
{
await Submit();
// Restart the Caddy container
try
var submitResponse = CaddyService.SaveCaddyConfiguration(new CaddySaveConfigurationRequest
{
Snackbar.Add("Restarting Caddy container", Severity.Info);
await DockerService.RestartCaddyContainerAsync();
Snackbar.Add("Caddy container restarted successfully", Severity.Success);
IsNew = IsNew,
FileName = FileName,
Content = await _codeEditor.GetValue(),
});
if (submitResponse.Success)
{
Snackbar.Add($"{FileName} Caddy configuration saved successfully", Severity.Success);
// Indicate successful save and that a restart is required by the calling component
MudDialog.Close(DialogResult.Ok(true));
}
catch
else
{
Snackbar.Add("Failed to restart the Caddy container", Severity.Error);
Snackbar.Add(submitResponse.Message, Severity.Error);
// Indicate failed save, no restart needed
MudDialog.Close(DialogResult.Ok(false));
}
}
}