feat(mobile): Phase 1 — real Feed/Explore/Notifications/Pets tabs

Moves the mobile app from a connectivity scaffold to a real Phase 1 app:

- Migrate off Expo Go onto a local custom dev client (expo-dev-client,
  built via expo prebuild + expo run:android against the local Android
  SDK — no EAS account needed). Needed because react-native-mmkv requires
  native code Expo Go doesn't ship.
- Persisted, MMKV-backed TanStack Query cache (PersistQueryClientProvider)
  plus expo-image, so a relaunch renders the last-known feed/pets/
  notifications instantly instead of a blank screen while refetching.
- ActivePetContext: every pet-scoped procedure requires an explicit petId
  server-side (no server-side "current pet"), ported from web's
  ActivePetContext, MMKV-backed instead of localStorage.
- Bottom Tabs (Feed/Explore/Notifications/Pets) mirroring the web app's
  actual mobile nav, with Messages as a header button rather than a tab
  (matches web). Feed, PostCard, PawButton reactions, pet discovery grid,
  notifications list, and a conversations list are all wired to the real
  backend and verified against the live database.
- Design tokens/components extended with PostCard/PawButton/PetAvatar/
  PetIdentityBadges, all styled from the existing src/theme/tokens.ts.
- Fixed a react/react-dom version mismatch surfaced along the way, and
  handle Clerk's needs_client_trust (Device Trust) sign-in status with an
  email-code step.

Verified end-to-end in the Android emulator against pawfeed.org: feed
scrolls and paginates with real posts/images, paw reactions toggle
optimistically and persist, pet switching updates every screen, and
notifications/explore show live data.
This commit is contained in:
admin committed 2026-09-05 13:19:01 +02:00
1 parent c4aaa8b3d6
commit c35d4cda46
26 files changed
+1476 -96

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
import { useState } from "react";
import { Pressable, Text, StyleSheet } from "react-native";
import { useMutation } from "@tanstack/react-query";
import { PawPrint } from "lucide-react-native";
import { useTRPC } from "../api/trpc";
import { colors, fontFamily } from "../theme/tokens";
type Props = {
postId: string;
petId: string;
initialCount: number;
};
/**
* Port of web's src/components/feed/PawButton.tsx. `reacted` always starts
* `false` on mount — the web app's feed response doesn't tell the client
* whether the viewer already reacted (postInclude has no reactions relation),
* an acknowledged simplification on web that this mirrors rather than fixes.
* Same optimistic-update shape: flip locally in onMutate, reconcile the exact
* count from the server's authoritative `reacted` in onSuccess, roll back in
* onError.
*/
export function PawButton({ postId, petId, initialCount }: Props) {
const trpc = useTRPC();
const [reacted, setReacted] = useState(false);
const [count, setCount] = useState(initialCount);
const toggleMutation = useMutation(
trpc.reactions.toggle.mutationOptions({
onMutate: () => {
const prevReacted = reacted;
const prevCount = count;
setReacted(!reacted);
return { prevReacted, prevCount };
},
onSuccess: (data, _vars, context) => {
setReacted(data.reacted);
if (context) {
setCount(data.reacted ? context.prevCount + 1 : Math.max(0, context.prevCount - 1));
}
},
onError: (_err, _vars, context) => {
if (context) {
setReacted(context.prevReacted);
setCount(context.prevCount);
}
},
})
);
return (
<Pressable
style={styles.button}
onPress={() => toggleMutation.mutate({ postId, petId })}
hitSlop={8}
>
<PawPrint
size={20}
color={reacted ? colors.marigoldOrange : colors.quietGray}
fill={reacted ? colors.marigoldOrange : "transparent"}
/>
<Text style={styles.count}>{count}</Text>
</Pressable>
);
}
const styles = StyleSheet.create({
button: { flexDirection: "row", alignItems: "center", gap: 6 },
count: { fontFamily: fontFamily.regular, fontSize: 13, color: colors.quietGray },
});
+44
View File
@@ -0,0 +1,44 @@
import { View, Text, StyleSheet } from "react-native";
import { Image } from "expo-image";
import { getAvatarUrl } from "../lib/media-url";
import { colors, fontFamily } from "../theme/tokens";
const SIZE_PRESETS = { sm: 32, md: 40, lg: 56 } as const;
type Props = {
name: string;
avatarKey?: string | null;
size?: keyof typeof SIZE_PRESETS;
};
/**
* Port of web's src/components/ui/pet-avatar.tsx — image if the pet has one,
* otherwise a colored initial fallback.
*/
export function PetAvatar({ name, avatarKey, size = "md" }: Props) {
const px = SIZE_PRESETS[size];
const uri = getAvatarUrl(avatarKey);
const dimensionStyle = { width: px, height: px, borderRadius: px / 2 };
if (uri) {
return <Image source={{ uri }} style={dimensionStyle} contentFit="cover" transition={150} />;
}
return (
<View style={[styles.fallback, dimensionStyle]}>
<Text style={[styles.fallbackText, { fontSize: px * 0.4 }]}>{name.charAt(0).toUpperCase()}</Text>
</View>
);
}
const styles = StyleSheet.create({
fallback: {
backgroundColor: colors.marigoldTint,
alignItems: "center",
justifyContent: "center",
},
fallbackText: {
color: colors.marigoldDeep,
fontFamily: fontFamily.semiBold,
},
});
@@ -0,0 +1,26 @@
import { View, StyleSheet } from "react-native";
import { BadgeCheck, Sparkles } from "lucide-react-native";
import { isActiveSponsor } from "../lib/sponsor";
import { colors } from "../theme/tokens";
type Props = {
isVerified?: boolean;
sponsor?: { sponsorSince: Date | string | null; sponsorPeriodEnd: Date | string | null } | null;
};
/** Port of web's src/components/ui/pet-identity-badges.tsx. */
export function PetIdentityBadges({ isVerified, sponsor }: Props) {
const showSponsor = sponsor ? isActiveSponsor(sponsor) : false;
if (!isVerified && !showSponsor) return null;
return (
<View style={styles.row}>
{isVerified && <BadgeCheck size={14} color={colors.marigoldOrange} />}
{showSponsor && <Sparkles size={14} color={colors.marigoldOrange} />}
</View>
);
}
const styles = StyleSheet.create({
row: { flexDirection: "row", gap: 4, marginLeft: 4 },
});
+117
View File
@@ -0,0 +1,117 @@
import { View, Text, StyleSheet, ScrollView, useWindowDimensions } from "react-native";
import { Image } from "expo-image";
import { MessageCircle, Repeat2, Video } from "lucide-react-native";
import { PetAvatar } from "./PetAvatar";
import { PetIdentityBadges } from "./PetIdentityBadges";
import { PawButton } from "./PawButton";
import { getMediaUrl } from "../lib/media-url";
import { formatPetName, formatRelativeTime } from "../lib/format";
import { colors, typography, radii } from "../theme/tokens";
import type { FeedPost } from "../api/types";
type Props = {
post: FeedPost;
/** The signed-in owner's currently active pet — the one reacting/acting. */
actingPetId: string;
};
/**
* Port of web's src/components/feed/PostCard.tsx, scoped to what Phase 1
* needs: pet header, image (carousel for 2+), caption, and the reaction/
* comment/repost row. Comment and repost are static counts in this pass —
* PostDetailDialog and repost creation are later phases, not built yet.
* Video posts and milestone posts get a minimal placeholder rather than
* full treatment (video playback UI is an explicit fast-follow).
*/
export function PostCard({ post, actingPetId }: Props) {
const { width } = useWindowDimensions();
const cardWidth = width - 32; // matches the 16px screen padding used by the feed list
return (
<View style={styles.card}>
<View style={styles.header}>
<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>
</View>
{post.type === "VIDEO" ? (
<View style={[styles.videoPlaceholder, { width: cardWidth }]}>
<Video size={32} color={colors.pureWhite} />
</View>
) : (
<PostImages images={post.images} width={cardWidth} />
)}
{post.caption ? <Text style={styles.caption}>{post.caption}</Text> : null}
<View style={styles.actions}>
<PawButton postId={post.id} petId={actingPetId} initialCount={post.reactionCount ?? 0} />
<View style={styles.actionGroup}>
<MessageCircle size={18} color={colors.quietGray} />
<Text style={styles.actionCount}>{post.commentCount ?? 0}</Text>
</View>
<View style={styles.actionGroup}>
<Repeat2 size={18} color={colors.quietGray} />
<Text style={styles.actionCount}>{post.repostCount ?? 0}</Text>
</View>
</View>
</View>
);
}
function PostImages({ images, width }: { images: FeedPost["images"]; width: number }) {
if (images.length === 0) return null;
if (images.length === 1) {
return <PostImage image={images[0]} width={width} />;
}
return (
<ScrollView horizontal pagingEnabled showsHorizontalScrollIndicator={false} style={{ width }}>
{images.map((image) => (
<PostImage key={image.id} image={image} width={width} />
))}
</ScrollView>
);
}
function PostImage({ image, width }: { image: FeedPost["images"][number]; width: number }) {
const rawRatio = image.width && image.height ? image.width / image.height : 1;
const aspectRatio = Math.min(1.91, Math.max(0.75, rawRatio));
return (
<Image
source={{ uri: getMediaUrl(image.storageKey) }}
style={{ width, aspectRatio, borderRadius: radii.md }}
contentFit="cover"
placeholder={image.blurhash ? { blurhash: image.blurhash } : undefined}
transition={150}
/>
);
}
const styles = StyleSheet.create({
card: { gap: 10 },
header: { flexDirection: "row", alignItems: "center", gap: 10 },
headerText: { flex: 1 },
nameRow: { flexDirection: "row", alignItems: "center" },
name: { ...typography.body, fontFamily: typography.title.fontFamily },
timestamp: { ...typography.label, textTransform: "none", letterSpacing: 0 },
caption: { ...typography.body },
actions: { flexDirection: "row", alignItems: "center", gap: 20 },
actionGroup: { flexDirection: "row", alignItems: "center", gap: 6 },
actionCount: { ...typography.body, color: colors.quietGray, fontSize: 13 },
videoPlaceholder: {
aspectRatio: 9 / 16,
borderRadius: radii.md,
backgroundColor: colors.ink,
alignItems: "center",
justifyContent: "center",
},
});