This commit is contained in:
th committed 2026-04-06 21:39:37 +02:00
1 parent 0d4d369870
commit 9c71e65041
9 files changed
+423 -16

No files matched your search

+16 -2
View File
@@ -59,7 +59,11 @@ export function openModal(card = null) {
inpTitle.focus();
}
export function closeModal() { modal.classList.remove('open'); state.editingId = null; }
export function closeModal() {
modal.classList.remove('open');
state.editingId = null;
state.returnToGalleryAfterEdit = false;
}
function updatePreview() {
if (state.previewVisible) previewContent.innerHTML = renderMd(body.value);
@@ -68,16 +72,26 @@ function updatePreview() {
export async function saveCard() {
const data = { title: inpTitle.value, body: body.value, color: inpColor.value, bucket_id: inpBucket.value || null };
if (!data.title.trim()) return;
const returnToGallery = state.returnToGalleryAfterEdit;
if (state.editingId) {
const prev = snapshotCard(state.cards.find(c => c.id == state.editingId));
if (prev) pushCardEdit('edit', state.editingId, { title: prev.title, body: prev.body, color: prev.color, bucket_id: prev.bucket_id });
await api(`api/cards/${state.editingId}`, { method: 'PATCH', body: data });
} else {
data.position = -1;
if (state.activeGroup) {
const parent = state.cards.find(c => c.id == state.activeGroup);
const groupCards = parent ? [parent, ...state.cards.filter(c => c.parent_id == parent.id)] : [];
const maxPos = groupCards.reduce((max, c) => Math.max(max, Number(c.position) || 0), -1);
data.parent_id = parent ? parent.id : state.activeGroup;
data.position = maxPos + 1;
} else {
data.position = -1;
}
await api('api/cards', { method: 'POST', body: data });
}
closeModal();
await window._reloadAll();
if (returnToGallery) window._openGallery?.();
}
// ── Markdown toolbar ──