feat: Profil-Ring (PROFILE_RING) ueberall am Tierbild + Story-Ring in Rangfarbe
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
0668459c1e
commit
c7c1473e2a
39 files changed
+374
-129
No files matched your search
@@ -164,7 +164,7 @@ function ExplorePetCard({ pet }: { pet: ExplorePet }) {
|
||||
return (
|
||||
<Pressable style={styles.cardPress} onPress={() => router.push(`/pets/${pet.id}`)}>
|
||||
<Card style={styles.card}>
|
||||
<PetAvatar name={pet.name} avatarKey={pet.avatarKey} size="lg" />
|
||||
<PetAvatar name={pet.name} avatarKey={pet.avatarKey} size="lg" owner={pet.owner} />
|
||||
<Text style={styles.name} numberOfLines={1}>
|
||||
{formatPetName(pet)}
|
||||
</Text>
|
||||
|
||||
@@ -169,7 +169,7 @@ export default function NotificationsScreen() {
|
||||
}}
|
||||
>
|
||||
{item.actorPet ? (
|
||||
<PetAvatar name={item.actorPet.name} avatarKey={item.actorPet.avatarKey} />
|
||||
<PetAvatar name={item.actorPet.name} avatarKey={item.actorPet.avatarKey} owner={item.actorPet.owner} />
|
||||
) : (
|
||||
<View style={styles.selfIcon}>
|
||||
<Text style={styles.selfIconText}>{SELF_ICONS[item.type] ?? "🏠"}</Text>
|
||||
|
||||
@@ -80,7 +80,7 @@ function PetRow({
|
||||
return (
|
||||
<Pressable onPress={onPress}>
|
||||
<Card style={styles.row}>
|
||||
<PetAvatar name={pet.name} avatarKey={pet.avatarKey} size="lg" />
|
||||
<PetAvatar name={pet.name} avatarKey={pet.avatarKey} size="lg" owner={pet.owner} />
|
||||
<View style={styles.rowText}>
|
||||
<View style={styles.nameRow}>
|
||||
<Text style={styles.name}>{formatPetName(pet)}</Text>
|
||||
|
||||
@@ -66,7 +66,7 @@ function ConversationRow({ conversation, onPress }: { conversation: Conversation
|
||||
const styles = useMemo(() => makeStyles(colors), [colors]);
|
||||
return (
|
||||
<Pressable style={styles.row} onPress={onPress}>
|
||||
<PetAvatar name={conversation.otherPet.name} avatarKey={conversation.otherPet.avatarKey} />
|
||||
<PetAvatar name={conversation.otherPet.name} avatarKey={conversation.otherPet.avatarKey} owner={conversation.otherPet.owner} />
|
||||
<View style={styles.rowText}>
|
||||
<View style={styles.nameRow}>
|
||||
<Text style={styles.name}>{formatPetName(conversation.otherPet)}</Text>
|
||||
|
||||
@@ -37,7 +37,7 @@ export default function FollowersScreen() {
|
||||
ItemSeparatorComponent={() => <View style={styles.separator} />}
|
||||
renderItem={({ item }) => (
|
||||
<Pressable style={styles.row} onPress={() => router.push(`/pets/${item.follower.id}`)}>
|
||||
<PetAvatar name={item.follower.name} avatarKey={item.follower.avatarKey} />
|
||||
<PetAvatar name={item.follower.name} avatarKey={item.follower.avatarKey} owner={item.follower.owner} />
|
||||
<Text style={typography.body}>{formatPetName(item.follower)}</Text>
|
||||
</Pressable>
|
||||
)}
|
||||
|
||||
@@ -37,7 +37,7 @@ export default function FollowingScreen() {
|
||||
ItemSeparatorComponent={() => <View style={styles.separator} />}
|
||||
renderItem={({ item }) => (
|
||||
<Pressable style={styles.row} onPress={() => router.push(`/pets/${item.followee.id}`)}>
|
||||
<PetAvatar name={item.followee.name} avatarKey={item.followee.avatarKey} />
|
||||
<PetAvatar name={item.followee.name} avatarKey={item.followee.avatarKey} owner={item.followee.owner} />
|
||||
<Text style={typography.body}>{formatPetName(item.followee)}</Text>
|
||||
</Pressable>
|
||||
)}
|
||||
|
||||
@@ -154,7 +154,7 @@ function CommentRow({ comment, isOwn, onDelete, onPressPet }: CommentRowProps) {
|
||||
return (
|
||||
<View style={styles.row}>
|
||||
<Pressable onPress={onPressPet}>
|
||||
<PetAvatar name={comment.pet.name} avatarKey={comment.pet.avatarKey} size="sm" />
|
||||
<PetAvatar name={comment.pet.name} avatarKey={comment.pet.avatarKey} size="sm" owner={comment.pet.owner} />
|
||||
</Pressable>
|
||||
<View style={styles.rowBody}>
|
||||
<View style={styles.rowHeader}>
|
||||
|
||||
@@ -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<typeof makeStyles>;
|
||||
@@ -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 (
|
||||
<View style={[styles.petRow, indented && styles.petRowIndented]}>
|
||||
<Pressable style={styles.petRowMain} onPress={onPress}>
|
||||
<PetAvatar name={pet.name} avatarKey={pet.avatarKey} size="sm" />
|
||||
<PetAvatar name={pet.name} avatarKey={pet.avatarKey} size="sm" owner={pet.owner} />
|
||||
<View style={styles.petRowText}>
|
||||
<Text style={styles.petName}>{pet.name}</Text>
|
||||
<Text style={styles.petSpecies}>{pet.breed?.name ?? pet.species.name}</Text>
|
||||
|
||||
@@ -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 && (
|
||||
<Svg
|
||||
width={box.width}
|
||||
height={box.height}
|
||||
viewBox={`0 ${-BEAN_OVERHANG} 100 ${100 + BEAN_OVERHANG}`}
|
||||
style={{ position: "absolute", top: 0, left: 0 }}
|
||||
>
|
||||
<Circle cx={50} cy={50} r={44} fill="none" stroke={rank.color} strokeWidth={strokeWidth * 0.6} />
|
||||
</Svg>
|
||||
)}
|
||||
{hasStory && (
|
||||
<Svg
|
||||
width={box.width}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Image } from "expo-image";
|
||||
import { getAvatarUrl } from "../lib/media-url";
|
||||
import { useTheme } from "../context/ThemeContext";
|
||||
import { fontFamily, type ColorTokens } from "../theme/tokens";
|
||||
import { useOwnerRankWithPerk, type ReferralOwnerFields } from "../hooks/useReferralRanks";
|
||||
|
||||
const SIZE_PRESETS = { sm: 32, md: 40, lg: 56 } as const;
|
||||
|
||||
@@ -11,28 +12,60 @@ type Props = {
|
||||
name: string;
|
||||
avatarKey?: string | null;
|
||||
size?: keyof typeof SIZE_PRESETS;
|
||||
/**
|
||||
* The pet's owner (referralRankId/referralPerks, part of petIdentitySelect).
|
||||
* With the PROFILE_RING perk the avatar gets a ring in the rank colour.
|
||||
* Don't pass it when a PawRing wraps this avatar — PawRing draws that ring.
|
||||
*/
|
||||
owner?: ReferralOwnerFields | null;
|
||||
};
|
||||
|
||||
// Ring sits *outside* the avatar (absolute overlay) so ranked and unranked
|
||||
// avatars keep the same footprint and list rows don't shift.
|
||||
const RING_WIDTH = { sm: 2, md: 2, lg: 3 } as const;
|
||||
const RING_GAP = 2;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
export function PetAvatar({ name, avatarKey, size = "md", owner }: Props) {
|
||||
const { colors } = useTheme();
|
||||
const styles = useMemo(() => 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 <Image source={{ uri }} style={dimensionStyle} contentFit="cover" transition={150} />;
|
||||
}
|
||||
|
||||
return (
|
||||
const avatar = uri ? (
|
||||
<Image source={{ uri }} style={dimensionStyle} contentFit="cover" transition={150} />
|
||||
) : (
|
||||
<View style={[styles.fallback, dimensionStyle]}>
|
||||
<Text style={[styles.fallbackText, { fontSize: px * 0.4 }]}>{name.charAt(0).toUpperCase()}</Text>
|
||||
</View>
|
||||
);
|
||||
|
||||
if (!rank) return avatar;
|
||||
|
||||
const offset = RING_GAP + RING_WIDTH[size];
|
||||
return (
|
||||
<View style={{ width: px, height: px }}>
|
||||
{avatar}
|
||||
<View
|
||||
pointerEvents="none"
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: -offset,
|
||||
left: -offset,
|
||||
width: px + offset * 2,
|
||||
height: px + offset * 2,
|
||||
borderRadius: (px + offset * 2) / 2,
|
||||
borderWidth: RING_WIDTH[size],
|
||||
borderColor: rank.color,
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function makeStyles(colors: ColorTokens) {
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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
|
||||
<View style={styles.card}>
|
||||
<View style={styles.headerRow}>
|
||||
<Pressable style={styles.header} onPress={() => router.push(`/pets/${post.pet.id}`)}>
|
||||
<PetAvatar name={post.pet.name} avatarKey={post.pet.avatarKey} />
|
||||
<PetAvatar name={post.pet.name} avatarKey={post.pet.avatarKey} owner={post.pet.owner} />
|
||||
<View style={styles.headerText}>
|
||||
<View style={styles.nameRow}>
|
||||
<Text style={styles.name}>{formatPetName(post.pet)}</Text>
|
||||
|
||||
@@ -45,7 +45,7 @@ export function RepostCard({ post }: Props) {
|
||||
</Pressable>
|
||||
|
||||
<Pressable style={styles.header} onPress={() => router.push(`/pets/${origPet.id}`)}>
|
||||
<PetAvatar name={origPet.name} avatarKey={origPet.avatarKey} size="sm" />
|
||||
<PetAvatar name={origPet.name} avatarKey={origPet.avatarKey} size="sm" owner={origPet.owner} />
|
||||
<Text style={styles.name}>{origPet.name}</Text>
|
||||
</Pressable>
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ export function StoryTray() {
|
||||
|
||||
{ownStory?.hasStory && activePet && (
|
||||
<Pressable style={styles.item} onPress={() => openViewer(activePet)}>
|
||||
<PawRing petId={activePet.id} size={AVATAR_SIZE} includeOwnRecent>
|
||||
<PawRing petId={activePet.id} size={AVATAR_SIZE} includeOwnRecent owner={activePet.owner}>
|
||||
<PetAvatar name={activePet.name} avatarKey={activePet.avatarKey} size="lg" />
|
||||
</PawRing>
|
||||
<Text style={styles.label} numberOfLines={1}>
|
||||
@@ -74,7 +74,7 @@ export function StoryTray() {
|
||||
|
||||
{followedWithStories.map((pet) => (
|
||||
<Pressable key={pet.id} style={styles.item} onPress={() => openViewer(pet)}>
|
||||
<PawRing petId={pet.id} size={AVATAR_SIZE}>
|
||||
<PawRing petId={pet.id} size={AVATAR_SIZE} owner={pet.owner}>
|
||||
<PetAvatar name={pet.name} avatarKey={pet.avatarKey} size="lg" />
|
||||
</PawRing>
|
||||
<Text style={styles.label} numberOfLines={1}>
|
||||
|
||||
@@ -93,7 +93,7 @@ export function StoryCommentsSheet({ storyId, activePetId, visible, onClose, onC
|
||||
renderItem={({ item }) => (
|
||||
<View style={styles.row}>
|
||||
<Pressable onPress={() => onPressPet(item.pet.id)}>
|
||||
<PetAvatar name={item.pet.name} avatarKey={item.pet.avatarKey} size="sm" />
|
||||
<PetAvatar name={item.pet.name} avatarKey={item.pet.avatarKey} size="sm" owner={item.pet.owner} />
|
||||
</Pressable>
|
||||
<View style={styles.rowBody}>
|
||||
<View style={styles.rowHeader}>
|
||||
|
||||
@@ -53,7 +53,7 @@ export function StoryViewersSheet({ storyId, visible, onClose, onPressPet }: Pro
|
||||
ListEmptyComponent={<Text style={styles.muted}>{t("storyViewer.noViewers")}</Text>}
|
||||
renderItem={({ item }) => (
|
||||
<Pressable style={styles.row} onPress={() => onPressPet(item.viewerPet.id)}>
|
||||
<PetAvatar name={item.viewerPet.name} avatarKey={item.viewerPet.avatarKey} size="sm" />
|
||||
<PetAvatar name={item.viewerPet.name} avatarKey={item.viewerPet.avatarKey} size="sm" owner={item.viewerPet.owner} />
|
||||
<Text style={styles.name} numberOfLines={1}>{formatPetName(item.viewerPet)}</Text>
|
||||
<Text style={styles.time}>{formatRelativeTime(item.viewedAt)}</Text>
|
||||
</Pressable>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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(<RankRing owner={ranked}><b /></RankRing>);
|
||||
expect(html).toContain(`0 0 0 4px ${GOLD}`);
|
||||
});
|
||||
|
||||
it("renders the avatar unchanged without the perk or without an owner", () => {
|
||||
expect(renderToStaticMarkup(<RankRing owner={badgeOnly}><b /></RankRing>)).toBe("<b></b>");
|
||||
expect(renderToStaticMarkup(<RankRing owner={null}><b /></RankRing>)).toBe("<b></b>");
|
||||
});
|
||||
});
|
||||
|
||||
describe("PawRing with rank", () => {
|
||||
it("colours an unseen story paw in the rank colour", () => {
|
||||
storyState.hasStory = true;
|
||||
const html = renderToStaticMarkup(<PawRing petId="p1" owner={ranked}><b /></PawRing>);
|
||||
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(<PawRing petId="p1" owner={ranked}><b /></PawRing>);
|
||||
expect(html).toContain("#9ca3af");
|
||||
expect(html).not.toContain(GOLD);
|
||||
});
|
||||
|
||||
it("draws a plain rank ring without a story", () => {
|
||||
const html = renderToStaticMarkup(<PawRing petId="p1" owner={ranked}><b /></PawRing>);
|
||||
expect(html).toContain(`stroke="${GOLD}"`);
|
||||
});
|
||||
|
||||
it("stays orange / ringless for owners without the perk", () => {
|
||||
expect(renderToStaticMarkup(<PawRing petId="p1" owner={badgeOnly}><b /></PawRing>)).not.toContain("<svg");
|
||||
storyState.hasStory = true;
|
||||
expect(renderToStaticMarkup(<PawRing petId="p1" owner={badgeOnly}><b /></PawRing>)).toContain("#f97316");
|
||||
});
|
||||
});
|
||||
@@ -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"
|
||||
>
|
||||
<Avatar className="w-12 h-12 shrink-0">
|
||||
{avatarUrl && <AvatarImage src={avatarUrl} alt={conv.otherPet.name} />}
|
||||
<AvatarFallback className="text-sm bg-muted">
|
||||
{conv.otherPet.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<RankRing owner={conv.otherPet.owner}>
|
||||
<Avatar className="w-12 h-12 shrink-0">
|
||||
{avatarUrl && <AvatarImage src={avatarUrl} alt={conv.otherPet.name} />}
|
||||
<AvatarFallback className="text-sm bg-muted">
|
||||
{conv.otherPet.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
</RankRing>
|
||||
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-baseline justify-between gap-2">
|
||||
|
||||
@@ -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 */}
|
||||
<div className="relative shrink-0">
|
||||
<Avatar className="w-10 h-10">
|
||||
{actorAvatarUrl && (
|
||||
<AvatarImage src={actorAvatarUrl} alt={notif.actorPet?.name ?? ""} />
|
||||
)}
|
||||
<AvatarFallback className="text-xs bg-muted">
|
||||
{notif.type === "BIRTHDAY" ? "🎂" :
|
||||
notif.type === "ADOPTION_DAY" ? "🏠" :
|
||||
notif.type === "VACCINE_DUE" ? "💉" :
|
||||
notif.actorPet?.name?.[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<RankRing owner={notif.actorPet?.owner}>
|
||||
<Avatar className="w-10 h-10">
|
||||
{actorAvatarUrl && (
|
||||
<AvatarImage src={actorAvatarUrl} alt={notif.actorPet?.name ?? ""} />
|
||||
)}
|
||||
<AvatarFallback className="text-xs bg-muted">
|
||||
{notif.type === "BIRTHDAY" ? "🎂" :
|
||||
notif.type === "ADOPTION_DAY" ? "🏠" :
|
||||
notif.type === "VACCINE_DUE" ? "💉" :
|
||||
notif.actorPet?.name?.[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
</RankRing>
|
||||
<span className="absolute -bottom-0.5 -right-0.5 w-5 h-5 rounded-full bg-card border flex items-center justify-center">
|
||||
{notificationIcon(notif.type as NotificationType)}
|
||||
</span>
|
||||
|
||||
@@ -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"
|
||||
>
|
||||
<Avatar className="w-10 h-10 shrink-0">
|
||||
{avatarUrl && <AvatarImage src={avatarUrl} alt={p.name} />}
|
||||
<AvatarFallback className="text-sm bg-muted">
|
||||
{p.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<RankRing owner={p.owner}>
|
||||
<Avatar className="w-10 h-10 shrink-0">
|
||||
{avatarUrl && <AvatarImage src={avatarUrl} alt={p.name} />}
|
||||
<AvatarFallback className="text-sm bg-muted">
|
||||
{p.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
</RankRing>
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm font-medium truncate">{p.name}</p>
|
||||
<Badge variant="secondary" className="text-xs mt-0.5">
|
||||
|
||||
@@ -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 (
|
||||
<div className="flex flex-col items-center gap-2 p-3 rounded-xl border bg-card hover:bg-muted/50 transition-colors">
|
||||
<Link href={`/pets/${pet.id}`} className="flex flex-col items-center gap-2 w-full">
|
||||
<Avatar className="w-14 h-14">
|
||||
{avatarUrl && <AvatarImage src={avatarUrl} alt={pet.name} />}
|
||||
<AvatarFallback className="text-sm bg-muted">
|
||||
{pet.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<RankRing owner={pet.owner}>
|
||||
<Avatar className="w-14 h-14">
|
||||
{avatarUrl && <AvatarImage src={avatarUrl} alt={pet.name} />}
|
||||
<AvatarFallback className="text-sm bg-muted">
|
||||
{pet.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
</RankRing>
|
||||
|
||||
<p className="text-sm font-medium text-center truncate max-w-full">
|
||||
{pet.name}
|
||||
|
||||
@@ -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) {
|
||||
<article className="bg-orange-500/5 border border-orange-500/20 rounded-lg overflow-hidden">
|
||||
{/* Header */}
|
||||
<div className="flex items-center gap-3 px-4 py-3">
|
||||
<Avatar className="w-8 h-8 shrink-0">
|
||||
{avatarUrl && <AvatarImage src={avatarUrl} alt={pet.name} />}
|
||||
<AvatarFallback className="text-xs bg-orange-100 text-orange-600">
|
||||
{pet.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<RankRing owner={pet.owner}>
|
||||
<Avatar className="w-8 h-8 shrink-0">
|
||||
{avatarUrl && <AvatarImage src={avatarUrl} alt={pet.name} />}
|
||||
<AvatarFallback className="text-xs bg-orange-100 text-orange-600">
|
||||
{pet.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
</RankRing>
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-base font-semibold text-foreground leading-tight truncate">
|
||||
{formatPetName(pet)}
|
||||
|
||||
@@ -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()}
|
||||
>
|
||||
<PawRing petId={pet.id} size={32}>
|
||||
<PawRing petId={pet.id} size={32} owner={pet.owner}>
|
||||
<PetAvatar name={pet.name} avatarKey={pet.avatarKey} className="w-8 h-8" />
|
||||
</PawRing>
|
||||
|
||||
|
||||
@@ -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}
|
||||
>
|
||||
<PawRing petId={pet.id} size={32}>
|
||||
<PawRing petId={pet.id} size={32} owner={pet.owner}>
|
||||
<PetAvatar name={pet.name} avatarKey={pet.avatarKey} className="w-8 h-8" />
|
||||
</PawRing>
|
||||
<div className="flex-1 min-w-0">
|
||||
@@ -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}
|
||||
/>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-baseline gap-1.5">
|
||||
|
||||
@@ -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"
|
||||
>
|
||||
<Avatar className="w-8 h-8">
|
||||
{origAvatarUrl && (
|
||||
<AvatarImage src={origAvatarUrl} alt={origPet.name} />
|
||||
)}
|
||||
<AvatarFallback className="text-xs bg-muted">
|
||||
{origPet.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<RankRing owner={origPet.owner}>
|
||||
<Avatar className="w-8 h-8">
|
||||
{origAvatarUrl && (
|
||||
<AvatarImage src={origAvatarUrl} alt={origPet.name} />
|
||||
)}
|
||||
<AvatarFallback className="text-xs bg-muted">
|
||||
{origPet.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
</RankRing>
|
||||
<p className="text-base font-semibold text-foreground leading-tight truncate">
|
||||
{origPet.name}
|
||||
</p>
|
||||
|
||||
@@ -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)
|
||||
<ArrowLeft className="h-5 w-5" aria-hidden="true" />
|
||||
</button>
|
||||
<Link href={`/pets/${otherPet.id}`} className="flex items-center gap-2 hover:opacity-80">
|
||||
<Avatar className="w-8 h-8">
|
||||
{otherAvatarUrl && <AvatarImage src={otherAvatarUrl} alt={otherPet.name} />}
|
||||
<AvatarFallback className="text-xs bg-muted">
|
||||
{otherPet.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<RankRing owner={otherPet.owner}>
|
||||
<Avatar className="w-8 h-8">
|
||||
{otherAvatarUrl && <AvatarImage src={otherAvatarUrl} alt={otherPet.name} />}
|
||||
<AvatarFallback className="text-xs bg-muted">
|
||||
{otherPet.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
</RankRing>
|
||||
<span className="text-sm font-semibold">{formatPetName(otherPet)}</span>
|
||||
</Link>
|
||||
</div>
|
||||
@@ -143,12 +147,14 @@ export function MessageThread({ conversationId, otherPet }: MessageThreadProps)
|
||||
|
||||
{!isLoading && messages.length === 0 && (
|
||||
<div className="flex flex-col items-center gap-2 py-20 text-muted-foreground">
|
||||
<Avatar className="w-16 h-16">
|
||||
{otherAvatarUrl && <AvatarImage src={otherAvatarUrl} alt={otherPet.name} />}
|
||||
<AvatarFallback className="text-xl bg-muted">
|
||||
{otherPet.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<RankRing owner={otherPet.owner}>
|
||||
<Avatar className="w-16 h-16">
|
||||
{otherAvatarUrl && <AvatarImage src={otherAvatarUrl} alt={otherPet.name} />}
|
||||
<AvatarFallback className="text-xl bg-muted">
|
||||
{otherPet.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
</RankRing>
|
||||
<p className="text-sm font-medium mt-2">{formatPetName(otherPet)}</p>
|
||||
<p className="text-xs">{t("empty")}</p>
|
||||
</div>
|
||||
@@ -178,14 +184,16 @@ export function MessageThread({ conversationId, otherPet }: MessageThreadProps)
|
||||
{!isOwn && (
|
||||
<div className="w-7 h-7 shrink-0">
|
||||
{showAvatar && (
|
||||
<Avatar className="w-7 h-7">
|
||||
{otherAvatarUrl && (
|
||||
<AvatarImage src={otherAvatarUrl} alt={otherPet.name} />
|
||||
)}
|
||||
<AvatarFallback className="text-xs bg-muted">
|
||||
{otherPet.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<RankRing owner={otherPet.owner}>
|
||||
<Avatar className="w-7 h-7">
|
||||
{otherAvatarUrl && (
|
||||
<AvatarImage src={otherAvatarUrl} alt={otherPet.name} />
|
||||
)}
|
||||
<AvatarFallback className="text-xs bg-muted">
|
||||
{otherPet.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
</RankRing>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -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 (
|
||||
<span
|
||||
className={`inline-flex shrink-0 rounded-full${className ? ` ${className}` : ""}`}
|
||||
style={{ boxShadow: `0 0 0 2px var(--background), 0 0 0 4px ${color}` }}
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<div className="flex items-center gap-2 px-4 py-2">
|
||||
<Avatar className="h-8 w-8 shrink-0">
|
||||
{pet.avatarKey && (
|
||||
<AvatarImage src={getAvatarUrl(pet.avatarKey)!} alt={pet.name} />
|
||||
)}
|
||||
<AvatarFallback className="text-xs bg-muted">
|
||||
{pet.name.slice(0, 2).toUpperCase()}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<RankRing owner={pet.owner}>
|
||||
<Avatar className="h-8 w-8 shrink-0">
|
||||
{pet.avatarKey && (
|
||||
<AvatarImage src={getAvatarUrl(pet.avatarKey)!} alt={pet.name} />
|
||||
)}
|
||||
<AvatarFallback className="text-xs bg-muted">
|
||||
{pet.name.slice(0, 2).toUpperCase()}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
</RankRing>
|
||||
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm font-semibold truncate">{pet.name}</p>
|
||||
|
||||
@@ -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 && (
|
||||
<svg
|
||||
width={S}
|
||||
height={S}
|
||||
viewBox="0 0 100 100"
|
||||
className="absolute inset-0 pointer-events-none"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<circle cx={mainCx} cy={mainCy} r={mainR} fill="none" stroke={rankColor} strokeWidth={strokeW * 0.6} />
|
||||
</svg>
|
||||
)}
|
||||
{hasStory && (
|
||||
<svg
|
||||
width={S}
|
||||
|
||||
@@ -98,7 +98,7 @@ export function StoryCommentsOverlay({
|
||||
)}
|
||||
{comments.map((c) => (
|
||||
<div key={c.id} className="group flex items-start gap-2">
|
||||
<PetAvatar name={c.pet.name} avatarKey={c.pet.avatarKey} className="h-6 w-6 shrink-0" />
|
||||
<PetAvatar name={c.pet.name} avatarKey={c.pet.avatarKey} className="h-6 w-6 shrink-0" owner={c.pet.owner} />
|
||||
<div className="min-w-0 flex-1">
|
||||
<span className="mr-1 text-xs font-semibold text-white">{c.pet.name}</span>
|
||||
<span className="break-words text-xs text-white/90">{c.body}</span>
|
||||
|
||||
@@ -101,6 +101,7 @@ export function StoryTray() {
|
||||
<PawRing
|
||||
petId={activePet.id}
|
||||
includeOwnRecent
|
||||
owner={activePet.owner}
|
||||
size={TRAY_AVATAR_SIZE}
|
||||
onPress={() =>
|
||||
setViewingPet({ id: activePet.id, name: activePet.name, avatarKey: activePet.avatarKey ?? null })
|
||||
@@ -132,6 +133,7 @@ export function StoryTray() {
|
||||
<PawRing
|
||||
petId={pet.id}
|
||||
size={TRAY_AVATAR_SIZE}
|
||||
owner={pet.owner}
|
||||
onPress={() => setViewingPet(pet)}
|
||||
>
|
||||
<Avatar
|
||||
|
||||
@@ -33,6 +33,7 @@ import { BlurImage } from "@/components/ui/blur-image";
|
||||
import { AiDisclosureBadge } from "@/components/content/AiDisclosureBadge";
|
||||
import { StoryPawButton } from "@/components/stories/StoryPawButton";
|
||||
import { StoryCommentsOverlay } from "@/components/stories/StoryCommentsOverlay";
|
||||
import { RankRing } from "@/components/referrals/RankRing";
|
||||
|
||||
// Same lazy-load rationale as VideoCard.tsx — keep the HLS.js player runtime
|
||||
// out of the main bundle, only load it when a video story actually renders.
|
||||
@@ -536,17 +537,19 @@ export function StoryViewer({
|
||||
<ul className="space-y-3">
|
||||
{viewers.map((v) => (
|
||||
<li key={v.viewerPetId} className="flex items-center gap-3">
|
||||
<Avatar className="w-9 h-9 shrink-0">
|
||||
{v.viewerPet.avatarKey && (
|
||||
<AvatarImage
|
||||
src={getAvatarUrl(v.viewerPet.avatarKey) ?? ""}
|
||||
alt={v.viewerPet.name}
|
||||
/>
|
||||
)}
|
||||
<AvatarFallback className="text-xs bg-muted">
|
||||
{v.viewerPet.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<RankRing owner={v.viewerPet.owner}>
|
||||
<Avatar className="w-9 h-9 shrink-0">
|
||||
{v.viewerPet.avatarKey && (
|
||||
<AvatarImage
|
||||
src={getAvatarUrl(v.viewerPet.avatarKey) ?? ""}
|
||||
alt={v.viewerPet.name}
|
||||
/>
|
||||
)}
|
||||
<AvatarFallback className="text-xs bg-muted">
|
||||
{v.viewerPet.name[0]?.toUpperCase() ?? "?"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
</RankRing>
|
||||
<span className="text-sm font-medium">{v.viewerPet.name}</span>
|
||||
</li>
|
||||
))}
|
||||
|
||||
@@ -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 = (
|
||||
<Avatar size={size} className={className}>
|
||||
{avatarKey && <AvatarImage src={getAvatarUrl(avatarKey)!} alt={name} />}
|
||||
<AvatarFallback
|
||||
@@ -21,4 +25,5 @@ export function PetAvatar({ name, avatarKey, size = "default", className }: PetA
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
);
|
||||
return owner ? <RankRing owner={owner}>{avatar}</RankRing> : avatar;
|
||||
}
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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 }>;
|
||||
|
||||
@@ -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 },
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -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" },
|
||||
});
|
||||
|
||||
@@ -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 },
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user