feat(mobile): add health tracking, milestones, messaging, and push registration
Health: consent gate (Art. 9 DSGVO) plus weight/vet-visit/vaccine log sections, gated behind health.getConsentStatus like the web app. Milestones: view a pet's milestone posts and create the 5 user-initiated types with an optional photo. Messaging: chat detail/compose screen (messages/[conversationId].tsx) polling while focused, reachable from the conversations list and from a pet profile's new "Nachricht" entry point. Push: usePushNotifications requests permission and registers the Expo push token with owner.registerPushToken; real delivery still needs an EAS project id (`eas init`), tracked in the README. All four verified live on a real Android emulator: health CRUD (add/list/ delete a weight log), Health/Milestones/Nachricht entry points gated correctly by own-pet vs. other-pet, and full chat history loading via an existing conversation. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0323e8d449
commit
a3f19ff70f
19 files changed
+1208
-31
No files matched your search
@@ -0,0 +1,172 @@
|
||||
import { useState, type ReactNode } from "react";
|
||||
import { View, Text, Pressable, ActivityIndicator, Linking, Alert, StyleSheet } from "react-native";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useRouter } from "expo-router";
|
||||
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";
|
||||
|
||||
type Props = {
|
||||
petId: string;
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
/**
|
||||
* Port of web's src/components/health/HealthConsentGate.tsx. Health-Tracking
|
||||
* data (weight, vet visits, vaccines) is gated behind explicit, un-pre-checked
|
||||
* consent per Art. 9 Abs. 2 lit. a DSGVO — this is the UI, health.ts's
|
||||
* assertHealthConsent is the actual enforcement boundary. Text copied
|
||||
* verbatim from messages/de.json's Health.consent namespace (mobile has no
|
||||
* i18n system yet).
|
||||
*/
|
||||
export function HealthConsentGate({ petId, children }: Props) {
|
||||
const trpc = useTRPC();
|
||||
const queryClient = useQueryClient();
|
||||
const router = useRouter();
|
||||
const [checked, setChecked] = useState(false);
|
||||
|
||||
const { data: status, isLoading } = useQuery(trpc.health.getConsentStatus.queryOptions({ petId }));
|
||||
|
||||
const invalidateHealthQueries = () => {
|
||||
queryClient.invalidateQueries({ queryKey: trpc.health.getConsentStatus.queryOptions({ petId }).queryKey });
|
||||
queryClient.invalidateQueries({ queryKey: trpc.health.listWeightLogs.queryOptions({ petId }).queryKey });
|
||||
queryClient.invalidateQueries({ queryKey: trpc.health.listVetVisits.queryOptions({ petId }).queryKey });
|
||||
queryClient.invalidateQueries({ queryKey: trpc.health.listVaccines.queryOptions({ petId }).queryKey });
|
||||
};
|
||||
|
||||
const giveMutation = useMutation(
|
||||
trpc.health.giveConsent.mutationOptions({
|
||||
onSuccess: invalidateHealthQueries,
|
||||
onError: () => Alert.alert("Einwilligung konnte nicht gespeichert werden."),
|
||||
})
|
||||
);
|
||||
|
||||
const revokeMutation = useMutation(
|
||||
trpc.health.revokeConsent.mutationOptions({
|
||||
onSuccess: invalidateHealthQueries,
|
||||
onError: () => Alert.alert("Einwilligung konnte nicht widerrufen werden."),
|
||||
})
|
||||
);
|
||||
|
||||
const confirmRevoke = () => {
|
||||
Alert.alert(
|
||||
"Einwilligung wirklich widerrufen?",
|
||||
"Dadurch werden alle Gewichtseinträge, Tierarztbesuche und Impfungen dieses Haustiers unwiderruflich gelöscht.",
|
||||
[
|
||||
{ text: "Abbrechen", style: "cancel" },
|
||||
{
|
||||
text: "Endgültig widerrufen und löschen",
|
||||
style: "destructive",
|
||||
onPress: () => revokeMutation.mutate({ petId }),
|
||||
},
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<View style={styles.center}>
|
||||
<ActivityIndicator color={colors.marigoldOrange} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (!status?.hasConsented) {
|
||||
return (
|
||||
<View style={styles.consentContainer}>
|
||||
<View style={styles.titleRow}>
|
||||
<HeartPulse color={colors.marigoldOrange} size={20} />
|
||||
<Text style={styles.title}>Einwilligung für Gesundheitsdaten</Text>
|
||||
</View>
|
||||
<Text style={styles.subtitle}>
|
||||
Bevor Sie den Health-Tracking-Bereich nutzen können, benötigen wir Ihre ausdrückliche Einwilligung zur
|
||||
Verarbeitung der Gesundheitsdaten Ihres Haustiers.
|
||||
</Text>
|
||||
|
||||
<Pressable style={styles.checkboxRow} onPress={() => setChecked((v) => !v)}>
|
||||
<View style={[styles.checkbox, checked && styles.checkboxChecked]}>
|
||||
{checked && <Check color={colors.pureWhite} size={14} />}
|
||||
</View>
|
||||
<Text style={styles.checkboxLabel}>
|
||||
Ich willige ausdrücklich ein, dass Gesundheitsdaten meines Haustiers (Gewicht, Tierarztbesuche,
|
||||
Impfungen) gespeichert und verarbeitet werden. Ich kann diese Einwilligung jederzeit widerrufen; danach
|
||||
werden alle Gesundheitsdaten dieses Haustiers automatisch gelöscht.
|
||||
</Text>
|
||||
</Pressable>
|
||||
|
||||
<Pressable onPress={() => Linking.openURL(`${env.apiUrl}/datenschutz`)}>
|
||||
<Text style={styles.privacyLink}>Weitere Informationen in unserer Datenschutzerklärung</Text>
|
||||
</Pressable>
|
||||
|
||||
<View style={styles.ctaRow}>
|
||||
<Button title="Abbrechen" variant="outline" style={styles.ctaButton} onPress={() => router.back()} />
|
||||
<Button
|
||||
title={giveMutation.isPending ? "…" : "Zustimmen und fortfahren"}
|
||||
style={styles.ctaButton}
|
||||
disabled={!checked || giveMutation.isPending}
|
||||
onPress={() => giveMutation.mutate({ petId })}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{children}
|
||||
<View style={styles.manageBox}>
|
||||
<ShieldOff color={colors.alertRed} size={18} />
|
||||
<View style={styles.manageText}>
|
||||
<Text style={styles.manageTitle}>Einwilligung verwalten</Text>
|
||||
<Text style={styles.manageDesc}>
|
||||
Ein Widerruf löscht sofort und unwiderruflich alle Gesundheitsdaten dieses Haustiers.
|
||||
</Text>
|
||||
</View>
|
||||
<Pressable onPress={confirmRevoke} disabled={revokeMutation.isPending}>
|
||||
<Text style={styles.revokeLink}>Widerrufen</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
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 },
|
||||
});
|
||||
@@ -0,0 +1,113 @@
|
||||
import { useState } from "react";
|
||||
import { View, Text, Pressable, ActivityIndicator, StyleSheet } from "react-native";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { Plus, Trash2 } from "lucide-react-native";
|
||||
import { useTRPC } from "../../api/trpc";
|
||||
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);
|
||||
|
||||
/** Port of web's health.ts vaccine CRUD — see health/page.tsx's Impfungen tab. */
|
||||
export function VaccineSection({ petId }: { petId: string }) {
|
||||
const trpc = useTRPC();
|
||||
const queryClient = useQueryClient();
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const [name, setName] = useState("");
|
||||
const [dateGiven, setDateGiven] = useState(today());
|
||||
const [nextDueDate, setNextDueDate] = useState("");
|
||||
const [notes, setNotes] = useState("");
|
||||
|
||||
const { data: vaccines = [], isLoading } = useQuery(trpc.health.listVaccines.queryOptions({ petId }));
|
||||
|
||||
const invalidate = () =>
|
||||
queryClient.invalidateQueries({ queryKey: trpc.health.listVaccines.queryOptions({ petId }).queryKey });
|
||||
|
||||
const addMutation = useMutation(
|
||||
trpc.health.addVaccine.mutationOptions({
|
||||
onSuccess: () => {
|
||||
invalidate();
|
||||
setShowForm(false);
|
||||
setName("");
|
||||
setNextDueDate("");
|
||||
setNotes("");
|
||||
setDateGiven(today());
|
||||
},
|
||||
})
|
||||
);
|
||||
const deleteMutation = useMutation(trpc.health.deleteVaccine.mutationOptions({ onSuccess: invalidate }));
|
||||
|
||||
const canSubmit = name.trim().length > 0 && dateGiven.length > 0 && !addMutation.isPending;
|
||||
const isOverdue = (nextDue: string | null) => !!nextDue && new Date(nextDue).getTime() < Date.now();
|
||||
|
||||
return (
|
||||
<View style={styles.section}>
|
||||
<View style={styles.sectionHeader}>
|
||||
<Text style={styles.sectionTitle}>Impfungen</Text>
|
||||
<Pressable onPress={() => setShowForm((v) => !v)} hitSlop={8}>
|
||||
<Plus color={colors.marigoldOrange} size={20} />
|
||||
</Pressable>
|
||||
</View>
|
||||
|
||||
{showForm && (
|
||||
<Card style={styles.form}>
|
||||
<TextField placeholder="Impfstoff, z.B. Tollwut, DHPP" value={name} onChangeText={setName} maxLength={100} />
|
||||
<TextField placeholder="Gegeben am (JJJJ-MM-TT)" value={dateGiven} onChangeText={setDateGiven} />
|
||||
<TextField placeholder="Nächste Fälligkeit (optional, JJJJ-MM-TT)" value={nextDueDate} onChangeText={setNextDueDate} />
|
||||
<TextField placeholder="Notizen (optional)" value={notes} onChangeText={setNotes} maxLength={200} />
|
||||
<Button
|
||||
title={addMutation.isPending ? "…" : "Speichern"}
|
||||
disabled={!canSubmit}
|
||||
onPress={() =>
|
||||
addMutation.mutate({
|
||||
petId,
|
||||
name: name.trim(),
|
||||
dateGiven,
|
||||
nextDueDate: nextDueDate.trim() || undefined,
|
||||
notes: notes.trim() || undefined,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{isLoading ? (
|
||||
<ActivityIndicator color={colors.marigoldOrange} />
|
||||
) : vaccines.length === 0 ? (
|
||||
<Text style={styles.empty}>Noch keine Impfungen eingetragen</Text>
|
||||
) : (
|
||||
vaccines.map((vaccine) => (
|
||||
<View key={vaccine.id} style={styles.row}>
|
||||
<View style={styles.rowText}>
|
||||
<Text style={styles.rowPrimary}>{vaccine.name}</Text>
|
||||
<Text style={styles.rowSecondary}>Gegeben {new Date(vaccine.dateGiven).toLocaleDateString("de-DE")}</Text>
|
||||
{vaccine.nextDueDate && (
|
||||
<Text style={[styles.rowSecondary, isOverdue(vaccine.nextDueDate) && styles.overdue]}>
|
||||
{isOverdue(vaccine.nextDueDate) ? "Überfällig" : `Fällig ${new Date(vaccine.nextDueDate).toLocaleDateString("de-DE")}`}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
<Pressable onPress={() => deleteMutation.mutate({ id: vaccine.id, petId })} hitSlop={8}>
|
||||
<Trash2 color={colors.quietGray} size={16} />
|
||||
</Pressable>
|
||||
</View>
|
||||
))
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
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 },
|
||||
});
|
||||
@@ -0,0 +1,111 @@
|
||||
import { useState } from "react";
|
||||
import { View, Text, Pressable, ActivityIndicator, StyleSheet } from "react-native";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { Plus, Trash2 } from "lucide-react-native";
|
||||
import { useTRPC } from "../../api/trpc";
|
||||
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);
|
||||
|
||||
/** Port of web's health.ts vetVisit CRUD — see health/page.tsx's Tierarzt tab. */
|
||||
export function VetVisitSection({ petId }: { petId: string }) {
|
||||
const trpc = useTRPC();
|
||||
const queryClient = useQueryClient();
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const [date, setDate] = useState(today());
|
||||
const [reason, setReason] = useState("");
|
||||
const [vetName, setVetName] = useState("");
|
||||
const [notes, setNotes] = useState("");
|
||||
|
||||
const { data: visits = [], isLoading } = useQuery(trpc.health.listVetVisits.queryOptions({ petId }));
|
||||
|
||||
const invalidate = () =>
|
||||
queryClient.invalidateQueries({ queryKey: trpc.health.listVetVisits.queryOptions({ petId }).queryKey });
|
||||
|
||||
const addMutation = useMutation(
|
||||
trpc.health.addVetVisit.mutationOptions({
|
||||
onSuccess: () => {
|
||||
invalidate();
|
||||
setShowForm(false);
|
||||
setReason("");
|
||||
setVetName("");
|
||||
setNotes("");
|
||||
setDate(today());
|
||||
},
|
||||
})
|
||||
);
|
||||
const deleteMutation = useMutation(trpc.health.deleteVetVisit.mutationOptions({ onSuccess: invalidate }));
|
||||
|
||||
const canSubmit = date.length > 0 && reason.trim().length > 0 && !addMutation.isPending;
|
||||
|
||||
return (
|
||||
<View style={styles.section}>
|
||||
<View style={styles.sectionHeader}>
|
||||
<Text style={styles.sectionTitle}>Tierarzt</Text>
|
||||
<Pressable onPress={() => setShowForm((v) => !v)} hitSlop={8}>
|
||||
<Plus color={colors.marigoldOrange} size={20} />
|
||||
</Pressable>
|
||||
</View>
|
||||
|
||||
{showForm && (
|
||||
<Card style={styles.form}>
|
||||
<TextField placeholder="JJJJ-MM-TT" value={date} onChangeText={setDate} />
|
||||
<TextField placeholder="Grund, z.B. Jahresuntersuchung" value={reason} onChangeText={setReason} maxLength={100} />
|
||||
<TextField placeholder="Tierarzt / Klinik (optional)" value={vetName} onChangeText={setVetName} maxLength={100} />
|
||||
<TextField placeholder="Notizen (optional)" value={notes} onChangeText={setNotes} maxLength={500} multiline />
|
||||
<Button
|
||||
title={addMutation.isPending ? "…" : "Speichern"}
|
||||
disabled={!canSubmit}
|
||||
onPress={() =>
|
||||
addMutation.mutate({
|
||||
petId,
|
||||
date,
|
||||
reason: reason.trim(),
|
||||
vetName: vetName.trim() || undefined,
|
||||
notes: notes.trim() || undefined,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{isLoading ? (
|
||||
<ActivityIndicator color={colors.marigoldOrange} />
|
||||
) : visits.length === 0 ? (
|
||||
<Text style={styles.empty}>Noch keine Tierarztbesuche</Text>
|
||||
) : (
|
||||
visits.map((visit) => (
|
||||
<View key={visit.id} style={styles.row}>
|
||||
<View style={styles.rowText}>
|
||||
<Text style={styles.rowPrimary}>{visit.reason}</Text>
|
||||
<Text style={styles.rowSecondary}>
|
||||
{new Date(visit.date).toLocaleDateString("de-DE")}
|
||||
{visit.vetName ? ` · ${visit.vetName}` : ""}
|
||||
</Text>
|
||||
{visit.notes ? <Text style={styles.rowNotes}>{visit.notes}</Text> : null}
|
||||
</View>
|
||||
<Pressable onPress={() => deleteMutation.mutate({ id: visit.id, petId })} hitSlop={8}>
|
||||
<Trash2 color={colors.quietGray} size={16} />
|
||||
</Pressable>
|
||||
</View>
|
||||
))
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
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 },
|
||||
});
|
||||
@@ -0,0 +1,99 @@
|
||||
import { useState } from "react";
|
||||
import { View, Text, Pressable, ActivityIndicator, StyleSheet } from "react-native";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { Plus, Trash2 } from "lucide-react-native";
|
||||
import { useTRPC } from "../../api/trpc";
|
||||
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);
|
||||
|
||||
/** 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 trpc = useTRPC();
|
||||
const queryClient = useQueryClient();
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const [date, setDate] = useState(today());
|
||||
const [weightKg, setWeightKg] = useState("");
|
||||
const [notes, setNotes] = useState("");
|
||||
|
||||
const { data: logs = [], isLoading } = useQuery(trpc.health.listWeightLogs.queryOptions({ petId }));
|
||||
|
||||
const invalidate = () =>
|
||||
queryClient.invalidateQueries({ queryKey: trpc.health.listWeightLogs.queryOptions({ petId }).queryKey });
|
||||
|
||||
const addMutation = useMutation(
|
||||
trpc.health.addWeightLog.mutationOptions({
|
||||
onSuccess: () => {
|
||||
invalidate();
|
||||
setShowForm(false);
|
||||
setWeightKg("");
|
||||
setNotes("");
|
||||
setDate(today());
|
||||
},
|
||||
})
|
||||
);
|
||||
const deleteMutation = useMutation(trpc.health.deleteWeightLog.mutationOptions({ onSuccess: invalidate }));
|
||||
|
||||
const parsedWeight = Number(weightKg.replace(",", "."));
|
||||
const canSubmit = date.length > 0 && parsedWeight > 0 && !addMutation.isPending;
|
||||
|
||||
return (
|
||||
<View style={styles.section}>
|
||||
<View style={styles.sectionHeader}>
|
||||
<Text style={styles.sectionTitle}>Gewicht</Text>
|
||||
<Pressable onPress={() => setShowForm((v) => !v)} hitSlop={8}>
|
||||
<Plus color={colors.marigoldOrange} size={20} />
|
||||
</Pressable>
|
||||
</View>
|
||||
|
||||
{showForm && (
|
||||
<Card style={styles.form}>
|
||||
<TextField placeholder="JJJJ-MM-TT" value={date} onChangeText={setDate} />
|
||||
<TextField placeholder="Gewicht (kg), z.B. 4,2" value={weightKg} onChangeText={setWeightKg} keyboardType="decimal-pad" />
|
||||
<TextField placeholder="Notizen (optional)" value={notes} onChangeText={setNotes} maxLength={200} />
|
||||
<Button
|
||||
title={addMutation.isPending ? "…" : "Speichern"}
|
||||
disabled={!canSubmit}
|
||||
onPress={() => addMutation.mutate({ petId, date, weightKg: parsedWeight, notes: notes.trim() || undefined })}
|
||||
/>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{isLoading ? (
|
||||
<ActivityIndicator color={colors.marigoldOrange} />
|
||||
) : logs.length === 0 ? (
|
||||
<Text style={styles.empty}>Noch keine Gewichtseinträge</Text>
|
||||
) : (
|
||||
logs.map((log) => (
|
||||
<View key={log.id} style={styles.row}>
|
||||
<View style={styles.rowText}>
|
||||
<Text style={styles.rowPrimary}>{(log.weightGrams / 1000).toLocaleString("de-DE")} kg</Text>
|
||||
<Text style={styles.rowSecondary}>
|
||||
{new Date(log.date).toLocaleDateString("de-DE")}
|
||||
{log.notes ? ` · ${log.notes}` : ""}
|
||||
</Text>
|
||||
</View>
|
||||
<Pressable onPress={() => deleteMutation.mutate({ id: log.id, petId })} hitSlop={8}>
|
||||
<Trash2 color={colors.quietGray} size={16} />
|
||||
</Pressable>
|
||||
</View>
|
||||
))
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
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 },
|
||||
});
|
||||
Reference in new issue
Block a user