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")}

+ )} +