Fix soft delete not being recognized.
This commit is contained in:
parent
598a9f7793
commit
eff6da0a3b
3 changed files with 101 additions and 5 deletions
|
|
@ -37,12 +37,18 @@
|
|||
.map(el => Number(el.id.slice(3)))
|
||||
.filter(Number.isFinite);
|
||||
}
|
||||
|
||||
function collectEditedUpdates() {
|
||||
const updates = [];
|
||||
for (const id of collectExistingUpdateIds()) updates.push({ id, content: getMarkdown(id) });
|
||||
const deleted = new Set(collectDeletedIds());
|
||||
for (const id of collectExistingUpdateIds()) {
|
||||
if(deleted.has(id)) continue; // skip ones marked for deletion
|
||||
updates.push({ id, content: getMarkdown(id) });
|
||||
}
|
||||
for (const md of (window.newDrafts || [])) if ((md ?? '').trim()) updates.push({ content: md });
|
||||
return updates;
|
||||
}
|
||||
|
||||
function collectDeletedIds() { return (window.deletedIds || []).filter(Number.isFinite); }
|
||||
|
||||
// much simpler, and correct
|
||||
|
|
|
|||
|
|
@ -13,16 +13,20 @@
|
|||
{{ n.timestamp.strftime("%Y-%m-%d %H:%M") if n.timestamp else "" }}
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" id="editSwitch{{ n.id }}" onchange="changeMode({{ n.id }})"
|
||||
role="switch" aria-label="Edit mode for update {{ n.id }}">
|
||||
<input class="form-check-input" type="checkbox" id="editSwitch{{ n.id }}" onchange="changeMode({{ n.id }})" role="switch" aria-label="Edit mode for update {{ n.id }}">
|
||||
<label for="editSwitch{{ n.id }}" class="form-check-label">Edit</label>
|
||||
</div>
|
||||
|
||||
<div class="mt-2">
|
||||
<button type="button" class="btn btn-outline-danger btn-sm" id="deleteBtn{{ n.id }}" onclick="toggleDelete({{ n.id }})">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="list-group-item text-muted">No updates yet.</li>
|
||||
<li id="noUpdatesRow" class="list-group-item text-muted">No updates yet.</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
|
|
@ -77,6 +81,64 @@
|
|||
ta.value = '';
|
||||
}
|
||||
|
||||
function renderNewDrafts() {
|
||||
const wrap = document.getElementById('newDraftsList');
|
||||
const ul = document.getElementById('newDraftsUl');
|
||||
ul.innerHTML = '';
|
||||
const drafts = window.newDrafts || [];
|
||||
if (!drafts.length) {
|
||||
wrap.classList.add('d-none');
|
||||
return;
|
||||
}
|
||||
wrap.classList.remove('d-none');
|
||||
drafts.forEach((md, idx) => {
|
||||
const li = document.createElement('li');
|
||||
li.className = 'list-group-item d-flex justify-content-between align-items-start';
|
||||
const left = document.createElement('div');
|
||||
left.className = 'w-100 markdown-body';
|
||||
left.innerHTML = DOMPurify.sanitize(marked.parse(md || ''));
|
||||
for (const a of left.querySelectorAll('a[href]')) {
|
||||
a.setAttribute('target','_blank');
|
||||
a.setAttribute('rel','noopener noreferrer nofollow');
|
||||
}
|
||||
const right = document.createElement('div');
|
||||
right.className = 'ms-3 d-flex flex-column align-items-end';
|
||||
right.innerHTML = `<button type="button" class="btn btn-outline-danger btn-sm" onclick="deleteDraft(${idx})">Remove</button>"`;
|
||||
li.appendChild(left);
|
||||
li.appendChild(right);
|
||||
ul.appendChild(li);
|
||||
});
|
||||
const noRow = document.getElementById('noUpdatesRow');
|
||||
if (noRow) {
|
||||
if (drafts.length) noRow.classList.add('d-none');
|
||||
else noRow.classList.remove('d-none');
|
||||
}
|
||||
}
|
||||
|
||||
function deleteDraft(idx) {
|
||||
if (!Array.isArray(window.newDrafts)) return;
|
||||
window.newDrafts.splice(idx, 1);
|
||||
renderNewDrafts();
|
||||
}
|
||||
|
||||
function toggleDelete(id) {
|
||||
window.deletedIds = window.deletedIds || [];
|
||||
const idx = window.deletedIds.indexOf(id);
|
||||
const btn = document.getElementById(`deleteBtn${id}`);
|
||||
const container = document.getElementById(`editContainer${id}`);
|
||||
if (idx === -1) {
|
||||
window.deletedIds.push(id);
|
||||
if (btn) btn.classList.replace('btn-outline-danger', 'btn-danger');
|
||||
if (btn) btn.textContent = 'Undelete';
|
||||
if (container) container.style.opacity = '0.5';
|
||||
} else {
|
||||
window.deletedIds.splice(idx, 1);
|
||||
if (btn) btn.classList.replace('btn-danger', 'btn-outline-danger');
|
||||
if (btn) btn.textContent = 'Delete';
|
||||
if (container) container.style.opacity = '1';
|
||||
}
|
||||
}
|
||||
|
||||
// Initial render
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const ids = [{% for n in items %} {{ n.id }}{% if not loop.last %}, {% endif %} {% endfor %} ];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue