From c7c1473e2a5cf965dbe5f8f3c27568f5cb0b4a07 Mon Sep 17 00:00:00 2001 From: neodk2004 Date: Sun, 4 Oct 2026 15:12:07 +0200 Subject: [PATCH] feat: Profil-Ring (PROFILE_RING) ueberall am Tierbild + Story-Ring in Rangfarbe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit found.md: Testnutzer mit "Goldene Pfote" (PROFILE_RING) sah keinen Ring — der Ring war bewusst nur im Profilkopf. Auf Wunsch jetzt ueberall: - petIdentitySelect liefert owner.referralRankId/referralPerks mit (referralOwnerSelect), ebenso search, explore.listPets und pets.list. - Web: RankRing (box-shadow, keine Layoutverschiebung) um Avatare in Feed, Kommentaren, Suche, Explore, Nachrichten, Mitteilungen, Follower-Listen, Meilenstein-/Repost-Karten, Story-Zuschauern/-Kommentaren; PetAvatar nimmt owner. - App: PetAvatar mit owner zeichnet den Ring als Overlay; an allen Listen/Karten uebergeben. - PawRing (Web + App): ungesehene Story-Pfote in Rangfarbe statt Orange, ohne Story schlichter Ring in Rangfarbe; gesehene Storys bleiben grau. Sponsor-Felder im Kartentyp optional (Identity-owner traegt nur den Rang). Co-Authored-By: Claude Opus 5.5 --- mobile/app/(app)/(tabs)/explore.tsx | 2 +- mobile/app/(app)/(tabs)/notifications.tsx | 2 +- mobile/app/(app)/(tabs)/pets.tsx | 2 +- mobile/app/(app)/messages/index.tsx | 2 +- mobile/app/(app)/pets/[petId]/followers.tsx | 2 +- mobile/app/(app)/pets/[petId]/following.tsx | 2 +- mobile/app/(app)/posts/[postId]/comments.tsx | 2 +- mobile/app/(app)/search.tsx | 4 +- mobile/src/components/PawRing.tsx | 23 +++++- mobile/src/components/PetAvatar.tsx | 45 ++++++++++-- mobile/src/components/PetIdentityBadges.tsx | 2 +- mobile/src/components/PostCard.tsx | 11 +-- mobile/src/components/RepostCard.tsx | 2 +- mobile/src/components/StoryTray.tsx | 4 +- .../components/stories/StoryCommentsSheet.tsx | 2 +- .../components/stories/StoryViewersSheet.tsx | 2 +- mobile/src/lib/sponsor.ts | 4 +- src/__tests__/rank-ring.test.tsx | 72 +++++++++++++++++++ src/app/(app)/messages/page.tsx | 15 ++-- src/app/(app)/notifications/page.tsx | 25 ++++--- src/app/(app)/search/page.tsx | 17 +++-- src/components/explore/ExploreCard.tsx | 17 +++-- src/components/feed/MilestoneCard.tsx | 15 ++-- src/components/feed/PostCard.tsx | 8 ++- src/components/feed/PostDetailDialog.tsx | 3 +- src/components/feed/RepostCard.tsx | 19 ++--- src/components/messages/MessageThread.tsx | 50 +++++++------ src/components/referrals/RankRing.tsx | 31 ++++++++ src/components/social/PetListItem.tsx | 21 +++--- src/components/stories/PawRing.tsx | 24 ++++++- .../stories/StoryCommentsOverlay.tsx | 2 +- src/components/stories/StoryTray.tsx | 2 + src/components/stories/StoryViewer.tsx | 25 ++++--- src/components/ui/pet-avatar.tsx | 9 ++- src/components/ui/pet-identity-badges.tsx | 5 +- src/repositories/pet-repository.ts | 21 ++++-- src/trpc/routers/explore.ts | 3 +- src/trpc/routers/pets.ts | 3 +- src/trpc/routers/search.ts | 3 +- 39 files changed, 374 insertions(+), 129 deletions(-) create mode 100644 src/__tests__/rank-ring.test.tsx create mode 100644 src/components/referrals/RankRing.tsx diff --git a/mobile/app/(app)/(tabs)/explore.tsx b/mobile/app/(app)/(tabs)/explore.tsx index a17d255..44dc0ec 100644 --- a/mobile/app/(app)/(tabs)/explore.tsx +++ b/mobile/app/(app)/(tabs)/explore.tsx @@ -164,7 +164,7 @@ function ExplorePetCard({ pet }: { pet: ExplorePet }) { return ( router.push(`/pets/${pet.id}`)}> - + {formatPetName(pet)} diff --git a/mobile/app/(app)/(tabs)/notifications.tsx b/mobile/app/(app)/(tabs)/notifications.tsx index f765089..6fdf482 100644 --- a/mobile/app/(app)/(tabs)/notifications.tsx +++ b/mobile/app/(app)/(tabs)/notifications.tsx @@ -169,7 +169,7 @@ export default function NotificationsScreen() { }} > {item.actorPet ? ( - + ) : ( {SELF_ICONS[item.type] ?? "🏠"} diff --git a/mobile/app/(app)/(tabs)/pets.tsx b/mobile/app/(app)/(tabs)/pets.tsx index 2fe3d90..97d09fd 100644 --- a/mobile/app/(app)/(tabs)/pets.tsx +++ b/mobile/app/(app)/(tabs)/pets.tsx @@ -80,7 +80,7 @@ function PetRow({ return ( - + {formatPetName(pet)} diff --git a/mobile/app/(app)/messages/index.tsx b/mobile/app/(app)/messages/index.tsx index 91dad6a..8046daa 100644 --- a/mobile/app/(app)/messages/index.tsx +++ b/mobile/app/(app)/messages/index.tsx @@ -66,7 +66,7 @@ function ConversationRow({ conversation, onPress }: { conversation: Conversation const styles = useMemo(() => makeStyles(colors), [colors]); return ( - + {formatPetName(conversation.otherPet)} diff --git a/mobile/app/(app)/pets/[petId]/followers.tsx b/mobile/app/(app)/pets/[petId]/followers.tsx index d211841..0c23826 100644 --- a/mobile/app/(app)/pets/[petId]/followers.tsx +++ b/mobile/app/(app)/pets/[petId]/followers.tsx @@ -37,7 +37,7 @@ export default function FollowersScreen() { ItemSeparatorComponent={() => } renderItem={({ item }) => ( router.push(`/pets/${item.follower.id}`)}> - + {formatPetName(item.follower)} )} diff --git a/mobile/app/(app)/pets/[petId]/following.tsx b/mobile/app/(app)/pets/[petId]/following.tsx index 1e1961f..7274fbc 100644 --- a/mobile/app/(app)/pets/[petId]/following.tsx +++ b/mobile/app/(app)/pets/[petId]/following.tsx @@ -37,7 +37,7 @@ export default function FollowingScreen() { ItemSeparatorComponent={() => } renderItem={({ item }) => ( router.push(`/pets/${item.followee.id}`)}> - + {formatPetName(item.followee)} )} diff --git a/mobile/app/(app)/posts/[postId]/comments.tsx b/mobile/app/(app)/posts/[postId]/comments.tsx index 72efe11..cf00658 100644 --- a/mobile/app/(app)/posts/[postId]/comments.tsx +++ b/mobile/app/(app)/posts/[postId]/comments.tsx @@ -154,7 +154,7 @@ function CommentRow({ comment, isOwn, onDelete, onPressPet }: CommentRowProps) { return ( - + diff --git a/mobile/app/(app)/search.tsx b/mobile/app/(app)/search.tsx index 9d48656..0dd17c5 100644 --- a/mobile/app/(app)/search.tsx +++ b/mobile/app/(app)/search.tsx @@ -15,6 +15,7 @@ import { FollowButton } from "../../src/components/FollowButton"; import { getMediaUrl } from "../../src/lib/media-url"; import { radii, getTypography, type ColorTokens } from "../../src/theme/tokens"; import { useBottomSafePadding } from "../../src/hooks/useBottomSafePadding"; +import type { ReferralOwnerFields } from "../../src/hooks/useReferralRanks"; type Tab = "pets" | "people" | "tags"; type Styles = ReturnType; @@ -25,6 +26,7 @@ type SearchPet = { avatarKey: string | null; species: { name: string }; breed: { name: string } | null; + owner?: ReferralOwnerFields | null; }; /** @@ -207,7 +209,7 @@ function PetRow({ return ( - + {pet.name} {pet.breed?.name ?? pet.species.name} diff --git a/mobile/src/components/PawRing.tsx b/mobile/src/components/PawRing.tsx index dbd77c5..e95fdcd 100644 --- a/mobile/src/components/PawRing.tsx +++ b/mobile/src/components/PawRing.tsx @@ -3,6 +3,7 @@ import Svg, { Circle } from "react-native-svg"; import { useQuery } from "@tanstack/react-query"; import { useTRPC } from "../api/trpc"; import { useActivePet } from "../context/ActivePetContext"; +import { useOwnerRankWithPerk, type ReferralOwnerFields } from "../hooks/useReferralRanks"; type Props = { petId: string; @@ -12,6 +13,12 @@ type Props = { onPress?: () => void; /** Nur Story-Leiste: eigene abgelaufene Storys (≤ 7 Tage) als grauer Ring. */ includeOwnRecent?: boolean; + /** + * Owner with the PROFILE_RING perk (found.md): an unseen story's paw takes + * the rank colour instead of orange, and without a story a plain ring in + * the rank colour is drawn. Seen stories stay gray either way. + */ + owner?: ReferralOwnerFields | null; }; const RING_PAD = 8; @@ -37,7 +44,7 @@ export function getPawRingBox(size: number) { * instead of inline SVG markup. Orange = unseen stories, gray = all seen, * no ring = no active story (STORY-02). */ -export function PawRing({ petId, children, size = 32, onPress, includeOwnRecent }: Props) { +export function PawRing({ petId, children, size = 32, onPress, includeOwnRecent, owner }: Props) { const trpc = useTRPC(); const { activePetId } = useActivePet(); @@ -49,7 +56,9 @@ export function PawRing({ petId, children, size = 32, onPress, includeOwnRecent }) ); const { hasStory, allSeen } = data; - const ringColor = allSeen ? SEEN_COLOR : UNSEEN_COLOR; + const rank = useOwnerRankWithPerk(owner, "PROFILE_RING"); + const ringColor = allSeen ? SEEN_COLOR : (rank?.color ?? UNSEEN_COLOR); + const showRankRingOnly = !hasStory && !!rank; const box = getPawRingBox(size); const strokeWidth = Math.max(4, size / 8); @@ -70,6 +79,16 @@ export function PawRing({ petId, children, size = 32, onPress, includeOwnRecent justifyContent: "center", }} > + {showRankRingOnly && ( + + + + )} {hasStory && ( makeStyles(colors), [colors]); + const rank = useOwnerRankWithPerk(owner, "PROFILE_RING"); const px = SIZE_PRESETS[size]; const uri = getAvatarUrl(avatarKey); const dimensionStyle = { width: px, height: px, borderRadius: px / 2 }; - if (uri) { - return ; - } - - return ( + const avatar = uri ? ( + + ) : ( {name.charAt(0).toUpperCase()} ); + + if (!rank) return avatar; + + const offset = RING_GAP + RING_WIDTH[size]; + return ( + + {avatar} + + + ); } function makeStyles(colors: ColorTokens) { diff --git a/mobile/src/components/PetIdentityBadges.tsx b/mobile/src/components/PetIdentityBadges.tsx index 1685814..582aca8 100644 --- a/mobile/src/components/PetIdentityBadges.tsx +++ b/mobile/src/components/PetIdentityBadges.tsx @@ -10,7 +10,7 @@ type Props = { isVerified?: boolean; /** Eines der ersten 250 Tiere (Pet.isFoundingMember). */ isFoundingMember?: boolean; - sponsor?: { sponsorSince: Date | string | null; sponsorPeriodEnd: Date | string | null } | null; + sponsor?: { sponsorSince?: Date | string | null; sponsorPeriodEnd?: Date | string | null } | null; /** Owner-Felder referralRankId/referralPerks — Rang-Abzeichen des Empfehlungsprogramms. */ referral?: ReferralOwnerFields | null; }; diff --git a/mobile/src/components/PostCard.tsx b/mobile/src/components/PostCard.tsx index 047ef6c..85684e9 100644 --- a/mobile/src/components/PostCard.tsx +++ b/mobile/src/components/PostCard.tsx @@ -18,6 +18,7 @@ import { getMediaUrl } from "../lib/media-url"; import { formatPetName, formatRelativeTime } from "../lib/format"; import { useTheme } from "../context/ThemeContext"; import { radii, getTypography, type ColorTokens, type Typography } from "../theme/tokens"; +import type { ReferralOwnerFields } from "../hooks/useReferralRanks"; /** * Structural rather than imported from a single router's inferred output: @@ -39,7 +40,7 @@ type PostCardOriginalPost = { type?: string | null; images: PostCardImage[]; milestone?: unknown; - pet: { id: string; name: string; avatarKey?: string | null }; + pet: { id: string; name: string; avatarKey?: string | null; owner?: ReferralOwnerFields | null }; }; export type PostCardPost = { @@ -60,9 +61,11 @@ export type PostCardPost = { avatarKey?: string | null; isVerified?: boolean; isFoundingMember?: boolean; + // Sponsor fields only come with petCardSelect (feed/explore); a plain pet + // identity's owner (posts.byPetId, comments) carries just the referral rank. owner?: { - sponsorSince: Date | string | null; - sponsorPeriodEnd: Date | string | null; + sponsorSince?: Date | string | null; + sponsorPeriodEnd?: Date | string | null; referralRankId?: string | null; referralPerks?: string[] | null; } | null; @@ -145,7 +148,7 @@ export function PostCard({ post, actingPetId, isTrending, isVisible = true }: Pr router.push(`/pets/${post.pet.id}`)}> - + {formatPetName(post.pet)} diff --git a/mobile/src/components/RepostCard.tsx b/mobile/src/components/RepostCard.tsx index 351e25f..00577c5 100644 --- a/mobile/src/components/RepostCard.tsx +++ b/mobile/src/components/RepostCard.tsx @@ -45,7 +45,7 @@ export function RepostCard({ post }: Props) { router.push(`/pets/${origPet.id}`)}> - + {origPet.name} diff --git a/mobile/src/components/StoryTray.tsx b/mobile/src/components/StoryTray.tsx index 0f89d54..da7435e 100644 --- a/mobile/src/components/StoryTray.tsx +++ b/mobile/src/components/StoryTray.tsx @@ -63,7 +63,7 @@ export function StoryTray() { {ownStory?.hasStory && activePet && ( openViewer(activePet)}> - + @@ -74,7 +74,7 @@ export function StoryTray() { {followedWithStories.map((pet) => ( openViewer(pet)}> - + diff --git a/mobile/src/components/stories/StoryCommentsSheet.tsx b/mobile/src/components/stories/StoryCommentsSheet.tsx index 7f254cf..9867d92 100644 --- a/mobile/src/components/stories/StoryCommentsSheet.tsx +++ b/mobile/src/components/stories/StoryCommentsSheet.tsx @@ -93,7 +93,7 @@ export function StoryCommentsSheet({ storyId, activePetId, visible, onClose, onC renderItem={({ item }) => ( onPressPet(item.pet.id)}> - + diff --git a/mobile/src/components/stories/StoryViewersSheet.tsx b/mobile/src/components/stories/StoryViewersSheet.tsx index 51accde..51d8d42 100644 --- a/mobile/src/components/stories/StoryViewersSheet.tsx +++ b/mobile/src/components/stories/StoryViewersSheet.tsx @@ -53,7 +53,7 @@ export function StoryViewersSheet({ storyId, visible, onClose, onPressPet }: Pro ListEmptyComponent={{t("storyViewer.noViewers")}} renderItem={({ item }) => ( onPressPet(item.viewerPet.id)}> - + {formatPetName(item.viewerPet)} {formatRelativeTime(item.viewedAt)} diff --git a/mobile/src/lib/sponsor.ts b/mobile/src/lib/sponsor.ts index f6767b6..6906ddc 100644 --- a/mobile/src/lib/sponsor.ts +++ b/mobile/src/lib/sponsor.ts @@ -5,8 +5,8 @@ * TS type — always coerce with `new Date(...)` before comparing. */ export function isActiveSponsor(owner: { - sponsorSince: Date | string | null; - sponsorPeriodEnd: Date | string | null; + sponsorSince?: Date | string | null; + sponsorPeriodEnd?: Date | string | null; }): boolean { if (!owner.sponsorSince) return false; if (!owner.sponsorPeriodEnd) return true; diff --git a/src/__tests__/rank-ring.test.tsx b/src/__tests__/rank-ring.test.tsx new file mode 100644 index 0000000..9fbcaa4 --- /dev/null +++ b/src/__tests__/rank-ring.test.tsx @@ -0,0 +1,72 @@ +/** + * found.md: Profil-Ring (Vorteil PROFILE_RING) überall am Tierbild und + * Story-Pfote in der Rangfarbe. + */ +import { describe, it, expect, vi, beforeEach } from "vitest"; +import { renderToStaticMarkup } from "react-dom/server"; + +const GOLD = "#c7951f"; +const { storyState } = vi.hoisted(() => ({ storyState: { hasStory: false, allSeen: false } })); + +vi.mock("@/hooks/useReferralRanks", () => ({ + useReferralRanks: () => ({ + ranks: [], + byId: new Map([["gold", { id: "gold", name: "Goldene Pfote", description: "", icon: "paw-print", color: GOLD }]]), + }), +})); +vi.mock("@/trpc/client", () => ({ + useTRPC: () => ({ stories: { hasActiveStory: { queryOptions: () => ({ queryKey: ["x"] }) } } }), +})); +vi.mock("@/context/ActivePetContext", () => ({ useActivePet: () => ({ activePetId: "me" }) })); +vi.mock("@tanstack/react-query", () => ({ useQuery: () => ({ data: storyState }) })); + +import { RankRing } from "@/components/referrals/RankRing"; +import { PawRing } from "@/components/stories/PawRing"; + +const ranked = { referralRankId: "gold", referralPerks: ["PROFILE_RING", "NAME_BADGE"] }; +const badgeOnly = { referralRankId: "gold", referralPerks: ["NAME_BADGE"] }; + +beforeEach(() => { + storyState.hasStory = false; + storyState.allSeen = false; +}); + +describe("RankRing", () => { + it("draws a ring in the rank colour with the PROFILE_RING perk", () => { + const html = renderToStaticMarkup(); + expect(html).toContain(`0 0 0 4px ${GOLD}`); + }); + + it("renders the avatar unchanged without the perk or without an owner", () => { + expect(renderToStaticMarkup()).toBe(""); + expect(renderToStaticMarkup()).toBe(""); + }); +}); + +describe("PawRing with rank", () => { + it("colours an unseen story paw in the rank colour", () => { + storyState.hasStory = true; + const html = renderToStaticMarkup(); + expect(html).toContain(`fill="${GOLD}"`); + expect(html).not.toContain("#f97316"); + }); + + it("keeps a seen story gray", () => { + storyState.hasStory = true; + storyState.allSeen = true; + const html = renderToStaticMarkup(); + expect(html).toContain("#9ca3af"); + expect(html).not.toContain(GOLD); + }); + + it("draws a plain rank ring without a story", () => { + const html = renderToStaticMarkup(); + expect(html).toContain(`stroke="${GOLD}"`); + }); + + it("stays orange / ringless for owners without the perk", () => { + expect(renderToStaticMarkup()).not.toContain(")).toContain("#f97316"); + }); +}); diff --git a/src/app/(app)/messages/page.tsx b/src/app/(app)/messages/page.tsx index 33e47e8..49c542e 100644 --- a/src/app/(app)/messages/page.tsx +++ b/src/app/(app)/messages/page.tsx @@ -10,6 +10,7 @@ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; import { getAvatarUrl } from "@/lib/avatar-url"; import { formatRelativeCompact } from "@/lib/format-relative-time"; +import { RankRing } from "@/components/referrals/RankRing"; export default function MessagesPage() { const t = useTranslations("Messages"); @@ -63,12 +64,14 @@ export default function MessagesPage() { onClick={() => router.push(`/messages/${conv.id}`)} className="w-full flex items-center gap-3 px-4 py-3 hover:bg-muted/50 transition-colors text-left" > - - {avatarUrl && } - - {conv.otherPet.name[0]?.toUpperCase() ?? "?"} - - + + + {avatarUrl && } + + {conv.otherPet.name[0]?.toUpperCase() ?? "?"} + + +
diff --git a/src/app/(app)/notifications/page.tsx b/src/app/(app)/notifications/page.tsx index 2784c1f..1c7d343 100644 --- a/src/app/(app)/notifications/page.tsx +++ b/src/app/(app)/notifications/page.tsx @@ -15,6 +15,7 @@ import { PostDetailDialog } from "@/components/feed/PostDetailDialog"; import type { PostCardPost } from "@/components/feed/PostCard"; import { useLocale, useTranslations } from "next-intl"; import { formatRelativeCompact } from "@/lib/format-relative-time"; +import { RankRing } from "@/components/referrals/RankRing"; type NotificationType = "FOLLOW" | "REACTION" | "COMMENT" | "MESSAGE" | "BIRTHDAY" | "ADOPTION_DAY" | "MENTION" | "PAW_BACK" | "PET_SUGGESTION" | "REFERRAL_JOINED" | "REFERRAL_RANK_UP" | "VACCINE_DUE"; @@ -189,17 +190,19 @@ export default function NotificationsPage() { {/* Actor avatar + notification type icon */}
- - {actorAvatarUrl && ( - - )} - - {notif.type === "BIRTHDAY" ? "🎂" : - notif.type === "ADOPTION_DAY" ? "🏠" : - notif.type === "VACCINE_DUE" ? "💉" : - notif.actorPet?.name?.[0]?.toUpperCase() ?? "?"} - - + + + {actorAvatarUrl && ( + + )} + + {notif.type === "BIRTHDAY" ? "🎂" : + notif.type === "ADOPTION_DAY" ? "🏠" : + notif.type === "VACCINE_DUE" ? "💉" : + notif.actorPet?.name?.[0]?.toUpperCase() ?? "?"} + + + {notificationIcon(notif.type as NotificationType)} diff --git a/src/app/(app)/search/page.tsx b/src/app/(app)/search/page.tsx index 6dbc321..9c7c90c 100644 --- a/src/app/(app)/search/page.tsx +++ b/src/app/(app)/search/page.tsx @@ -16,6 +16,8 @@ import { FollowButton } from "@/components/social/FollowButton"; import { getAvatarUrl } from "@/lib/avatar-url"; import { getMediaUrl } from "@/lib/media-url"; import { BlurImage } from "@/components/ui/blur-image"; +import { RankRing } from "@/components/referrals/RankRing"; +import type { ReferralOwnerFields } from "@/components/referrals/ReferralRankBadge"; export default function SearchPage() { const t = useTranslations("Search"); @@ -93,6 +95,7 @@ export default function SearchPage() { name: string; avatarKey: string | null; species: { name: string }; + owner?: ReferralOwnerFields | null; breed: { name: string } | null; _count: { followers: number }; }; @@ -106,12 +109,14 @@ export default function SearchPage() { href={`/pets/${p.id}`} className="flex items-center gap-3 flex-1 min-w-0" > - - {avatarUrl && } - - {p.name[0]?.toUpperCase() ?? "?"} - - + + + {avatarUrl && } + + {p.name[0]?.toUpperCase() ?? "?"} + + +

{p.name}

diff --git a/src/components/explore/ExploreCard.tsx b/src/components/explore/ExploreCard.tsx index fcc938e..2211243 100644 --- a/src/components/explore/ExploreCard.tsx +++ b/src/components/explore/ExploreCard.tsx @@ -6,6 +6,8 @@ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; import { FollowButton } from "@/components/social/FollowButton"; import { getAvatarUrl } from "@/lib/avatar-url"; +import { RankRing } from "@/components/referrals/RankRing"; +import type { ReferralOwnerFields } from "@/components/referrals/ReferralRankBadge"; interface ExploreCardPet { id: string; @@ -14,6 +16,7 @@ interface ExploreCardPet { species: { name: string }; breed: { name: string } | null; _count: { followers: number }; + owner?: ReferralOwnerFields | null; } interface ExploreCardProps { @@ -31,12 +34,14 @@ export function ExploreCard({ pet, activePetId }: ExploreCardProps) { return (
- - {avatarUrl && } - - {pet.name[0]?.toUpperCase() ?? "?"} - - + + + {avatarUrl && } + + {pet.name[0]?.toUpperCase() ?? "?"} + + +

{pet.name} diff --git a/src/components/feed/MilestoneCard.tsx b/src/components/feed/MilestoneCard.tsx index 9e3326a..fa93945 100644 --- a/src/components/feed/MilestoneCard.tsx +++ b/src/components/feed/MilestoneCard.tsx @@ -15,6 +15,7 @@ import { PawButton } from "@/components/feed/PawButton"; import { PawBackButton } from "@/components/feed/PawBackButton"; import { PostDetailDialog } from "@/components/feed/PostDetailDialog"; import type { PostCardPost } from "@/components/feed/PostCard"; +import { RankRing } from "@/components/referrals/RankRing"; interface MilestoneCardProps { post: PostCardPost; @@ -52,12 +53,14 @@ export function MilestoneCard({ post, onDeleted }: MilestoneCardProps) {

{/* Header */}
- - {avatarUrl && } - - {pet.name[0]?.toUpperCase() ?? "?"} - - + + + {avatarUrl && } + + {pet.name[0]?.toUpperCase() ?? "?"} + + +

{formatPetName(pet)} diff --git a/src/components/feed/PostCard.tsx b/src/components/feed/PostCard.tsx index d40ad60..e51291b 100644 --- a/src/components/feed/PostCard.tsx +++ b/src/components/feed/PostCard.tsx @@ -82,9 +82,11 @@ type PostPet = { avatarKey: string | null; isVerified?: boolean; isFoundingMember?: boolean; + // Sponsor fields only come with petCardSelect (feed/explore); posts.byPetId + // uses petIdentitySelect, whose owner carries just the referral rank. owner?: { - sponsorSince: Date | string | null; - sponsorPeriodEnd: Date | string | null; + sponsorSince?: Date | string | null; + sponsorPeriodEnd?: Date | string | null; referralRankId?: string | null; referralPerks?: string[] | null; } | null; @@ -247,7 +249,7 @@ function PostCardImpl({ post, onDeleted, variant = "feed" }: PostCardProps) { className="flex items-center gap-3 flex-1 min-w-0 hover:opacity-80 transition-opacity" onClick={(e) => e.stopPropagation()} > - + diff --git a/src/components/feed/PostDetailDialog.tsx b/src/components/feed/PostDetailDialog.tsx index 97f78f6..c22e3df 100644 --- a/src/components/feed/PostDetailDialog.tsx +++ b/src/components/feed/PostDetailDialog.tsx @@ -190,7 +190,7 @@ export function PostDetailDialog({ post, open, onClose, onDeleted }: PostDetailD className="flex items-center gap-3 flex-1 min-w-0 hover:opacity-80 transition-opacity" onClick={onClose} > - +

@@ -438,6 +438,7 @@ export function PostDetailDialog({ post, open, onClose, onDeleted }: PostDetailD name={comment.pet.name} avatarKey={comment.pet.avatarKey} className="h-7 w-7 shrink-0 mt-0.5" + owner={comment.pet.owner} />
diff --git a/src/components/feed/RepostCard.tsx b/src/components/feed/RepostCard.tsx index d1ece77..c2eabd0 100644 --- a/src/components/feed/RepostCard.tsx +++ b/src/components/feed/RepostCard.tsx @@ -19,6 +19,7 @@ import { getMediaUrl } from "@/lib/media-url"; import { BlurImage } from "@/components/ui/blur-image"; import { MilestoneCard } from "@/components/feed/MilestoneCard"; import type { PostCardPost } from "@/components/feed/PostCard"; +import { RankRing } from "@/components/referrals/RankRing"; interface RepostCardProps { post: PostCardPost; @@ -98,14 +99,16 @@ function RepostCardInner({ href={`/pets/${origPet.id}`} className="flex items-center gap-3 px-4 py-3 hover:opacity-80 transition-opacity" > - - {origAvatarUrl && ( - - )} - - {origPet.name[0]?.toUpperCase() ?? "?"} - - + + + {origAvatarUrl && ( + + )} + + {origPet.name[0]?.toUpperCase() ?? "?"} + + +

{origPet.name}

diff --git a/src/components/messages/MessageThread.tsx b/src/components/messages/MessageThread.tsx index 3795619..13f4ad8 100644 --- a/src/components/messages/MessageThread.tsx +++ b/src/components/messages/MessageThread.tsx @@ -14,6 +14,8 @@ import { Textarea } from "@/components/ui/textarea"; import { getAvatarUrl } from "@/lib/avatar-url"; import Link from "next/link"; import { useTranslations } from "next-intl"; +import { RankRing } from "@/components/referrals/RankRing"; +import type { ReferralOwnerFields } from "@/components/referrals/ReferralRankBadge"; function formatTime(date: Date | string) { return new Date(date).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }); @@ -21,7 +23,7 @@ function formatTime(date: Date | string) { interface MessageThreadProps { conversationId: string; - otherPet: { id: string; name: string; avatarKey: string | null }; + otherPet: { id: string; name: string; avatarKey: string | null; owner?: ReferralOwnerFields | null }; } export function MessageThread({ conversationId, otherPet }: MessageThreadProps) { @@ -123,12 +125,14 @@ export function MessageThread({ conversationId, otherPet }: MessageThreadProps)
@@ -143,12 +147,14 @@ export function MessageThread({ conversationId, otherPet }: MessageThreadProps) {!isLoading && messages.length === 0 && (
- - {otherAvatarUrl && } - - {otherPet.name[0]?.toUpperCase() ?? "?"} - - + + + {otherAvatarUrl && } + + {otherPet.name[0]?.toUpperCase() ?? "?"} + + +

{formatPetName(otherPet)}

{t("empty")}

@@ -178,14 +184,16 @@ export function MessageThread({ conversationId, otherPet }: MessageThreadProps) {!isOwn && (
{showAvatar && ( - - {otherAvatarUrl && ( - - )} - - {otherPet.name[0]?.toUpperCase() ?? "?"} - - + + + {otherAvatarUrl && ( + + )} + + {otherPet.name[0]?.toUpperCase() ?? "?"} + + + )}
)} diff --git a/src/components/referrals/RankRing.tsx b/src/components/referrals/RankRing.tsx new file mode 100644 index 0000000..906831d --- /dev/null +++ b/src/components/referrals/RankRing.tsx @@ -0,0 +1,31 @@ +"use client"; + +import type { ReactNode } from "react"; +import { useReferralRingColor, type ReferralOwnerFields } from "@/components/referrals/ReferralRankBadge"; + +/** + * Ring in der Rangfarbe um ein beliebiges Tierbild (Vorteil PROFILE_RING) — + * found.md: überall, wo das Tier erscheint, nicht nur im Profilkopf. Als + * box-shadow (Spalt in Hintergrundfarbe + Ring) statt Rahmen, damit Tiere mit + * und ohne Rang denselben Platz belegen und Listen nicht springen. + */ +export function RankRing({ + owner, + children, + className, +}: { + owner: ReferralOwnerFields | null | undefined; + children: ReactNode; + className?: string; +}) { + const color = useReferralRingColor(owner); + if (!color) return <>{children}; + return ( + + {children} + + ); +} diff --git a/src/components/social/PetListItem.tsx b/src/components/social/PetListItem.tsx index a95bbee..7f06598 100644 --- a/src/components/social/PetListItem.tsx +++ b/src/components/social/PetListItem.tsx @@ -4,6 +4,8 @@ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; import { getAvatarUrl } from "@/lib/avatar-url"; import { FollowButton } from "@/components/social/FollowButton"; +import { RankRing } from "@/components/referrals/RankRing"; +import type { ReferralOwnerFields } from "@/components/referrals/ReferralRankBadge"; /** * PetListItem — a single row in the followers/following list (SOCL-03) @@ -22,6 +24,7 @@ interface PetListItemProps { name: string; avatarKey: string | null; species: { name: string }; + owner?: ReferralOwnerFields | null; }; /** The active pet performing the follow action (from ActivePetContext) */ followerPetId: string; @@ -30,14 +33,16 @@ interface PetListItemProps { export function PetListItem({ pet, followerPetId }: PetListItemProps) { return (
- - {pet.avatarKey && ( - - )} - - {pet.name.slice(0, 2).toUpperCase()} - - + + + {pet.avatarKey && ( + + )} + + {pet.name.slice(0, 2).toUpperCase()} + + +

{pet.name}

diff --git a/src/components/stories/PawRing.tsx b/src/components/stories/PawRing.tsx index 313671c..43a10ee 100644 --- a/src/components/stories/PawRing.tsx +++ b/src/components/stories/PawRing.tsx @@ -3,6 +3,7 @@ import { useQuery } from "@tanstack/react-query"; import { useTRPC } from "@/trpc/client"; import { useActivePet } from "@/context/ActivePetContext"; +import { useReferralRingColor, type ReferralOwnerFields } from "@/components/referrals/ReferralRankBadge"; interface PawRingProps { petId: string; @@ -14,6 +15,12 @@ interface PawRingProps { onPress?: () => void; /** Nur Story-Leiste: eigene abgelaufene Storys (≤ 7 Tage) als grauer Ring. */ includeOwnRecent?: boolean; + /** + * Owner mit Vorteil PROFILE_RING (found.md): ungesehene Story-Pfote in der + * Rangfarbe statt Orange, ohne Story ein schlichter Ring in Rangfarbe. + * Gesehene Storys bleiben grau. + */ + owner?: ReferralOwnerFields | null; } const RING_PAD = 8; @@ -24,7 +31,7 @@ const RING_PAD = 8; * Orange = unseen stories; gray = all stories already seen; no ring = no stories (STORY-02). * viewerPetId is read from ActivePetContext so callers don't need to pass it explicitly. */ -export function PawRing({ petId, children, size = 32, onPress, includeOwnRecent }: PawRingProps) { +export function PawRing({ petId, children, size = 32, onPress, includeOwnRecent, owner }: PawRingProps) { const trpc = useTRPC(); const { activePetId } = useActivePet(); @@ -37,7 +44,9 @@ export function PawRing({ petId, children, size = 32, onPress, includeOwnRecent ); const { hasStory, allSeen } = data; - const ringColor = allSeen ? "#9ca3af" : "#f97316"; // gray-400 if seen, orange-500 if unseen + const rankColor = useReferralRingColor(owner); + // gray-400 if seen, rank colour (PROFILE_RING) or orange-500 if unseen + const ringColor = allSeen ? "#9ca3af" : (rankColor ?? "#f97316"); const S = size + RING_PAD * 2; @@ -62,6 +71,17 @@ export function PawRing({ petId, children, size = 32, onPress, includeOwnRecent {...(hasStory && onPress ? { onClick: onPress } : {})} {...(hasStory && onPress ? { "aria-label": "View story" } : {})} > + {!hasStory && rankColor && ( + + )} {hasStory && ( (
- +
{c.pet.name} {c.body} diff --git a/src/components/stories/StoryTray.tsx b/src/components/stories/StoryTray.tsx index d588ad9..d7d3b25 100644 --- a/src/components/stories/StoryTray.tsx +++ b/src/components/stories/StoryTray.tsx @@ -101,6 +101,7 @@ export function StoryTray() { setViewingPet({ id: activePet.id, name: activePet.name, avatarKey: activePet.avatarKey ?? null }) @@ -132,6 +133,7 @@ export function StoryTray() { setViewingPet(pet)} > {viewers.map((v) => (
  • - - {v.viewerPet.avatarKey && ( - - )} - - {v.viewerPet.name[0]?.toUpperCase() ?? "?"} - - + + + {v.viewerPet.avatarKey && ( + + )} + + {v.viewerPet.name[0]?.toUpperCase() ?? "?"} + + + {v.viewerPet.name}
  • ))} diff --git a/src/components/ui/pet-avatar.tsx b/src/components/ui/pet-avatar.tsx index 2640829..2bb7a43 100644 --- a/src/components/ui/pet-avatar.tsx +++ b/src/components/ui/pet-avatar.tsx @@ -1,16 +1,20 @@ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { getAvatarUrl } from "@/lib/avatar-url"; import { getInitialsColor } from "@/lib/avatar-color"; +import { RankRing } from "@/components/referrals/RankRing"; +import type { ReferralOwnerFields } from "@/components/referrals/ReferralRankBadge"; interface PetAvatarProps { name: string; avatarKey?: string | null; size?: "default" | "sm" | "lg"; className?: string; + /** Owner (petIdentitySelect) — mit Vorteil PROFILE_RING Ring in Rangfarbe. Nicht übergeben, wenn ein PawRing das Bild umschließt. */ + owner?: ReferralOwnerFields | null; } -export function PetAvatar({ name, avatarKey, size = "default", className }: PetAvatarProps) { - return ( +export function PetAvatar({ name, avatarKey, size = "default", className, owner }: PetAvatarProps) { + const avatar = ( {avatarKey && } ); + return owner ? {avatar} : avatar; } diff --git a/src/components/ui/pet-identity-badges.tsx b/src/components/ui/pet-identity-badges.tsx index 76f6880..60ddd12 100644 --- a/src/components/ui/pet-identity-badges.tsx +++ b/src/components/ui/pet-identity-badges.tsx @@ -5,8 +5,9 @@ import { ReferralRankBadge, type ReferralOwnerFields } from "@/components/referr import { FoundingMemberBadge } from "@/components/ui/founding-member-badge"; type SponsorWindow = { - sponsorSince: Date | string | null; - sponsorPeriodEnd: Date | string | null; + // Optional: a pet identity's owner (petIdentitySelect) carries only the referral rank. + sponsorSince?: Date | string | null; + sponsorPeriodEnd?: Date | string | null; }; type Props = { diff --git a/src/repositories/pet-repository.ts b/src/repositories/pet-repository.ts index ba80a37..77782fe 100644 --- a/src/repositories/pet-repository.ts +++ b/src/repositories/pet-repository.ts @@ -1,15 +1,28 @@ import type { Prisma } from "@prisma/client"; /** - * Minimal pet identity — id/name/nickname/avatarKey. This is the shape every - * "who posted/commented/follows this" display needs; compose on top of it - * (spread + extra fields) rather than hand-writing the fragment again. + * The owner's cached referral rank + perks — resolved client-side against + * referrals.ranks. Part of every pet identity so the PROFILE_RING perk can + * draw its ring around *any* avatar (found.md: feed, comments, lists, story + * ring), not just the profile header. + */ +export const referralOwnerSelect = { + referralRankId: true, + referralPerks: true, +} satisfies Prisma.OwnerSelect; + +/** + * Minimal pet identity — id/name/nickname/avatarKey plus the owner's rank + * fields for the avatar ring. This is the shape every "who posted/commented/ + * follows this" display needs; compose on top of it (spread + extra fields) + * rather than hand-writing the fragment again. */ export const petIdentitySelect = { id: true, name: true, nickname: true, avatarKey: true, + owner: { select: referralOwnerSelect }, } satisfies Prisma.PetSelect; /** @@ -22,7 +35,7 @@ export const petCardSelect = { ...petIdentitySelect, isVerified: true, isFoundingMember: true, - owner: { select: { sponsorSince: true, sponsorPeriodEnd: true, referralRankId: true, referralPerks: true } }, + owner: { select: { sponsorSince: true, sponsorPeriodEnd: true, ...referralOwnerSelect } }, } satisfies Prisma.PetSelect; export type PetIdentity = Prisma.PetGetPayload<{ select: typeof petIdentitySelect }>; diff --git a/src/trpc/routers/explore.ts b/src/trpc/routers/explore.ts index c66caa0..d8cdaa8 100644 --- a/src/trpc/routers/explore.ts +++ b/src/trpc/routers/explore.ts @@ -3,7 +3,7 @@ import { z } from "zod"; import { router, publicProcedure, rateLimited } from "@/trpc/init"; import { pickLocalizedName } from "@/lib/localized-name"; import { getSpiderExclusionId } from "@/lib/spider-exclusion"; -import { petCardSelect } from "@/repositories/pet-repository"; +import { petCardSelect, referralOwnerSelect } from "@/repositories/pet-repository"; const TRENDING_POSTS_WINDOW_MS = 48 * 60 * 60 * 1000; // 48 h const TRENDING_HASHTAGS_WINDOW_MS = 7 * 24 * 60 * 60 * 1000; // 7 days @@ -34,6 +34,7 @@ export const exploreRouter = router({ species: { include: { translations: { where: { locale: ctx.locale } } } }, breed: { include: { translations: { where: { locale: ctx.locale } } } }, _count: { select: { followers: true } }, + owner: { select: referralOwnerSelect }, }, }); diff --git a/src/trpc/routers/pets.ts b/src/trpc/routers/pets.ts index ed4d991..e209528 100644 --- a/src/trpc/routers/pets.ts +++ b/src/trpc/routers/pets.ts @@ -3,7 +3,7 @@ import { TRPCError } from "@trpc/server"; import { router, protectedProcedure } from "@/trpc/init"; import { assertPetOwnership } from "@/lib/assert-pet-ownership"; import { pickLocalizedName } from "@/lib/localized-name"; -import { petCardSelect } from "@/repositories/pet-repository"; +import { petCardSelect, referralOwnerSelect } from "@/repositories/pet-repository"; import { welcomeNewPet } from "@/lib/new-pet-welcome"; import { deletePetCompletely } from "@/lib/delete-pet"; @@ -65,6 +65,7 @@ export const petsRouter = router({ include: { species: { include: { translations: { where: { locale: ctx.locale } } } }, breed: { include: { translations: { where: { locale: ctx.locale } } } }, + owner: { select: referralOwnerSelect }, }, orderBy: { createdAt: "asc" }, }); diff --git a/src/trpc/routers/search.ts b/src/trpc/routers/search.ts index eb4a36d..b979a5a 100644 --- a/src/trpc/routers/search.ts +++ b/src/trpc/routers/search.ts @@ -4,7 +4,7 @@ import { router, protectedProcedure } from "@/trpc/init"; import { clerkClient } from "@clerk/nextjs/server"; import { pickLocalizedName } from "@/lib/localized-name"; import { getSpiderExclusionId } from "@/lib/spider-exclusion"; -import { petIdentitySelect } from "@/repositories/pet-repository"; +import { petIdentitySelect, referralOwnerSelect } from "@/repositories/pet-repository"; export const searchRouter = router({ pets: protectedProcedure @@ -33,6 +33,7 @@ export const searchRouter = router({ species: { include: { translations: { where: { locale: ctx.locale } } } }, breed: { include: { translations: { where: { locale: ctx.locale } } } }, _count: { select: { followers: true } }, + owner: { select: referralOwnerSelect }, }, });