From aa09252b0613dbaf7327a76e6196943eb6149883 Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Fri, 9 Oct 2026 13:48:51 -0400 Subject: [PATCH] feat(chronicle): show draft entries to staff on /story Drafts were only reachable in the admin panel: /story hard-filtered to published. Story staff (admin/developer) now see drafts in the Chronicle, badged and clearly marked, while everyone else stays published-only. The collection's own read access remains the backstop (overrideAccess stays false), so a non-staff request can never leak a draft. - page: staff fetch all entries, others published-only - new DraftBadge (amber pill) rendered in the list, immersive reader, book view, and table of contents - drafts hide the read marker and reactions - front-end copy adopts Chronicle wording --- src/app/(frontend)/story/page.tsx | 35 +++++++++++++------ src/components/frontend/story/BookView.tsx | 7 +++- src/components/frontend/story/DraftBadge.tsx | 18 ++++++++++ .../frontend/story/StoryTableOfContents.tsx | 23 +++++++----- src/components/frontend/story/StoryViewer.tsx | 13 +++++-- 5 files changed, 73 insertions(+), 23 deletions(-) create mode 100644 src/components/frontend/story/DraftBadge.tsx diff --git a/src/app/(frontend)/story/page.tsx b/src/app/(frontend)/story/page.tsx index b6943915..a3e41ee2 100644 --- a/src/app/(frontend)/story/page.tsx +++ b/src/app/(frontend)/story/page.tsx @@ -4,11 +4,13 @@ import { headers as nextHeaders } from "next/headers"; import { RichText } from "@payloadcms/richtext-lexical/react"; import type { StoryBeat, StoryBeatState, StoryVoiceover } from "@/payload-types"; import { isPayloadUser } from "@/utils/access-control/isPayloadUser"; +import hasRoles from "@/utils/access-control/hasRoles"; import { cn } from "@/lib/utils"; import { BEAT_BODY_CLASSES } from "@/lib/story/richtextClasses"; import { BeatReactions } from "@/components/frontend/story/BeatReactions"; import { BeatReadMarker } from "@/components/frontend/story/BeatReadMarker"; import { BeatVoiceover } from "@/components/frontend/story/BeatVoiceover"; +import { DraftBadge } from "@/components/frontend/story/DraftBadge"; import { BookView } from "@/components/frontend/story/BookView"; import { StoryViewer, type StoryViewerBeat } from "@/components/frontend/story/StoryViewer"; import { StoryTableOfContents } from "@/components/frontend/story/StoryTableOfContents"; @@ -43,9 +45,14 @@ export default async function StoryPage() { if (!isPayloadUser(user)) return null; + // Story staff (admin/developer) preview drafts on /story; everyone else sees + // published entries only. The collection's own read access is the backstop: + // overrideAccess stays false, so a non-staff request can never leak a draft. + const isStaff = hasRoles(["admin", "developer"], user); + const beatsResult = await payload.find({ collection: "story-beats", - where: { status: { equals: "published" } }, + ...(isStaff ? {} : { where: { status: { equals: "published" } } }), limit: 200, depth: 1, overrideAccess: false, @@ -98,6 +105,7 @@ export default async function StoryPage() { initialRead: Boolean(stateByBeat.get(beat.id)?.readAt), voiceoverUrl: voiceoverDoc(beat)?.url ?? null, voiceoverAiGenerated: voiceoverDoc(beat)?.aiGenerated ?? false, + draft: beat.status !== "published", })); return ( @@ -108,9 +116,9 @@ export default async function StoryPage() {

The Unit Chronicle

-

Story Chronicle

+

The Chronicle

- Every operation leaves a mark. These are the beats of our story, told in order. + Every operation leaves a mark. These are the entries of our chronicle, told in order.

