Files
petfeed/src/components/feed/MilestoneCard.tsx
T
admin 50e2848312 feat(legal): AI-content disclosure for user uploads (Gitea #18)
Owners can now optionally mark uploaded content as AI_MODIFIED or
AI_GENERATED (mutually exclusive, defaults to NONE) across every upload
surface — photo posts, video posts, milestones, stories, and pet avatars.
Once set, the choice is owner-immutable; only a moderator can correct it
via a new admin.setAiDisclosure mutation (Posts admin page), which
requires a reason and writes to ModerationLog like every other
moderation action.

The disclosure renders as a UI-only overlay badge (the two provided
label assets) wherever the content is shown — feed, post detail, story
viewer, milestone cards, and the pet profile avatar — never baked into
the image pixels.

New shared components: AiDisclosureSelect (the 3-way picker used in all
five upload forms) and AiDisclosureBadge (the overlay renderer).
2026-08-13 13:44:16 +02:00

100 lines
3.5 KiB
TypeScript

"use client";
import type { MilestoneType } from "@prisma/client";
import { MILESTONE_META } from "@/lib/milestone-meta";
import { getAvatarUrl } from "@/lib/avatar-url";
import { getMediaUrl } from "@/lib/media-url";
import { BlurImage } from "@/components/ui/blur-image";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { AiDisclosureBadge } from "@/components/content/AiDisclosureBadge";
import type { AiDisclosureValue } from "@/components/content/AiDisclosureSelect";
type MilestoneCardPost = {
id: string;
caption: string | null;
createdAt: Date | string;
aiDisclosure?: AiDisclosureValue;
pet: { id: string; name: string; avatarKey: string | null };
images: { id: string; storageKey: string; position: number; blurhash?: string | null }[];
milestone: { milestoneType: MilestoneType; notes: string | null } | null;
};
interface MilestoneCardProps {
post: MilestoneCardPost;
}
function formatDate(date: Date | string): string {
return new Date(date).toLocaleDateString(undefined, {
year: "numeric",
month: "long",
day: "numeric",
});
}
/**
* MilestoneCard — distinct orange-tinted card for milestone posts (MILE-02).
*
* Renders: icon (32px, orange-500) + type label (text-base font-semibold orange-500)
* + pet name + date + optional caption/notes + optional photo.
* Background: bg-orange-50 border border-orange-200 per UI-SPEC accent reservation #8.
*/
export function MilestoneCard({ post }: MilestoneCardProps) {
const { pet, milestone, images, caption } = post;
if (!milestone) return null;
const meta = MILESTONE_META[milestone.milestoneType];
const Icon = meta.icon;
const avatarUrl = getAvatarUrl(pet.avatarKey);
const photo = images[0];
return (
<article className="bg-orange-50 border border-orange-200 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>
<div className="flex-1 min-w-0">
<p className="text-base font-semibold text-foreground leading-tight truncate">
{pet.name}
</p>
<p className="text-xs text-muted-foreground">{formatDate(post.createdAt)}</p>
</div>
</div>
{/* Milestone type badge */}
<div className="flex items-center gap-3 px-4 pb-3">
<Icon className="h-8 w-8 text-orange-500 shrink-0" aria-hidden="true" />
<span className="text-base font-semibold text-orange-500">{meta.label}</span>
</div>
{/* Optional photo */}
{photo && (
<div className="relative w-full">
<BlurImage
src={getMediaUrl(photo.storageKey) ?? ""}
blurhash={photo.blurhash}
alt={caption ?? `${pet.name}'s milestone`}
className="w-full object-cover max-h-[400px]"
/>
<AiDisclosureBadge value={post.aiDisclosure} />
</div>
)}
{/* Caption or notes */}
{(caption || milestone.notes) && (
<div className="px-4 py-3 space-y-1">
{caption && <p className="text-sm text-foreground">{caption}</p>}
{milestone.notes && (
<p className="text-sm text-muted-foreground italic">{milestone.notes}</p>
)}
</div>
)}
</article>
);
}