Add draft preview to posts and builders#40
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
resolveAccessToken()— reads/me, and only if the user is a real admin hands the OAuth access token to the request-scoped store.apiFetchattaches that token, so York Factory returns draft content (preview mode).DraftPreviewBannerrenders 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 ingenerateMetadata+ the page, add the draft-not-found admin fallback, and render the banner for genuine drafts.DraftPreviewBannerfrommemos/[slug]/tocomponents/auth/so all three content types share it (memos import updated).lib/api/builders.ts: readpublishedAtfrom the builder detail response (needed for the genuine-draft check).Dependency
Builders needs
published_atfrom 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,publishedAtisundefinedand a viewing admin would see the banner on published builders too).Testing
npx eslinton changed files — clean.npx tsc --noEmit— no new errors in changed files (pre-existingbills/next-auth errors are unrelated).