{displayBeats.length > 0 && (
@@ -122,12 +130,13 @@ export default async function StoryPage() { {displayBeats.length === 0 ? (

- No published chapters yet. Check back soon. + No chronicle entries to show yet. Check back soon.

) : (
    {displayBeats.map((beat) => { const state = stateByBeat.get(beat.id); + const isDraft = beat.status !== "published"; const mission = beat.mission && typeof beat.mission !== "number" ? beat.mission : null; const missionLabel = mission @@ -149,7 +158,11 @@ export default async function StoryPage() {

    Chapter {chapterById.get(beat.id) ?? 0}

    - + {isDraft ? ( + + ) : ( + + )}

{beat.title}

@@ -174,11 +187,13 @@ export default async function StoryPage() {
- + {!isDraft && ( + + )} ); })} diff --git a/src/components/frontend/story/BookView.tsx b/src/components/frontend/story/BookView.tsx index 570e444d..16d342e3 100644 --- a/src/components/frontend/story/BookView.tsx +++ b/src/components/frontend/story/BookView.tsx @@ -6,6 +6,7 @@ import { RichText } from "@payloadcms/richtext-lexical/react"; import { Button } from "@/components/ui/button"; import { BeatReadMarker } from "@/components/frontend/story/BeatReadMarker"; import { BeatVoiceover } from "@/components/frontend/story/BeatVoiceover"; +import { DraftBadge } from "@/components/frontend/story/DraftBadge"; import type { StoryViewerBeat } from "@/components/frontend/story/StoryViewer"; import { BOOK_COLUMN_GAP, @@ -258,7 +259,11 @@ export function BookView({ beats }: { readonly beats: readonly StoryViewerBeat[]

Chapter {beat.chapter}

- + {beat.draft ? ( + + ) : ( + + )}

diff --git a/src/components/frontend/story/DraftBadge.tsx b/src/components/frontend/story/DraftBadge.tsx new file mode 100644 index 00000000..3b400109 --- /dev/null +++ b/src/components/frontend/story/DraftBadge.tsx @@ -0,0 +1,18 @@ +import { cn } from "@/lib/utils"; + +/** + * Amber "Draft" pill marking a chronicle entry that is not yet published. + * Shown only to story staff, who can preview drafts on /story. + */ +export function DraftBadge({ className }: { className?: string }) { + return ( + + Draft + + ); +} diff --git a/src/components/frontend/story/StoryTableOfContents.tsx b/src/components/frontend/story/StoryTableOfContents.tsx index 8dd3ba9e..6a384626 100644 --- a/src/components/frontend/story/StoryTableOfContents.tsx +++ b/src/components/frontend/story/StoryTableOfContents.tsx @@ -3,11 +3,12 @@ import { useEffect, useState } from "react"; import { Headphones } from "lucide-react"; import type { StoryViewerBeat } from "@/components/frontend/story/StoryViewer"; +import { DraftBadge } from "@/components/frontend/story/DraftBadge"; import { cn } from "@/lib/utils"; export type StoryTableOfContentsBeat = Pick< StoryViewerBeat, - "id" | "title" | "chapter" | "initialRead" | "voiceoverUrl" + "id" | "title" | "chapter" | "initialRead" | "voiceoverUrl" | "draft" >; export function StoryTableOfContents({ @@ -79,7 +80,7 @@ export function StoryTableOfContents({
    {beats.map((beat) => { const active = activeBeatId === beat.id; - const readLabel = beat.initialRead ? "Read" : "Unread"; + const readLabel = beat.draft ? "Draft" : beat.initialRead ? "Read" : "Unread"; const ariaLabel = beat.voiceoverUrl ? `Chapter ${beat.chapter}: ${beat.title}. ${readLabel}. Has audio.` : `Chapter ${beat.chapter}: ${beat.title}. ${readLabel}.`; @@ -115,13 +116,17 @@ export function StoryTableOfContents({ className="mt-1.5 size-3 shrink-0 text-muted-foreground" /> )} -

{beat.title}