From 0ffab23b6d734fefc82bc9803a87d61910a1c87e Mon Sep 17 00:00:00 2001 From: Daniel Volz Date: Sat, 14 Feb 2026 19:22:37 +0100 Subject: [PATCH] feat: add back button in medication edit header (#201) --- frontend/src/components/MobileEditModal.tsx | 3 + frontend/src/i18n/de.json | 1 + frontend/src/i18n/en.json | 1 + frontend/src/pages/MedicationsPage.tsx | 63 +++++++++++++++------ 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/frontend/src/components/MobileEditModal.tsx b/frontend/src/components/MobileEditModal.tsx index 9a8401d..69e0221 100644 --- a/frontend/src/components/MobileEditModal.tsx +++ b/frontend/src/components/MobileEditModal.tsx @@ -125,6 +125,9 @@ export function MobileEditModal({ ×
+

{editingId ? t("form.editEntry") : t("form.newEntry")}

{ + if (!editingId) { + return meds; + } + + const selectedMedication = meds.find((med) => med.id === editingId); + if (!selectedMedication) { + return meds; + } + + return [selectedMedication, ...meds.filter((med) => med.id !== editingId)]; + }, [meds, editingId]); + + const medListRef = useRef(null); + useEffect(() => { + if (viewMode !== "form" || !editingId) { + return; + } + + if (medListRef.current) { + medListRef.current.scrollTop = 0; + } + }, [viewMode, editingId]); + return (
{viewMode === "grid" ? ( @@ -361,7 +385,7 @@ export function MedicationsPage() {
- {meds.map((med) => ( + {orderedMeds.map((med) => (
@@ -461,8 +485,8 @@ export function MedicationsPage() { + {t("form.newEntry")}
-
- {meds.map((med) => ( +
+ {orderedMeds.map((med) => (
@@ -547,20 +571,25 @@ export function MedicationsPage() {
- {editingId ? ( -
- m.id === editingId)?.name || ""} - imageUrl={meds.find((m) => m.id === editingId)?.imageUrl} - size="md" - /> -

- {t("form.editEntry")}: {meds.find((m) => m.id === editingId)?.name} -

-
- ) : ( -

{t("form.newEntry")}

- )} +
+ + {editingId ? ( + <> + m.id === editingId)?.name || ""} + imageUrl={meds.find((m) => m.id === editingId)?.imageUrl} + size="md" + /> +

+ {t("form.editEntry")}: {meds.find((m) => m.id === editingId)?.name} +

+ + ) : ( +

{t("form.newEntry")}

+ )} +