feat: Story-Kommentare, Pfoten und Zuschauerliste in der App
- App-Viewer: Pfote, Kommentar-Sheet (schreiben, eigene löschen) und für die eigene Story die Zuschauerliste; Timer pausiert, solange ein Sheet offen ist - stories.listActive: optionales viewerPetId → reactedByViewer, damit die Pfote gefüllt startet (abwärtskompatibel für alte App-Builds) - Web-StoryPawButton nutzt reactedByViewer ebenfalls und wird pro Story neu initialisiert Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
204d5f6831
commit
ccebfa46a6
11 files changed
+533
-22
No files matched your search
@@ -141,6 +141,38 @@ describe("stories.create", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("stories.listActive", () => {
|
||||
it("marks stories the viewer already pawed and strips the raw reactions", async () => {
|
||||
const { caller, mockPrisma } = createCaller();
|
||||
mockPrisma.story.findMany.mockResolvedValue([
|
||||
{ id: "s1", petId: "pet-a", reactionCount: 2, reactions: [{ petId: "pet-me" }] },
|
||||
{ id: "s2", petId: "pet-a", reactionCount: 0, reactions: [] },
|
||||
]);
|
||||
|
||||
const result = await caller.listActive({ petId: "pet-a", viewerPetId: "pet-me" });
|
||||
|
||||
expect(result.map((s) => s.reactedByViewer)).toEqual([true, false]);
|
||||
expect(result[0]).not.toHaveProperty("reactions");
|
||||
expect(mockPrisma.story.findMany).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
include: expect.objectContaining({ reactions: { where: { petId: "pet-me" }, select: { petId: true }, take: 1 } }),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("stays compatible with older clients that send only petId", async () => {
|
||||
const { caller, mockPrisma } = createCaller();
|
||||
mockPrisma.story.findMany.mockResolvedValue([{ id: "s1", petId: "pet-a", reactionCount: 1 }]);
|
||||
|
||||
const result = await caller.listActive({ petId: "pet-a" });
|
||||
|
||||
expect(result[0].reactedByViewer).toBe(false);
|
||||
expect(mockPrisma.story.findMany).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ include: { musicTrack: true } })
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("stories.hasActiveStory", () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
|
||||
@@ -9,17 +9,18 @@ interface StoryPawButtonProps {
|
||||
storyId: string;
|
||||
petId: string;
|
||||
initialCount: number;
|
||||
/** From stories.listActive({ viewerPetId }) — whether the active pet already pawed this story. */
|
||||
initialReacted?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gitea #29 — paw-like button for stories, mirrors PawButton (feed posts).
|
||||
* initialReacted is always false (same limitation PawButton documents:
|
||||
* listActive doesn't return per-viewer reaction state) — the icon starts
|
||||
* unfilled and flips correctly on the first toggle this session.
|
||||
* initialReacted comes from stories.listActive({ viewerPetId }); the
|
||||
* parent keys this component by story id so state resets per story.
|
||||
*/
|
||||
export function StoryPawButton({ storyId, petId, initialCount }: StoryPawButtonProps) {
|
||||
export function StoryPawButton({ storyId, petId, initialCount, initialReacted = false }: StoryPawButtonProps) {
|
||||
const trpc = useTRPC();
|
||||
const [reacted, setReacted] = useState(false);
|
||||
const [reacted, setReacted] = useState(initialReacted);
|
||||
const [count, setCount] = useState(initialCount);
|
||||
const [animationKey, setAnimationKey] = useState(0);
|
||||
const [showBurst, setShowBurst] = useState(false);
|
||||
|
||||
@@ -81,7 +81,7 @@ export function StoryViewer({
|
||||
}, []);
|
||||
|
||||
const { data: stories = [] } = useQuery(
|
||||
trpc.stories.listActive.queryOptions({ petId })
|
||||
trpc.stories.listActive.queryOptions({ petId, viewerPetId: activePetId ?? undefined })
|
||||
);
|
||||
|
||||
const currentStory = stories[currentIndex];
|
||||
@@ -419,9 +419,11 @@ export function StoryViewer({
|
||||
{activePetId && (
|
||||
<div className="absolute bottom-6 right-4 z-10 flex flex-col items-center gap-4">
|
||||
<StoryPawButton
|
||||
key={currentStory.id}
|
||||
storyId={currentStory.id}
|
||||
petId={activePetId}
|
||||
initialCount={currentStory.reactionCount}
|
||||
initialReacted={currentStory.reactedByViewer}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -216,16 +216,28 @@ export const storiesRouter = router({
|
||||
|
||||
/**
|
||||
* List active (non-expired) stories for a pet (D-07 lazy-delete pattern).
|
||||
* With the optional viewerPetId, each story also carries reactedByViewer so
|
||||
* the paw button can start filled — optional so older app builds that only
|
||||
* send { petId } keep working unchanged (reactedByViewer is then false).
|
||||
*/
|
||||
listActive: protectedProcedure
|
||||
.input(z.object({ petId: z.string().min(1) }))
|
||||
.input(z.object({ petId: z.string().min(1), viewerPetId: z.string().min(1).optional() }))
|
||||
.query(async ({ ctx, input }) => {
|
||||
return ctx.prisma.story.findMany({
|
||||
const stories = await ctx.prisma.story.findMany({
|
||||
where: { petId: input.petId, expiresAt: { gt: new Date() } },
|
||||
include: { musicTrack: true },
|
||||
include: {
|
||||
musicTrack: true,
|
||||
...(input.viewerPetId
|
||||
? { reactions: { where: { petId: input.viewerPetId }, select: { petId: true }, take: 1 } }
|
||||
: {}),
|
||||
},
|
||||
orderBy: { createdAt: "asc" },
|
||||
take: 50,
|
||||
});
|
||||
return stories.map(({ reactions, ...story }: (typeof stories)[number] & { reactions?: { petId: string }[] }) => ({
|
||||
...story,
|
||||
reactedByViewer: (reactions?.length ?? 0) > 0,
|
||||
}));
|
||||
}),
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user