Fix ingredient modal closing recipe editor

Ingredient modal's onSubmit returned undefined → showModal treated it
as success → closeModal + renderScreen → killed the parent recipe editor.

Fix: ingredient onSubmit returns "norender", showModal checks for it
and skips renderScreen. Modal still closes via closeModal/history.back,
returning to the recipe editor with the new ingredient added.
This commit is contained in:
4aiman 2026-05-27 20:53:00 +03:00
commit d59013cc62

View file

@ -868,7 +868,7 @@ function showModal(html, onSubmit) {
overlay.querySelector("#modal-cancel").onclick = () => closeModal();
overlay.querySelector("#modal-ok").onclick = async () => {
const ok = await onSubmit(overlay);
if (ok !== false) { closeModal(); renderScreen(state.screen); }
if (ok !== false) { closeModal(); if (ok !== "norender") renderScreen(state.screen); }
};
setTimeout(() => overlay.querySelector("input")?.focus(), 50);
}
@ -1689,6 +1689,7 @@ function showAddIngredientModal(cookingMethods, onAdd) {
_product: null,
});
}
return "norender"; // sub-modal: close without re-rendering parent screen
});
const overlays = document.querySelectorAll(".modal-overlay");