Skip to content

Add draft preview to posts and builders#40

Merged
xrendan merged 3 commits into
mainfrom
feature/posts-builders-draft-preview
Jul 23, 2026
Merged

Add draft preview to posts and builders#40
xrendan merged 3 commits into
mainfrom
feature/posts-builders-draft-preview

Conversation

@xrendan

@xrendan xrendan commented Jul 23, 2026

Copy link
Copy Markdown
Member

Summary

Brings the memo draft-preview experience to posts and builders. A signed-in admin can now open an unpublished post/builder and see it rendered with a DRAFT banner; everyone else still gets a 404 for unpublished content.

How it works

Same pattern as memos:

  1. The page calls resolveAccessToken() — reads /me, and only if the user is a real admin hands the OAuth access token to the request-scoped store.
  2. apiFetch attaches that token, so York Factory returns draft content (preview mode).
  3. A DraftPreviewBanner renders only for genuine drafts — no publish date, or one scheduled in the future — so admins don't see the banner on already-published content.

Changes

  • posts/[slug]/page.tsx, builders/[slug]/page.tsx: prime the token in generateMetadata + the page, add the draft-not-found admin fallback, and render the banner for genuine drafts.
  • Moved DraftPreviewBanner from memos/[slug]/ to components/auth/ so all three content types share it (memos import updated).
  • lib/api/builders.ts: read publishedAt from the builder detail response (needed for the genuine-draft check).

Dependency

Builders needs published_at from the builder API, added in BuildCanada/york_factory#78. Merge/deploy that first (posts already works today; the builder banner's genuine-draft check depends on the new field — until it deploys, publishedAt is undefined and a viewing admin would see the banner on published builders too).

Testing

  • npx eslint on changed files — clean.
  • npx tsc --noEmit — no new errors in changed files (pre-existing bills/ next-auth errors are unrelated).
  • TradingPost has no automated test suite; verified types + lint.

xrendan added 3 commits July 23, 2026 12:22
Posts and builders now prime the admin OAuth access token before
fetching (like memos), so signed-in admins can preview unpublished
content and see a DRAFT banner. The banner shows only for genuine
drafts (no publish date, or one scheduled in the future).

Moves DraftPreviewBanner out of the memos route into
components/auth so all three content types can share it. Builders
now reads publishedAt from the API (York Factory exposes it in the
builder serializer) to make the genuine-draft distinction.
The token-priming, genuine-draft check, and admin 404 fallback were
duplicated across the memos, posts, and builders pages. Pull them into:

- lib/preview.ts: primeAdminPreviewToken() + isDraft()
- components/auth/PreviewNotFound.tsx: the admin draft-not-found page

All three pages now share these. No behaviour change (memos keeps its
existing banner condition; the isDraft gating for memos stays in the
in-flight fix/draft-banner-published-memos branch).
…c page

In preview mode the API returns all records, so a fetch miss means the
slug genuinely doesn't exist — the normal notFound() page is the correct
and simpler response. Drops PreviewNotFound; memos, posts, and builders
all just call notFound() now.
@xrendan
xrendan merged commit 4a2faee into main Jul 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant