From 56760654006be3a1c4b5c2b1101d483dabfc9563 Mon Sep 17 00:00:00 2001 From: neodk2004 Date: Sun, 4 Oct 2026 16:47:25 +0200 Subject: [PATCH] feat(web): Story-Overlays und Text-Storys im Web-Viewer anzeigen Web zeigt Story-Editor-Inhalte nur an (Entscheidung: kein Web-Editor): StoryOverlayLayer mit gleicher Geometrie/Groessen wie die App, Text-Storys mit Farbverlauf, Markierungen fuehren ins Tierprofil, Notschalter beachtet. Mitteilungen STORY_MENTION/COMMENT/REACTION, Hinweistexte: Follower- Sichtbarkeit regelt jetzt auch das Markieren. Co-Authored-By: Claude Opus 5.5 --- messages/de.json | 11 +- messages/en.json | 11 +- src/app/(app)/notifications/page.tsx | 15 +- src/components/stories/StoryOverlayLayer.tsx | 243 +++++++++++++++++++ src/components/stories/StoryViewer.tsx | 27 +++ 5 files changed, 297 insertions(+), 10 deletions(-) create mode 100644 src/components/stories/StoryOverlayLayer.tsx diff --git a/messages/de.json b/messages/de.json index 2e5e6e3..797f448 100644 --- a/messages/de.json +++ b/messages/de.json @@ -483,7 +483,10 @@ "typePetSuggestion": "könnte dir gefallen", "typeReferralJoined": "ist über deine Einladung zu PawFeed gekommen", "typeReferralRankUp": "Du hast einen neuen Empfehlungsrang erreicht. Schau ihn dir an!", - "typeVaccineDue": "💉 Die Impfung „{name}“ ist am {date} fällig – Zeit, einen Termin zu vereinbaren." + "typeVaccineDue": "💉 Die Impfung „{name}“ ist am {date} fällig – Zeit, einen Termin zu vereinbaren.", + "typeStoryMention": "hat dich in einer Story markiert.", + "typeStoryComment": "hat deine Story kommentiert.", + "typeStoryReaction": "hat deiner Story eine Pfote gegeben." }, "PhotoPostForm": { "captionPlaceholder": "Bildunterschrift schreiben…", @@ -669,9 +672,9 @@ "onlyMe": "Nur ich", "followerVisibilitySaved": "Follower-Sichtbarkeit gespeichert", "followerVisibilitySaveFailed": "Follower-Sichtbarkeit konnte nicht gespeichert werden", - "followerEveryoneHint": "Jeder kann die Follower- und Folgt-Listen von {name} sehen.", - "followerFollowersOnlyHint": "Nur Tiere, die {name} folgen, können die Follower- und Folgt-Listen sehen.", - "followerNobodyHint": "Nur du kannst die Follower- und Folgt-Listen von {name} sehen.", + "followerEveryoneHint": "Jeder kann die Follower- und Folgt-Listen von {name} sehen und {name} in Storys markieren.", + "followerFollowersOnlyHint": "Nur Tiere, die {name} folgen, können die Follower- und Folgt-Listen sehen und {name} in Storys markieren.", + "followerNobodyHint": "Nur du kannst die Follower- und Folgt-Listen von {name} sehen — markieren in Storys kann {name} niemand.", "verificationHeading": "Verifizierung", "verifiedStatus": "Dieses Tier ist verifiziert.", "pendingStatus": "Dein Verifizierungsantrag wird noch geprüft.", diff --git a/messages/en.json b/messages/en.json index 37d7a9b..cc4b03f 100644 --- a/messages/en.json +++ b/messages/en.json @@ -483,7 +483,10 @@ "typePetSuggestion": "might be a good match", "typeReferralJoined": "joined PawFeed through your invite", "typeReferralRankUp": "You reached a new referral rank. Take a look!", - "typeVaccineDue": "💉 The \"{name}\" vaccination is due on {date} – time to book an appointment." + "typeVaccineDue": "💉 The \"{name}\" vaccination is due on {date} – time to book an appointment.", + "typeStoryMention": "tagged you in a story.", + "typeStoryComment": "commented on your story.", + "typeStoryReaction": "gave your story a paw." }, "PhotoPostForm": { "captionPlaceholder": "Write a caption…", @@ -669,9 +672,9 @@ "onlyMe": "Only me", "followerVisibilitySaved": "Follower privacy setting saved", "followerVisibilitySaveFailed": "Failed to save follower privacy setting", - "followerEveryoneHint": "Anyone can see {name}'s followers and following lists.", - "followerFollowersOnlyHint": "Only pets that follow {name} can see the followers and following lists.", - "followerNobodyHint": "Only you can see {name}'s followers and following lists.", + "followerEveryoneHint": "Anyone can see {name}'s followers and following lists and tag {name} in stories.", + "followerFollowersOnlyHint": "Only pets that follow {name} can see the followers and following lists and tag {name} in stories.", + "followerNobodyHint": "Only you can see {name}'s followers and following lists — nobody can tag {name} in stories.", "verificationHeading": "Verification", "verifiedStatus": "This pet is verified.", "pendingStatus": "Your verification request is pending review.", diff --git a/src/app/(app)/notifications/page.tsx b/src/app/(app)/notifications/page.tsx index 1c7d343..b8d9a08 100644 --- a/src/app/(app)/notifications/page.tsx +++ b/src/app/(app)/notifications/page.tsx @@ -3,7 +3,7 @@ import { useEffect, useState } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; -import { Bell, UserPlus, Heart, MessageCircle, Cake, Home, AtSign, Repeat2, Sparkles, Gift, Award, Syringe } from "lucide-react"; +import { Bell, UserPlus, Heart, MessageCircle, Cake, Home, AtSign, Repeat2, Sparkles, Gift, Award, Syringe, PawPrint } from "lucide-react"; import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import { useTRPC } from "@/trpc/client"; import { useActivePet } from "@/context/ActivePetContext"; @@ -17,7 +17,7 @@ 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"; +type NotificationType = "FOLLOW" | "REACTION" | "COMMENT" | "MESSAGE" | "BIRTHDAY" | "ADOPTION_DAY" | "MENTION" | "PAW_BACK" | "PET_SUGGESTION" | "REFERRAL_JOINED" | "REFERRAL_RANK_UP" | "VACCINE_DUE" | "STORY_MENTION" | "STORY_COMMENT" | "STORY_REACTION"; function notificationIcon(type: NotificationType) { switch (type) { @@ -33,6 +33,9 @@ function notificationIcon(type: NotificationType) { case "REFERRAL_JOINED": return ; case "REFERRAL_RANK_UP": return ; case "VACCINE_DUE": return ; + case "STORY_MENTION": return ; + case "STORY_COMMENT": return ; + case "STORY_REACTION": return ; } } @@ -100,6 +103,11 @@ export default function NotificationsPage() { return notif.actorPet ? `/pets/${notif.actorPet.id}` : null; case "REFERRAL_RANK_UP": return "/einladen"; + // Story-Mitteilungen → Tierprofil (dort läuft die Story über den Ring) + case "STORY_MENTION": + case "STORY_COMMENT": + case "STORY_REACTION": + return notif.story ? `/pets/${notif.story.petId}` : null; case "BIRTHDAY": case "ADOPTION_DAY": case "VACCINE_DUE": @@ -240,6 +248,9 @@ export default function NotificationsPage() { {notif.type === "PET_SUGGESTION" && t("typePetSuggestion")} {notif.type === "REFERRAL_JOINED" && t("typeReferralJoined")} {notif.type === "REFERRAL_RANK_UP" && t("typeReferralRankUp")} + {notif.type === "STORY_MENTION" && t("typeStoryMention")} + {notif.type === "STORY_COMMENT" && t("typeStoryComment")} + {notif.type === "STORY_REACTION" && t("typeStoryReaction")} {notif.type === "VACCINE_DUE" && notif.vaccine?.nextDueDate && t("typeVaccineDue", { name: notif.vaccine.name, diff --git a/src/components/stories/StoryOverlayLayer.tsx b/src/components/stories/StoryOverlayLayer.tsx new file mode 100644 index 0000000..9d6b0ef --- /dev/null +++ b/src/components/stories/StoryOverlayLayer.tsx @@ -0,0 +1,243 @@ +"use client"; + +import { useLayoutEffect, useRef, useState, type CSSProperties } from "react"; +import { + OVERLAY_SIZES, + STORY_BACKGROUNDS, + containRect, + contrastTextColor, + overlayCenter, + type Rect, + type StoryOverlay, +} from "@/lib/story-overlays"; +import { STICKER_OUTLINE, STORY_STICKERS, type StickerPart } from "@/lib/story-stickers"; + +type MentionedPet = { id: string; name: string }; + +/** + * Web-Anzeige des Story-Editors (erstellt wird nur in der App). Legt Text, + * Markierungen, GIFs und Sticker auf die Medienfläche — dieselbe Geometrie und + * dieselben Größenregeln wie mobile/src/components/story-editor/, damit alles an + * derselben Stelle sitzt. Bei Text-Storys zeichnet die Ebene auch den Farbverlauf. + */ +export function StoryOverlayLayer({ + overlays, + mediaSize, + mentionedPets, + background, + showOverlays, + onMentionClick, +}: { + overlays: readonly StoryOverlay[]; + mediaSize: { width: number; height: number }; + mentionedPets: readonly MentionedPet[]; + /** Nur Text-Storys: Farbverlauf-Schlüssel */ + background?: string | null; + /** Notschalter: aus → nur der Farbverlauf, keine Overlays */ + showOverlays: boolean; + onMentionClick?: (petId: string) => void; +}) { + const containerRef = useRef(null); + const [box, setBox] = useState({ width: 0, height: 0 }); + + useLayoutEffect(() => { + const el = containerRef.current; + if (!el) return; + const update = () => setBox({ width: el.clientWidth, height: el.clientHeight }); + update(); + const observer = new ResizeObserver(update); + observer.observe(el); + return () => observer.disconnect(); + }, []); + + const rect = containRect(box.width, box.height, mediaSize.width, mediaSize.height); + + return ( +
+ +
+ ); +} + +/** Reine Darstellung auf einer bekannten Medienfläche — ohne Messen (auch für Vorschau/Tests). */ +export function StoryOverlayStatic({ + overlays, + rect, + mentionedPets, + background, + showOverlays, + onMentionClick, +}: { + overlays: readonly StoryOverlay[]; + rect: Rect; + mentionedPets: readonly MentionedPet[]; + background?: string | null; + showOverlays: boolean; + onMentionClick?: (petId: string) => void; +}) { + if (rect.width <= 0) return null; + const names = new Map(mentionedPets.map((p) => [p.id, p.name])); + const gradient = background ? STORY_BACKGROUNDS[background] ?? STORY_BACKGROUNDS.sunset : null; + + return ( + <> + {gradient && ( +
+ )} + {showOverlays && + overlays.map((overlay, i) => ( + + {overlay.kind === "mention" ? ( + + ) : ( + + )} + + ))} + + ); +} + +function Positioned({ overlay, rect, children }: { overlay: StoryOverlay; rect: Rect; children: React.ReactNode }) { + const { left, top } = overlayCenter(rect, overlay); + return ( +
+ {children} +
+ ); +} + +function OverlayContent({ overlay, baseWidth }: { overlay: StoryOverlay; baseWidth: number }) { + switch (overlay.kind) { + case "text": + return ; + case "gif": { + const width = OVERLAY_SIZES.gifWidth * baseWidth; + return ( + // eslint-disable-next-line @next/next/no-img-element -- animiertes GIF von GIPHY, kein next/image + GIF + ); + } + case "sticker": + return ; + case "mention": + return null; + } +} + +/** Gleiche Regeln wie textAppearance() in der App (OverlayContent.tsx). */ +function textAppearance(overlay: Extract): { color: string; background?: string } { + switch (overlay.style) { + case "box": + return { color: contrastTextColor(overlay.color), background: overlay.color }; + case "soft": + return { color: overlay.color, background: overlay.color === "#171717" ? "rgba(255,255,255,0.85)" : "rgba(0,0,0,0.55)" }; + default: + return { color: overlay.color }; + } +} + +function TextContent({ overlay, baseWidth }: { overlay: Extract; baseWidth: number }) { + const fontSize = OVERLAY_SIZES.textFont * baseWidth; + const { color, background } = textAppearance(overlay); + const style: CSSProperties = { + maxWidth: OVERLAY_SIZES.textMaxWidth * baseWidth, + width: "max-content", + fontSize, + lineHeight: 1.2, + color, + fontWeight: overlay.font === "bold" ? 700 : 400, + textAlign: "center", + whiteSpace: "pre-wrap", + overflowWrap: "break-word", + background, + borderRadius: fontSize * 0.3, + padding: background ? `${fontSize * 0.18}px ${fontSize * 0.4}px` : 0, + textShadow: background ? undefined : "0 1px 6px rgba(0,0,0,0.45)", + }; + return
{overlay.text}
; +} + +function MentionChip({ name, baseWidth }: { name: string; baseWidth: number }) { + const fontSize = OVERLAY_SIZES.mentionFont * baseWidth; + return ( + + @{name} + + ); +} + +function Sticker({ stickerId, size }: { stickerId: string; size: number }) { + const sticker = STORY_STICKERS.find((s) => s.id === stickerId); + if (!sticker) return null; + return ( + + {sticker.parts.map((part, i) => ( + + ))} + {sticker.parts.map((part, i) => ( + + ))} + + ); +} + +function Shape({ part, fill, stroke, strokeWidth }: { part: StickerPart; fill: string; stroke?: string; strokeWidth?: number }) { + const strokeProps = stroke ? { stroke, strokeWidth, strokeLinejoin: "round" as const } : {}; + switch (part.type) { + case "circle": + return ; + case "rect": + return ; + case "path": + return ; + } +} diff --git a/src/components/stories/StoryViewer.tsx b/src/components/stories/StoryViewer.tsx index d8eead4..96114f8 100644 --- a/src/components/stories/StoryViewer.tsx +++ b/src/components/stories/StoryViewer.tsx @@ -2,6 +2,7 @@ import { useState, useEffect, useCallback, useRef } from "react"; import { createPortal } from "react-dom"; +import { useRouter } from "next/navigation"; import dynamic from "next/dynamic"; import { X, Eye, Volume2, VolumeX, Loader2, MessageCircle, Trash2, PawPrint, Clock } from "lucide-react"; import { toast } from "sonner"; @@ -34,6 +35,8 @@ import { AiDisclosureBadge } from "@/components/content/AiDisclosureBadge"; import { StoryPawButton } from "@/components/stories/StoryPawButton"; import { StoryCommentsOverlay } from "@/components/stories/StoryCommentsOverlay"; import { RankRing } from "@/components/referrals/RankRing"; +import { StoryOverlayLayer } from "@/components/stories/StoryOverlayLayer"; +import { storyMediaSize } from "@/lib/story-overlays"; // 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. @@ -102,6 +105,11 @@ export function StoryViewer({ const currentStory = stories[currentIndex]; const isOwnPet = activePetId === petId; const isVideo = currentStory?.mediaType === "VIDEO"; + const isText = currentStory?.mediaType === "TEXT"; + const router = useRouter(); + // Story-Editor-Notschalter (Admin): aus → Overlays ausblenden. + const { data: featureFlags } = useQuery({ ...trpc.stories.featureFlags.queryOptions(), staleTime: 60_000 }); + const showOverlays = featureFlags?.storyEditor ?? false; const musicUrl = currentStory?.musicTrack ? getMusicUrl(currentStory.musicTrack.storageKey) : null; // For a VIDEO story, the overlay track only plays if musicMuteOriginal was // chosen at creation time (see StoryForm.tsx) — otherwise the video keeps @@ -265,6 +273,21 @@ export function StoryViewer({ if (!currentStory) return null; const mediaUrl = currentStory.storageKey ? getMediaUrl(currentStory.storageKey) : null; + // Fläche, auf die sich Story-Editor-Overlays beziehen (null = alte Story ohne Maße → keine Overlays). + const overlayMediaSize = storyMediaSize(currentStory); + const overlayLayer = overlayMediaSize ? ( + { + handleClose(); + router.push(`/pets/${mentionedPetId}`); + }} + /> + ) : null; return ( <> @@ -369,12 +392,15 @@ export function StoryViewer({ )} )} + {videoStatus === "READY" && overlayLayer}
+ ) : isText ? ( +
{overlayLayer}
) : ( mediaUrl && (
@@ -385,6 +411,7 @@ export function StoryViewer({ className="block w-full h-full object-contain" wrapperClassName="relative block w-full h-full" /> + {overlayLayer}