Name the deleted speaker in the confirmation toast

The handler read the name back out of the response, but the endpoint returns
the re-rendered list as HTML, so the JSON parse fell back to a placeholder
and the reviewer saw "Deleted speaker." instead of the name they clicked.
The name is already known at the call site - pass it through, and drop the
unused nameOf helper.

Verified in a browser: "Deleted ZZ Browser Delete."
This commit is contained in:
B.D. Murphy
2026-10-11 21:40:02 -07:00
parent 970e6e884a
commit e5bb555e01

View File

@@ -120,10 +120,10 @@ function notify(message, isError) {
// later row pointing at the wrong speaker.
function deleteSpeaker(idx, name) {
if (!confirm('Delete ' + name + '?')) return;
requestDelete(idx, '');
requestDelete(idx, '', name);
}
function requestDelete(idx, reassignTo) {
function requestDelete(idx, reassignTo, name) {
var url = '/api/speakers/' + idx +
(reassignTo ? '?reassign_to=' + encodeURIComponent(reassignTo) : '');
fetch(url, {method: 'DELETE', headers: {'HX-Request': 'true'}})
@@ -133,7 +133,7 @@ function requestDelete(idx, reassignTo) {
})
.then(function (res) {
if (res.status === 409) {
showReassignPrompt(idx, nameOf(res.data), res.data);
showReassignPrompt(idx, name, res.data);
return;
}
if (res.status !== 200) {
@@ -143,7 +143,7 @@ function requestDelete(idx, reassignTo) {
htmx.ajax('GET', '/speakers/partial', {
target: '#speakers-list', swap: 'innerHTML'
});
var msg = 'Deleted ' + nameOf(res.data) + '.';
notify('Deleted ' + name + '.');
notify(msg);
initSpeakerNames();
})
@@ -152,10 +152,6 @@ function requestDelete(idx, reassignTo) {
});
}
function nameOf(data) {
return (data && data.speaker_name) || 'speaker';
}
function showReassignPrompt(idx, name, data) {
var box = document.getElementById('delete-prompt-' + idx);
if (!box) {
@@ -175,7 +171,7 @@ function showReassignPrompt(idx, name, data) {
'<div style="display:flex; gap:0.4rem">' +
'<button class="btn btn-reject" style="font-size:0.75rem" ' +
'onclick="requestDelete(' + idx + ', document.getElementById(\'delete-target-' +
idx + '\').value)">Reassign and delete</button>' +
idx + '\').value, " + JSON.stringify(name) + ")">Reassign and delete</button>' +
'<button class="btn" style="font-size:0.75rem" ' +
'onclick="document.getElementById(\'delete-prompt-' + idx + '\').style.display=\'none\'">' +
'Cancel</button></div>';