fix(mobile): dark mode + nested-scroll fix in pet creation, invalidate pets.list after create
- PetCreateForm.tsx and onboarding/pet.tsx used the static light-only colors/typography tokens instead of useTheme() — pet creation stayed light even in dark mode. - onboarding/pet.tsx wrapped its steps in a plain ScrollView; the breed OptionPicker nests its own vertical ScrollView, and two same-axis ScrollViews swallow the inner one's scroll gesture on Android even with nestedScrollEnabled. Switched the outer container to a FlatList (empty data + ListHeaderComponent), matching explore.tsx's already working fix for the same component. - pets.create's mutation never invalidated trpc.pets.list, so ActivePetContext kept seeing zero pets after the first pet was created — OnboardingRedirect then bounced the user straight back to /onboarding/pet after the avatar step, with only an app restart breaking the loop. Added the missing invalidateQueries call.
This commit is contained in:
1 parent
c94df5fc6b
commit
f700000e87
3 files changed
+54
-18
No files matched your search
@@ -1,12 +1,13 @@
|
||||
import { useState } from "react";
|
||||
import { useMemo, useState } from "react";
|
||||
import { View, Text, StyleSheet } from "react-native";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useTRPC } from "../../api/trpc";
|
||||
import { TextField } from "../TextField";
|
||||
import { Button } from "../Button";
|
||||
import { OptionPicker, type PickerOption } from "../OptionPicker";
|
||||
import { colors, typography } from "../../theme/tokens";
|
||||
import { useTheme } from "../../context/ThemeContext";
|
||||
import { getTypography, type ColorTokens } from "../../theme/tokens";
|
||||
|
||||
type Props = { onSuccess: (pet: { id: string; name: string }) => void };
|
||||
|
||||
@@ -19,6 +20,9 @@ type Props = { onSuccess: (pet: { id: string; name: string }) => void };
|
||||
export function PetCreateForm({ onSuccess }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const trpc = useTRPC();
|
||||
const queryClient = useQueryClient();
|
||||
const { colors } = useTheme();
|
||||
const styles = useMemo(() => makeStyles(colors), [colors]);
|
||||
const [name, setName] = useState("");
|
||||
const [nickname, setNickname] = useState("");
|
||||
const [speciesId, setSpeciesId] = useState<string | null>(null);
|
||||
@@ -31,7 +35,14 @@ export function PetCreateForm({ onSuccess }: Props) {
|
||||
|
||||
const createMutation = useMutation(
|
||||
trpc.pets.create.mutationOptions({
|
||||
onSuccess: (pet) => onSuccess({ id: pet.id, name: pet.name }),
|
||||
onSuccess: (pet) => {
|
||||
// Ohne dieses Invalidate bleibt ActivePetContext.pets (trpc.pets.list)
|
||||
// auf dem alten "keine Tiere"-Stand stehen, bis die App neu startet —
|
||||
// OnboardingRedirect wirft dann sofort wieder auf /onboarding/pet
|
||||
// zurück, sobald man nach dem Avatar-Schritt in (app) landet.
|
||||
queryClient.invalidateQueries({ queryKey: trpc.pets.list.queryOptions().queryKey });
|
||||
onSuccess({ id: pet.id, name: pet.name });
|
||||
},
|
||||
onError: (err) => setError(err.message),
|
||||
})
|
||||
);
|
||||
@@ -161,12 +172,15 @@ function BreedPicker({
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { padding: 24, gap: 6 },
|
||||
title: { ...typography.title, fontSize: 18, marginBottom: 4 },
|
||||
subtitle: { ...typography.body, color: colors.quietGray, marginBottom: 16 },
|
||||
label: { ...typography.label, textTransform: "none", letterSpacing: 0, marginTop: 10 },
|
||||
multiline: { height: 80, textAlignVertical: "top", paddingTop: 12 },
|
||||
error: { ...typography.body, color: colors.alertRed, marginTop: 8 },
|
||||
cta: { marginTop: 16 },
|
||||
});
|
||||
function makeStyles(colors: ColorTokens) {
|
||||
const typography = getTypography(colors);
|
||||
return StyleSheet.create({
|
||||
container: { padding: 24, gap: 6 },
|
||||
title: { ...typography.title, fontSize: 18, marginBottom: 4 },
|
||||
subtitle: { ...typography.body, color: colors.quietGray, marginBottom: 16 },
|
||||
label: { ...typography.label, textTransform: "none", letterSpacing: 0, marginTop: 10 },
|
||||
multiline: { height: 80, textAlignVertical: "top", paddingTop: 12 },
|
||||
error: { ...typography.body, color: colors.alertRed, marginTop: 8 },
|
||||
cta: { marginTop: 16 },
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user