refactor(centralui): migrate Move/Rename/Compose dialogs to DialogService.ShowAsync host (T33b)
This commit is contained in:
@@ -1,59 +1,36 @@
|
||||
@if (IsVisible)
|
||||
{
|
||||
<div class="modal show d-block" tabindex="-1" style="background: rgba(0,0,0,0.4);">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h6 class="modal-title">Move '@TemplateName' to…</h6>
|
||||
<button type="button" class="btn-close" @onclick="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<select class="form-select form-select-sm" @bind="_targetFolderId">
|
||||
@foreach (var opt in FolderOptions)
|
||||
{
|
||||
<option value="@opt.Id">@opt.Label</option>
|
||||
}
|
||||
</select>
|
||||
@if (!string.IsNullOrEmpty(ErrorMessage)) { <div class="text-danger small mt-1">@ErrorMessage</div> }
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-outline-secondary btn-sm" @onclick="Close">Cancel</button>
|
||||
<button class="btn btn-primary btn-sm" @onclick="Submit">Move</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@*
|
||||
T33b: body component for the "Move template" dialog hosted by
|
||||
IDialogService.ShowAsync. Renders ONLY the picker + action buttons inside the
|
||||
host's .modal-body; the host owns the backdrop, header, and focus trap. Closes
|
||||
with a MoveTemplateResult carrying the picked folder id (null = Root) — a result
|
||||
record so Close(null) for the Root choice stays distinguishable from a Cancel.
|
||||
*@
|
||||
<select class="form-select form-select-sm" @bind="_targetFolderId">
|
||||
@foreach (var opt in FolderOptions)
|
||||
{
|
||||
<option value="@opt.Id">@opt.Label</option>
|
||||
}
|
||||
</select>
|
||||
|
||||
<div class="modal-footer px-0 pb-0 mt-3">
|
||||
<button class="btn btn-outline-secondary btn-sm" @onclick="() => Context.Cancel()">Cancel</button>
|
||||
<button class="btn btn-primary btn-sm" @onclick="Submit">Move</button>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter] public bool IsVisible { get; set; }
|
||||
[Parameter] public EventCallback<bool> IsVisibleChanged { get; set; }
|
||||
[Parameter] public int TemplateId { get; set; }
|
||||
[Parameter] public string TemplateName { get; set; } = string.Empty;
|
||||
/// <summary>Host-supplied context used to close (with the picked folder id) or cancel.</summary>
|
||||
[Parameter] public DialogContext<MoveTemplateResult> Context { get; set; } = default!;
|
||||
[Parameter] public IEnumerable<(int? Id, string Label)> FolderOptions { get; set; } = Array.Empty<(int?, string)>();
|
||||
[Parameter] public string? ErrorMessage { get; set; }
|
||||
[Parameter] public EventCallback<(int TemplateId, int? NewFolderId)> OnSubmit { get; set; }
|
||||
|
||||
private bool _wasVisible;
|
||||
private int? _targetFolderId;
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
// Reset internal state on transition from hidden -> visible.
|
||||
if (IsVisible && !_wasVisible)
|
||||
{
|
||||
_targetFolderId = null;
|
||||
}
|
||||
_wasVisible = IsVisible;
|
||||
}
|
||||
private void Submit() => Context.Close(new MoveTemplateResult(_targetFolderId));
|
||||
|
||||
private async Task Close()
|
||||
{
|
||||
await IsVisibleChanged.InvokeAsync(false);
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await OnSubmit.InvokeAsync((TemplateId, _targetFolderId));
|
||||
}
|
||||
/// <summary>
|
||||
/// Result of the move-template picker. A reference type so a non-null close is
|
||||
/// distinguishable from a cancel even when the picked folder is null (Root):
|
||||
/// ShowAsync resolves to this record on Move and to <c>null</c> on Cancel.
|
||||
/// </summary>
|
||||
/// <param name="NewFolderId">The chosen destination folder id, or <c>null</c> for Root.</param>
|
||||
public sealed record MoveTemplateResult(int? NewFolderId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user