feat(cms): replace track audio in edit form, gate last-track delete
Swap a track's audio by EntryKey (metadata/release/position preserved, waveform regenerated); hide per-track remove on a release's sole persisted track so it can only be replaced or release-deleted.
This commit is contained in:
@@ -34,12 +34,37 @@
|
||||
Disabled="@(index == Tracks.Count - 1 || Disabled)"
|
||||
OnClick="@(() => OnMoveDown.InvokeAsync(index))"
|
||||
aria-label="Move track down" />
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete"
|
||||
Color="Color.Error"
|
||||
Size="Size.Small"
|
||||
Disabled="@Disabled"
|
||||
OnClick="@(() => OnRemove.InvokeAsync(index))"
|
||||
aria-label="Remove track" />
|
||||
@* Replace audio: existing (persisted) rows only. New rows still pick their WAV
|
||||
via the file input above, so a replace control there would be redundant. A
|
||||
native <label for> drives a per-row hidden InputFile — clicking the icon
|
||||
opens that row's picker with zero JS (no eval, no programmatic .click()). *@
|
||||
@if (row.Id.HasValue)
|
||||
{
|
||||
<label for="@ReplaceInputId(index)" @onclick:stopPropagation="true"
|
||||
style="display: inline-flex; @(Disabled ? "pointer-events: none; opacity: 0.5;" : "cursor: pointer;")">
|
||||
<MudIcon Icon="@Icons.Material.Filled.SwapHoriz"
|
||||
Color="Color.Primary"
|
||||
Size="Size.Small"
|
||||
aria-label="Replace audio" />
|
||||
</label>
|
||||
<InputFile id="@ReplaceInputId(index)"
|
||||
OnChange="@(e => OnReplaceFileSelected.InvokeAsync((index, e.File)))"
|
||||
accept=".wav,audio/wav,audio/x-wav"
|
||||
disabled="@Disabled"
|
||||
style="display: none;" />
|
||||
}
|
||||
@* Remove: hidden for the sole remaining persisted track so a release can never
|
||||
be track-deleted down to zero (that path soft-deletes the whole release). New
|
||||
rows are always removable — dropping one only discards a pending upload. *@
|
||||
@if (!(row.Id.HasValue && ExistingTrackCount <= 1))
|
||||
{
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete"
|
||||
Color="Color.Error"
|
||||
Size="Size.Small"
|
||||
Disabled="@Disabled"
|
||||
OnClick="@(() => OnRemove.InvokeAsync(index))"
|
||||
aria-label="Remove track" />
|
||||
}
|
||||
</MudStack>
|
||||
@if (row.Status == BatchRowStatus.Uploading)
|
||||
{
|
||||
@@ -60,11 +85,28 @@
|
||||
[Parameter] public EventCallback<int> SelectedIndexChanged { get; set; }
|
||||
[Parameter] public bool Disabled { get; set; }
|
||||
[Parameter] public bool AllowNewTracks { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Count of existing (persisted, Id-bearing) tracks in the list. When this is 1, the remove
|
||||
/// control on the sole persisted row is suppressed so a release cannot be track-deleted to zero
|
||||
/// (replace + release-level delete remain). New unsaved rows are excluded from this count.
|
||||
/// </summary>
|
||||
[Parameter] public int ExistingTrackCount { get; set; }
|
||||
|
||||
[Parameter] public EventCallback<IReadOnlyList<IBrowserFile>> OnWavFilesSelected { get; set; }
|
||||
[Parameter] public EventCallback<int> OnMoveUp { get; set; }
|
||||
[Parameter] public EventCallback<int> OnMoveDown { get; set; }
|
||||
[Parameter] public EventCallback<int> OnRemove { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Raised when the admin picks a replacement WAV for an existing row, carrying the list index and
|
||||
/// the chosen file. Only fired for persisted (Id-bearing) rows.
|
||||
/// </summary>
|
||||
[Parameter] public EventCallback<(int Index, IBrowserFile File)> OnReplaceFileSelected { get; set; }
|
||||
|
||||
// Stable per-row DOM id linking the swap-icon <label> to its hidden InputFile.
|
||||
private static string ReplaceInputId(int index) => $"replace-audio-input-{index}";
|
||||
|
||||
private const int MaxFilesPerPick = 50;
|
||||
|
||||
private Task SelectRow(int index) => SelectedIndexChanged.InvokeAsync(index);
|
||||
|
||||
Reference in New Issue
Block a user