fix(mobile): found.md batch — reports, dark mode, health form fixes

- new report feature: a "..." button on every post opens a reason-picker
  sheet (reports.create), matching web's ReportSheet reasons/copy
- pet profile, edit, followers/following, and the whole health screen
  (incl. consent gate) converted to the makeStyles(colors) dark-mode
  pattern
- fixed the invisible back button on every pushed (app)/_layout.tsx
  screen: headerTintColor was never set, so the native-stack default
  back chevron kept its platform tint instead of the theme color —
  black-on-black in dark mode looked like a missing button entirely
- health forms (weight/vet visit/vaccine) now take dates as DD-MM-YYYY
  instead of the backend's raw YYYY-MM-DD, converting internally
  (src/lib/date-format.ts); invalid dates now show an error instead of
  the mutation silently failing with no onError handler at all — this,
  not persistence, was the actual "Gesundheitsdaten werden nicht
  gespeichert" bug
- pinch-to-zoom on the full-screen image viewer via a plain
  PanResponder (no new native dependency)
- Pets tab: language switcher now uses flag emoji (🇩🇪/🇬🇧/🌐), and a
  new footer section links Impressum/Datenschutz/Nutzungsbedingungen
  plus the installed app version

All live-verified against the deployed backend except pinch-zoom
(two-finger gestures aren't simulatable over adb).
This commit is contained in:
admin committed 2026-09-06 18:55:12 +02:00
1 parent 462f295caa
commit 4a35fce20b
19 files changed
+615 -214

No files matched your search

+27 -12
View File
@@ -1,14 +1,15 @@
import { useMemo } from "react";
import { useMemo, useState } from "react";
import { View, Text, Pressable, StyleSheet, ScrollView, useWindowDimensions } from "react-native";
import { useRouter } from "expo-router";
import { Image } from "expo-image";
import { MessageCircle } from "lucide-react-native";
import { MessageCircle, MoreVertical } from "lucide-react-native";
import { PetAvatar } from "./PetAvatar";
import { PetIdentityBadges } from "./PetIdentityBadges";
import { PawButton } from "./PawButton";
import { PawBackButton } from "./PawBackButton";
import { RepostCard } from "./RepostCard";
import { VideoPlayer } from "./VideoPlayer";
import { ReportSheet } from "./ReportSheet";
import { getMediaUrl } from "../lib/media-url";
import { formatPetName, formatRelativeTime } from "../lib/format";
import { useTheme } from "../context/ThemeContext";
@@ -77,6 +78,7 @@ export function PostCard({ post, actingPetId }: Props) {
const { colors } = useTheme();
const styles = useMemo(() => makeStyles(colors), [colors]);
const cardWidth = width - 32; // matches the 16px screen padding used by the feed list
const [reportOpen, setReportOpen] = useState(false);
// Reposts ("Paw-Backs") delegate to RepostCard — a read-only wrapper
// around the original post, no action row (matches web).
@@ -91,16 +93,27 @@ export function PostCard({ post, actingPetId }: Props) {
return (
<View style={styles.card}>
<Pressable style={styles.header} onPress={() => router.push(`/pets/${post.pet.id}`)}>
<PetAvatar name={post.pet.name} avatarKey={post.pet.avatarKey} />
<View style={styles.headerText}>
<View style={styles.nameRow}>
<Text style={styles.name}>{formatPetName(post.pet)}</Text>
<PetIdentityBadges isVerified={post.pet.isVerified} sponsor={post.pet.owner} />
<View style={styles.headerRow}>
<Pressable style={styles.header} onPress={() => router.push(`/pets/${post.pet.id}`)}>
<PetAvatar name={post.pet.name} avatarKey={post.pet.avatarKey} />
<View style={styles.headerText}>
<View style={styles.nameRow}>
<Text style={styles.name}>{formatPetName(post.pet)}</Text>
<PetIdentityBadges isVerified={post.pet.isVerified} sponsor={post.pet.owner} />
</View>
<Text style={styles.timestamp}>{formatRelativeTime(post.createdAt)}</Text>
</View>
<Text style={styles.timestamp}>{formatRelativeTime(post.createdAt)}</Text>
</View>
</Pressable>
</Pressable>
<Pressable style={styles.moreButton} onPress={() => setReportOpen(true)} hitSlop={8}>
<MoreVertical size={18} color={colors.quietGray} />
</Pressable>
</View>
<ReportSheet
visible={reportOpen}
onClose={() => setReportOpen(false)}
reporterPetId={actingPetId}
targetPostId={post.id}
/>
{post.type === "VIDEO" && post.videoPost ? (
<VideoPlayer
@@ -170,7 +183,9 @@ function makeStyles(colors: ColorTokens) {
const typography: Typography = getTypography(colors);
return StyleSheet.create({
card: { gap: 10 },
header: { flexDirection: "row", alignItems: "center", gap: 10 },
headerRow: { flexDirection: "row", alignItems: "center" },
header: { flex: 1, flexDirection: "row", alignItems: "center", gap: 10 },
moreButton: { padding: 4 },
headerText: { flex: 1 },
nameRow: { flexDirection: "row", alignItems: "center" },
name: { ...typography.body, fontFamily: typography.title.fontFamily },
+100
View File
@@ -0,0 +1,100 @@
import { useMemo, useState } from "react";
import { Modal, View, Text, Pressable, Alert, StyleSheet } from "react-native";
import { useMutation } from "@tanstack/react-query";
import { useTranslation } from "react-i18next";
import { useTRPC } from "../api/trpc";
import { useTheme } from "../context/ThemeContext";
import { getTypography, radii, type ColorTokens, type Typography } from "../theme/tokens";
type ReportReason = "SPAM" | "HARASSMENT" | "INAPPROPRIATE" | "MISINFORMATION" | "OTHER";
const REASONS: ReportReason[] = ["SPAM", "HARASSMENT", "INAPPROPRIATE", "MISINFORMATION", "OTHER"];
type Props = {
visible: boolean;
onClose: () => void;
reporterPetId: string;
/** Mutually exclusive — set one or the other, matching the backend's targetPostId XOR targetPetId. */
targetPostId?: string;
targetPetId?: string;
};
/**
* Port of web's src/components/safety/ReportSheet.tsx (SAFE-02), trimmed for
* mobile v1: tapping a reason submits immediately instead of a separate
* radio-then-submit step, and there's no optional notes textarea yet — the
* backend already accepts one (`reports.create`'s `notes` field), so this is
* a real, if narrower, gap versus web rather than a stub.
*/
export function ReportSheet({ visible, onClose, reporterPetId, targetPostId, targetPetId }: Props) {
const { t } = useTranslation();
const trpc = useTRPC();
const { colors } = useTheme();
const styles = useMemo(() => makeStyles(colors), [colors]);
const [pendingReason, setPendingReason] = useState<ReportReason | null>(null);
const reportMutation = useMutation(
trpc.reports.create.mutationOptions({
onSuccess: () => {
setPendingReason(null);
onClose();
Alert.alert(t("report.successToast"));
},
onError: (err) => {
setPendingReason(null);
Alert.alert(err.data?.code === "CONFLICT" ? t("report.alreadyReported") : t("report.errorToast"));
},
})
);
const submit = (reason: ReportReason) => {
setPendingReason(reason);
reportMutation.mutate({ reporterPetId, targetPostId, targetPetId, reason });
};
return (
<Modal visible={visible} transparent animationType="slide" onRequestClose={onClose}>
<Pressable style={styles.backdrop} onPress={onClose}>
<Pressable style={styles.sheet} onPress={(e) => e.stopPropagation()}>
<Text style={styles.title}>{t("report.title")}</Text>
<Text style={styles.question}>{t("report.reasonQuestion")}</Text>
{REASONS.map((reason) => (
<Pressable
key={reason}
style={styles.reasonRow}
onPress={() => submit(reason)}
disabled={reportMutation.isPending}
>
<Text style={styles.reasonText}>
{pendingReason === reason ? "…" : t(`report.reason${reason}`)}
</Text>
</Pressable>
))}
<Pressable style={styles.cancelRow} onPress={onClose} disabled={reportMutation.isPending}>
<Text style={styles.cancelText}>{t("report.cancel")}</Text>
</Pressable>
</Pressable>
</Pressable>
</Modal>
);
}
function makeStyles(colors: ColorTokens) {
const typography: Typography = getTypography(colors);
return StyleSheet.create({
backdrop: { flex: 1, backgroundColor: "rgba(0,0,0,0.4)", justifyContent: "flex-end" },
sheet: {
backgroundColor: colors.pureWhite,
borderTopLeftRadius: radii["2xl"],
borderTopRightRadius: radii["2xl"],
padding: 20,
gap: 4,
},
title: { ...typography.title, fontSize: 18 },
question: { ...typography.body, color: colors.quietGray, marginBottom: 8 },
reasonRow: { paddingVertical: 14, borderBottomWidth: 1, borderBottomColor: colors.hairlineGray },
reasonText: { ...typography.body },
cancelRow: { paddingVertical: 16, alignItems: "center" },
cancelText: { ...typography.body, color: colors.quietGray },
});
}
@@ -1,4 +1,4 @@
import { useState, type ReactNode } from "react";
import { useMemo, useState, type ReactNode } from "react";
import { View, Text, Pressable, ActivityIndicator, Linking, Alert, StyleSheet } from "react-native";
import { useTranslation } from "react-i18next";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
@@ -7,7 +7,8 @@ import { HeartPulse, ShieldOff, Check } from "lucide-react-native";
import { useTRPC } from "../../api/trpc";
import { env } from "../../lib/env";
import { Button } from "../Button";
import { colors, radii, typography } from "../../theme/tokens";
import { useTheme } from "../../context/ThemeContext";
import { radii, getTypography, type ColorTokens, type Typography } from "../../theme/tokens";
type Props = {
petId: string;
@@ -25,6 +26,8 @@ export function HealthConsentGate({ petId, children }: Props) {
const trpc = useTRPC();
const queryClient = useQueryClient();
const router = useRouter();
const { colors } = useTheme();
const styles = useMemo(() => makeStyles(colors), [colors]);
const [checked, setChecked] = useState(false);
const { data: status, isLoading } = useQuery(trpc.health.getConsentStatus.queryOptions({ petId }));
@@ -123,41 +126,44 @@ export function HealthConsentGate({ petId, children }: Props) {
);
}
const styles = StyleSheet.create({
center: { flex: 1, alignItems: "center", justifyContent: "center", padding: 40 },
consentContainer: { padding: 20, gap: 4 },
titleRow: { flexDirection: "row", alignItems: "center", gap: 8, marginBottom: 4 },
title: { ...typography.title, fontSize: 18 },
subtitle: { ...typography.body, color: colors.quietGray, marginBottom: 16 },
checkboxRow: { flexDirection: "row", gap: 12, padding: 14, borderRadius: radii.xl, borderWidth: 1, borderColor: colors.hairlineGray, marginBottom: 16 },
checkbox: {
width: 20,
height: 20,
borderRadius: 5,
borderWidth: 1.5,
borderColor: colors.hairlineGray,
alignItems: "center",
justifyContent: "center",
marginTop: 2,
},
checkboxChecked: { backgroundColor: colors.marigoldOrange, borderColor: colors.marigoldOrange },
checkboxLabel: { ...typography.body, flex: 1, fontSize: 13, lineHeight: 19 },
privacyLink: { ...typography.label, textTransform: "none", letterSpacing: 0, color: colors.marigoldDeep, marginBottom: 20 },
ctaRow: { flexDirection: "row", gap: 10 },
ctaButton: { flex: 1 },
manageBox: {
flexDirection: "row",
alignItems: "flex-start",
gap: 10,
margin: 16,
padding: 14,
borderRadius: radii.xl,
borderWidth: 1,
borderColor: colors.alertRedTint,
backgroundColor: colors.alertRedTint,
},
manageText: { flex: 1 },
manageTitle: { ...typography.body, fontFamily: typography.title.fontFamily, fontSize: 13 },
manageDesc: { ...typography.label, textTransform: "none", letterSpacing: 0, marginTop: 2 },
revokeLink: { ...typography.body, color: colors.alertRed, fontFamily: typography.title.fontFamily, fontSize: 13 },
});
function makeStyles(colors: ColorTokens) {
const typography: Typography = getTypography(colors);
return StyleSheet.create({
center: { flex: 1, alignItems: "center", justifyContent: "center", padding: 40 },
consentContainer: { padding: 20, gap: 4 },
titleRow: { flexDirection: "row", alignItems: "center", gap: 8, marginBottom: 4 },
title: { ...typography.title, fontSize: 18 },
subtitle: { ...typography.body, color: colors.quietGray, marginBottom: 16 },
checkboxRow: { flexDirection: "row", gap: 12, padding: 14, borderRadius: radii.xl, borderWidth: 1, borderColor: colors.hairlineGray, marginBottom: 16 },
checkbox: {
width: 20,
height: 20,
borderRadius: 5,
borderWidth: 1.5,
borderColor: colors.hairlineGray,
alignItems: "center",
justifyContent: "center",
marginTop: 2,
},
checkboxChecked: { backgroundColor: colors.marigoldOrange, borderColor: colors.marigoldOrange },
checkboxLabel: { ...typography.body, flex: 1, fontSize: 13, lineHeight: 19 },
privacyLink: { ...typography.label, textTransform: "none", letterSpacing: 0, color: colors.marigoldDeep, marginBottom: 20 },
ctaRow: { flexDirection: "row", gap: 10 },
ctaButton: { flex: 1 },
manageBox: {
flexDirection: "row",
alignItems: "flex-start",
gap: 10,
margin: 16,
padding: 14,
borderRadius: radii.xl,
borderWidth: 1,
borderColor: colors.alertRedTint,
backgroundColor: colors.alertRedTint,
},
manageText: { flex: 1 },
manageTitle: { ...typography.body, fontFamily: typography.title.fontFamily, fontSize: 13 },
manageDesc: { ...typography.label, textTransform: "none", letterSpacing: 0, marginTop: 2 },
revokeLink: { ...typography.body, color: colors.alertRed, fontFamily: typography.title.fontFamily, fontSize: 13 },
});
}
+48 -29
View File
@@ -1,24 +1,26 @@
import { useState } from "react";
import { View, Text, Pressable, ActivityIndicator, StyleSheet } from "react-native";
import { useMemo, useState } from "react";
import { View, Text, Pressable, ActivityIndicator, Alert, StyleSheet } from "react-native";
import { useTranslation } from "react-i18next";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { Plus, Trash2 } from "lucide-react-native";
import { useTRPC } from "../../api/trpc";
import { useTheme } from "../../context/ThemeContext";
import { TextField } from "../TextField";
import { Button } from "../Button";
import { Card } from "../Card";
import { colors, typography } from "../../theme/tokens";
const today = () => new Date().toISOString().slice(0, 10);
import { getTypography, type ColorTokens, type Typography } from "../../theme/tokens";
import { displayDateToIso, todayAsDisplayDate } from "../../lib/date-format";
/** Port of web's health.ts vaccine CRUD — see health/page.tsx's Impfungen tab. */
export function VaccineSection({ petId }: { petId: string }) {
const { t, i18n } = useTranslation();
const trpc = useTRPC();
const queryClient = useQueryClient();
const { colors } = useTheme();
const styles = useMemo(() => makeStyles(colors), [colors]);
const [showForm, setShowForm] = useState(false);
const [name, setName] = useState("");
const [dateGiven, setDateGiven] = useState(today());
const [dateGiven, setDateGiven] = useState(todayAsDisplayDate());
const [nextDueDate, setNextDueDate] = useState("");
const [notes, setNotes] = useState("");
@@ -35,15 +37,37 @@ export function VaccineSection({ petId }: { petId: string }) {
setName("");
setNextDueDate("");
setNotes("");
setDateGiven(today());
setDateGiven(todayAsDisplayDate());
},
onError: () => Alert.alert(t("health.saveError")),
})
);
const deleteMutation = useMutation(trpc.health.deleteVaccine.mutationOptions({ onSuccess: invalidate }));
const canSubmit = name.trim().length > 0 && dateGiven.length > 0 && !addMutation.isPending;
const canSubmit = name.trim().length > 0 && !!displayDateToIso(dateGiven) && !addMutation.isPending;
const isOverdue = (nextDue: string | null) => !!nextDue && new Date(nextDue).getTime() < Date.now();
const handleSubmit = () => {
const isoDateGiven = displayDateToIso(dateGiven);
if (!isoDateGiven) {
Alert.alert(t("health.invalidDate"));
return;
}
const trimmedNextDue = nextDueDate.trim();
const isoNextDue = trimmedNextDue ? displayDateToIso(trimmedNextDue) : null;
if (trimmedNextDue && !isoNextDue) {
Alert.alert(t("health.invalidDate"));
return;
}
addMutation.mutate({
petId,
name: name.trim(),
dateGiven: isoDateGiven,
nextDueDate: isoNextDue ?? undefined,
notes: notes.trim() || undefined,
});
};
return (
<View style={styles.section}>
<View style={styles.sectionHeader}>
@@ -62,15 +86,7 @@ export function VaccineSection({ petId }: { petId: string }) {
<Button
title={addMutation.isPending ? "…" : t("common.save")}
disabled={!canSubmit}
onPress={() =>
addMutation.mutate({
petId,
name: name.trim(),
dateGiven,
nextDueDate: nextDueDate.trim() || undefined,
notes: notes.trim() || undefined,
})
}
onPress={handleSubmit}
/>
</Card>
)}
@@ -105,15 +121,18 @@ export function VaccineSection({ petId }: { petId: string }) {
);
}
const styles = StyleSheet.create({
section: { gap: 10 },
sectionHeader: { flexDirection: "row", alignItems: "center", justifyContent: "space-between" },
sectionTitle: { ...typography.title, fontSize: 16 },
form: { gap: 10 },
empty: { ...typography.body, color: colors.quietGray },
row: { flexDirection: "row", alignItems: "flex-start", justifyContent: "space-between", paddingVertical: 8, borderBottomWidth: 1, borderBottomColor: colors.hairlineGray },
rowText: { flex: 1, gap: 2 },
rowPrimary: { ...typography.body, fontFamily: typography.title.fontFamily },
rowSecondary: { ...typography.label, textTransform: "none", letterSpacing: 0 },
overdue: { color: colors.alertRed },
});
function makeStyles(colors: ColorTokens) {
const typography: Typography = getTypography(colors);
return StyleSheet.create({
section: { gap: 10 },
sectionHeader: { flexDirection: "row", alignItems: "center", justifyContent: "space-between" },
sectionTitle: { ...typography.title, fontSize: 16 },
form: { gap: 10 },
empty: { ...typography.body, color: colors.quietGray },
row: { flexDirection: "row", alignItems: "flex-start", justifyContent: "space-between", paddingVertical: 8, borderBottomWidth: 1, borderBottomColor: colors.hairlineGray },
rowText: { flex: 1, gap: 2 },
rowPrimary: { ...typography.body, fontFamily: typography.title.fontFamily },
rowSecondary: { ...typography.label, textTransform: "none", letterSpacing: 0 },
overdue: { color: colors.alertRed },
});
}
@@ -1,23 +1,25 @@
import { useState } from "react";
import { View, Text, Pressable, ActivityIndicator, StyleSheet } from "react-native";
import { useMemo, useState } from "react";
import { View, Text, Pressable, ActivityIndicator, Alert, StyleSheet } from "react-native";
import { useTranslation } from "react-i18next";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { Plus, Trash2 } from "lucide-react-native";
import { useTRPC } from "../../api/trpc";
import { useTheme } from "../../context/ThemeContext";
import { TextField } from "../TextField";
import { Button } from "../Button";
import { Card } from "../Card";
import { colors, typography } from "../../theme/tokens";
const today = () => new Date().toISOString().slice(0, 10);
import { getTypography, type ColorTokens, type Typography } from "../../theme/tokens";
import { displayDateToIso, todayAsDisplayDate } from "../../lib/date-format";
/** Port of web's health.ts vetVisit CRUD — see health/page.tsx's Tierarzt tab. */
export function VetVisitSection({ petId }: { petId: string }) {
const { t, i18n } = useTranslation();
const trpc = useTRPC();
const queryClient = useQueryClient();
const { colors } = useTheme();
const styles = useMemo(() => makeStyles(colors), [colors]);
const [showForm, setShowForm] = useState(false);
const [date, setDate] = useState(today());
const [date, setDate] = useState(todayAsDisplayDate());
const [reason, setReason] = useState("");
const [vetName, setVetName] = useState("");
const [notes, setNotes] = useState("");
@@ -35,13 +37,29 @@ export function VetVisitSection({ petId }: { petId: string }) {
setReason("");
setVetName("");
setNotes("");
setDate(today());
setDate(todayAsDisplayDate());
},
onError: () => Alert.alert(t("health.saveError")),
})
);
const deleteMutation = useMutation(trpc.health.deleteVetVisit.mutationOptions({ onSuccess: invalidate }));
const canSubmit = date.length > 0 && reason.trim().length > 0 && !addMutation.isPending;
const canSubmit = !!displayDateToIso(date) && reason.trim().length > 0 && !addMutation.isPending;
const handleSubmit = () => {
const isoDate = displayDateToIso(date);
if (!isoDate) {
Alert.alert(t("health.invalidDate"));
return;
}
addMutation.mutate({
petId,
date: isoDate,
reason: reason.trim(),
vetName: vetName.trim() || undefined,
notes: notes.trim() || undefined,
});
};
return (
<View style={styles.section}>
@@ -61,15 +79,7 @@ export function VetVisitSection({ petId }: { petId: string }) {
<Button
title={addMutation.isPending ? "…" : t("common.save")}
disabled={!canSubmit}
onPress={() =>
addMutation.mutate({
petId,
date,
reason: reason.trim(),
vetName: vetName.trim() || undefined,
notes: notes.trim() || undefined,
})
}
onPress={handleSubmit}
/>
</Card>
)}
@@ -99,15 +109,18 @@ export function VetVisitSection({ petId }: { petId: string }) {
);
}
const styles = StyleSheet.create({
section: { gap: 10 },
sectionHeader: { flexDirection: "row", alignItems: "center", justifyContent: "space-between" },
sectionTitle: { ...typography.title, fontSize: 16 },
form: { gap: 10 },
empty: { ...typography.body, color: colors.quietGray },
row: { flexDirection: "row", alignItems: "flex-start", justifyContent: "space-between", paddingVertical: 8, borderBottomWidth: 1, borderBottomColor: colors.hairlineGray },
rowText: { flex: 1, gap: 2 },
rowPrimary: { ...typography.body, fontFamily: typography.title.fontFamily },
rowSecondary: { ...typography.label, textTransform: "none", letterSpacing: 0 },
rowNotes: { ...typography.body, fontSize: 13, marginTop: 2 },
});
function makeStyles(colors: ColorTokens) {
const typography: Typography = getTypography(colors);
return StyleSheet.create({
section: { gap: 10 },
sectionHeader: { flexDirection: "row", alignItems: "center", justifyContent: "space-between" },
sectionTitle: { ...typography.title, fontSize: 16 },
form: { gap: 10 },
empty: { ...typography.body, color: colors.quietGray },
row: { flexDirection: "row", alignItems: "flex-start", justifyContent: "space-between", paddingVertical: 8, borderBottomWidth: 1, borderBottomColor: colors.hairlineGray },
rowText: { flex: 1, gap: 2 },
rowPrimary: { ...typography.body, fontFamily: typography.title.fontFamily },
rowSecondary: { ...typography.label, textTransform: "none", letterSpacing: 0 },
rowNotes: { ...typography.body, fontSize: 13, marginTop: 2 },
});
}
@@ -1,23 +1,25 @@
import { useState } from "react";
import { View, Text, Pressable, ActivityIndicator, StyleSheet } from "react-native";
import { useMemo, useState } from "react";
import { View, Text, Pressable, ActivityIndicator, Alert, StyleSheet } from "react-native";
import { useTranslation } from "react-i18next";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { Plus, Trash2 } from "lucide-react-native";
import { useTRPC } from "../../api/trpc";
import { useTheme } from "../../context/ThemeContext";
import { TextField } from "../TextField";
import { Button } from "../Button";
import { Card } from "../Card";
import { colors, typography } from "../../theme/tokens";
const today = () => new Date().toISOString().slice(0, 10);
import { getTypography, type ColorTokens, type Typography } from "../../theme/tokens";
import { displayDateToIso, todayAsDisplayDate } from "../../lib/date-format";
/** Port of web's health.ts weightLog CRUD — see src/app/(app)/pets/[petId]/health/page.tsx's Gewicht tab. */
export function WeightLogSection({ petId }: { petId: string }) {
const { t, i18n } = useTranslation();
const trpc = useTRPC();
const queryClient = useQueryClient();
const { colors } = useTheme();
const styles = useMemo(() => makeStyles(colors), [colors]);
const [showForm, setShowForm] = useState(false);
const [date, setDate] = useState(today());
const [date, setDate] = useState(todayAsDisplayDate());
const [weightKg, setWeightKg] = useState("");
const [notes, setNotes] = useState("");
@@ -33,14 +35,24 @@ export function WeightLogSection({ petId }: { petId: string }) {
setShowForm(false);
setWeightKg("");
setNotes("");
setDate(today());
setDate(todayAsDisplayDate());
},
onError: () => Alert.alert(t("health.saveError")),
})
);
const deleteMutation = useMutation(trpc.health.deleteWeightLog.mutationOptions({ onSuccess: invalidate }));
const parsedWeight = Number(weightKg.replace(",", "."));
const canSubmit = date.length > 0 && parsedWeight > 0 && !addMutation.isPending;
const canSubmit = !!displayDateToIso(date) && parsedWeight > 0 && !addMutation.isPending;
const handleSubmit = () => {
const isoDate = displayDateToIso(date);
if (!isoDate) {
Alert.alert(t("health.invalidDate"));
return;
}
addMutation.mutate({ petId, date: isoDate, weightKg: parsedWeight, notes: notes.trim() || undefined });
};
return (
<View style={styles.section}>
@@ -59,7 +71,7 @@ export function WeightLogSection({ petId }: { petId: string }) {
<Button
title={addMutation.isPending ? "…" : t("common.save")}
disabled={!canSubmit}
onPress={() => addMutation.mutate({ petId, date, weightKg: parsedWeight, notes: notes.trim() || undefined })}
onPress={handleSubmit}
/>
</Card>
)}
@@ -88,14 +100,17 @@ export function WeightLogSection({ petId }: { petId: string }) {
);
}
const styles = StyleSheet.create({
section: { gap: 10 },
sectionHeader: { flexDirection: "row", alignItems: "center", justifyContent: "space-between" },
sectionTitle: { ...typography.title, fontSize: 16 },
form: { gap: 10 },
empty: { ...typography.body, color: colors.quietGray },
row: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", paddingVertical: 8, borderBottomWidth: 1, borderBottomColor: colors.hairlineGray },
rowText: { flex: 1, gap: 2 },
rowPrimary: { ...typography.body, fontFamily: typography.title.fontFamily },
rowSecondary: { ...typography.label, textTransform: "none", letterSpacing: 0 },
});
function makeStyles(colors: ColorTokens) {
const typography: Typography = getTypography(colors);
return StyleSheet.create({
section: { gap: 10 },
sectionHeader: { flexDirection: "row", alignItems: "center", justifyContent: "space-between" },
sectionTitle: { ...typography.title, fontSize: 16 },
form: { gap: 10 },
empty: { ...typography.body, color: colors.quietGray },
row: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", paddingVertical: 8, borderBottomWidth: 1, borderBottomColor: colors.hairlineGray },
rowText: { flex: 1, gap: 2 },
rowPrimary: { ...typography.body, fontFamily: typography.title.fontFamily },
rowSecondary: { ...typography.label, textTransform: "none", letterSpacing: 0 },
});
}