1
0
Fork 0

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
This commit is contained in:
Jason Fraley 2026-10-09 13:48:51 -04:00
parent dffcd0013c
commit aa09252b06
5 changed files with 73 additions and 23 deletions

View file

@ -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() {
<p className="text-xs uppercase tracking-[0.3em] text-muted-foreground">
The Unit Chronicle
</p>
<h1 className="mt-2 font-serif text-4xl font-bold">Story Chronicle</h1>
<h1 className="mt-2 font-serif text-4xl font-bold">The Chronicle</h1>
<p className="mt-3 text-muted-foreground">
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.
</p>
{displayBeats.length > 0 && (
<div className="mt-5 flex flex-wrap justify-center gap-2">
@ -122,12 +130,13 @@ export default async function StoryPage() {
{displayBeats.length === 0 ? (
<p className="text-center text-muted-foreground">
No published chapters yet. Check back soon.
No chronicle entries to show yet. Check back soon.
</p>
) : (
<ol className="space-y-16">
{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() {
<p className="text-xs uppercase tracking-widest text-muted-foreground">
Chapter {chapterById.get(beat.id) ?? 0}
</p>
<BeatReadMarker beatId={beat.id} initialRead={Boolean(state?.readAt)} />
{isDraft ? (
<DraftBadge />
) : (
<BeatReadMarker beatId={beat.id} initialRead={Boolean(state?.readAt)} />
)}
</div>
<h2 className="mt-2 font-serif text-2xl font-semibold">{beat.title}</h2>
<div className="mt-1 flex flex-wrap items-center gap-3 text-xs text-muted-foreground">
@ -174,11 +187,13 @@ export default async function StoryPage() {
<div className="mt-4">
<RichText data={beat.body} className={cn(BEAT_BODY_CLASSES)} />
</div>
<BeatReactions
beatId={beat.id}
initialReaction={state?.reaction ?? null}
initialCounts={counts.get(beat.id) ?? emptyCounts()}
/>
{!isDraft && (
<BeatReactions
beatId={beat.id}
initialReaction={state?.reaction ?? null}
initialCounts={counts.get(beat.id) ?? emptyCounts()}
/>
)}
</li>
);
})}

View file

@ -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[]
<p className="text-xs uppercase tracking-[0.3em] text-neutral-500">
Chapter {beat.chapter}
</p>
<BeatReadMarker beatId={beat.id} initialRead={beat.initialRead} />
{beat.draft ? (
<DraftBadge />
) : (
<BeatReadMarker beatId={beat.id} initialRead={beat.initialRead} />
)}
</div>
<div className="mt-6 text-center">
<h2 className="font-serif text-3xl font-semibold leading-tight text-white sm:text-4xl">

View file

@ -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 (
<span
className={cn(
"inline-flex shrink-0 items-center rounded-sm border border-amber-500/40 bg-amber-500/15 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-amber-400",
className,
)}
>
Draft
</span>
);
}

View file

@ -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({
<ol className="border-l border-border">
{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"
/>
)}
<span
aria-hidden="true"
className={cn(
"mt-1.5 size-1.5 shrink-0 rounded-full",
beat.initialRead ? "bg-emerald-500" : "bg-amber-500",
)}
/>
{beat.draft ? (
<DraftBadge className="mt-0.5" />
) : (
<span
aria-hidden="true"
className={cn(
"mt-1.5 size-1.5 shrink-0 rounded-full",
beat.initialRead ? "bg-emerald-500" : "bg-amber-500",
)}
/>
)}
</button>
</li>
);

View file

@ -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 { StoryBeat } from "@/payload-types";
import { cn } from "@/lib/utils";
import { READER_BODY_CLASSES } from "@/lib/story/richtextClasses";
@ -19,6 +20,8 @@ export type StoryViewerBeat = {
readonly initialRead: boolean;
readonly voiceoverUrl: string | null;
readonly voiceoverAiGenerated: boolean;
/** True when the entry is still a draft (visible only to story staff). */
readonly draft: boolean;
};
export function StoryViewer({ beats }: { readonly beats: readonly StoryViewerBeat[] }) {
@ -94,9 +97,13 @@ export function StoryViewer({ beats }: { readonly beats: readonly StoryViewerBea
<p className="text-xs uppercase tracking-[0.3em] text-neutral-500">
Chapter {beat.chapter}
</p>
<div className="[&_.text-muted-foreground]:text-neutral-500">
<BeatReadMarker beatId={beat.id} initialRead={beat.initialRead} />
</div>
{beat.draft ? (
<DraftBadge />
) : (
<div className="[&_.text-muted-foreground]:text-neutral-500">
<BeatReadMarker beatId={beat.id} initialRead={beat.initialRead} />
</div>
)}
</div>
<h2 className="mt-6 font-serif text-3xl font-semibold leading-tight text-white sm:text-4xl">
{beat.title}