Skip to content

Add post templates to publish flow - #1079

Merged
feruzm merged 5 commits into
developfrom
feature/post-templates
Jul 6, 2026
Merged

Add post templates to publish flow#1079
feruzm merged 5 commits into
developfrom
feature/post-templates

Conversation

@feruzm

Copy link
Copy Markdown
Member

Adds reusable post templates to the publish flow: save the current post (title, body, tags, community, beneficiaries, reward type, poll) as a named template, apply it into the editor, and delete templates.

How it works

  • Templates are stored as regular private-api drafts carrying meta.postTemplate: true and meta.templateName, so no backend changes are needed. The drafts dialog filters them out of the normal drafts list.
  • New Templates entry in the publish action bar dropdown opens a dialog (list/apply/delete plus a save-as-template form), gated behind a new visionFeatures.postTemplates flag and login.
  • Applying a template hydrates publish state the same way draft loading does; if the editor already has content, apply asks for confirmation first.
  • Validate step shows a warning when the post body is still nearly identical to the applied template (word-overlap similarity >= 0.9), nudging authors to add their own content before publishing.

Notes

  • Templates ride the drafts pagination; the list chain-fetches pages until enough templates are collected.
  • The mobile app will show template drafts in its drafts screen until it ships the same meta filter (follow-up there).
  • New util wordOverlapSimilarity with unit tests; no new type errors vs develop baseline.

@coderabbitai

coderabbitaiBot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@feruzm, you've reached your PR review limit, so we couldn't start this review.

Next review available in:14 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 42b4a69f-45be-408c-8e34-b3b9e7df381b

📥 Commits

Reviewing files that changed from the base of the PR and between 61eae38 and 0a752c1.

📒 Files selected for processing (19)
  • apps/web/src/app/publish/_api/index.ts
  • apps/web/src/app/publish/_api/use-save-template.ts
  • apps/web/src/app/publish/_components/publish-action-bar.tsx
  • apps/web/src/app/publish/_components/publish-validate-post.tsx
  • apps/web/src/app/publish/_hooks/index.ts
  • apps/web/src/app/publish/_hooks/use-apply-template.ts
  • apps/web/src/app/publish/_hooks/use-publish-state.tsx
  • apps/web/src/app/publish/_page.tsx
  • apps/web/src/app/publish/drafts/[id]/_page.tsx
  • apps/web/src/config/config.template.ts
  • apps/web/src/config/config.ts
  • apps/web/src/entities/private-api/drafts.ts
  • apps/web/src/features/i18n/locales/en-US.json
  • apps/web/src/features/shared/drafts/drafts-list.tsx
  • apps/web/src/features/shared/post-templates/index.tsx
  • apps/web/src/features/shared/post-templates/post-templates-list-item.tsx
  • apps/web/src/features/shared/post-templates/post-templates-list.tsx
  • apps/web/src/specs/utils/text-similarity.spec.ts
  • apps/web/src/utils/text-similarity.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/post-templates

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:03efe0b3cc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const allDrafts = useMemo(
() => data?.pages.flatMap((page) => page.data) ?? [],
() =>
(data?.pages.flatMap((page) => page.data) ?? []).filter((d) => !d.meta?.postTemplate),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep fetching drafts after filtering templates

When a user's newest page of drafts is made up entirely of saved templates, this filter turns the first limit=10 page into an empty allDrafts array; the component then takes the existing allDrafts.length === 0 empty-state return and never renders the Load More button. In that scenario, older non-template drafts still exist on later pages but become inaccessible from the drafts dialog, so the drafts list needs the same kind of chain-fetch/empty-with-next-page handling used by the templates list.

Useful? React with 👍 / 👎.

@greptile-apps

greptile-appsBot commented Jul 6, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds a reusable post-templates feature to the publish flow, storing templates as private-api drafts with meta.postTemplate: true so no backend changes are required. Apply, save, delete, and a similarity warning on the validate step are all included.

  • Template storage & filtering: Templates piggyback on the existing drafts pagination. Both DraftsList and PostTemplatesList now filter by meta.postTemplate and apply a 5-page auto-fetch budget to avoid unbounded waterfalls when draft pages consist entirely of templates.
  • Apply flow: useApplyTemplate calls clearAll() then re-hydrates all publish-state fields (title, body, tags, reward, beneficiaries, poll, thumbnail, location) and updates the TipTap editor imperatively; appliedTemplateBody is stored in publish state so the validate step can compute a Sørensen-Dice similarity warning.
  • Delete safety: PostTemplatesListItem uses the SDK-level useDeleteDraft which performs optimistic cache removal and post-success draftsInfinite invalidation — the empty app-level callback is safe.

Confidence Score: 5/5

Safe to merge — the template feature is self-contained, feature-flagged, and the core delete/save/apply flows all correctly manage cache invalidation.

All core flows (save, apply, delete, similarity warning, draft-list filtering) are correctly implemented and previously-flagged issues were addressed. The only remaining items are a missing 'no results' message when the name filter returns zero matches and a trivially incorrect sort comparator that never returns 0 — neither affects data integrity or user sessions.

apps/web/src/features/shared/post-templates/post-templates-list.tsx — the filter empty-state gap and sort comparator.

Important Files Changed

FilenameOverview
apps/web/src/features/shared/post-templates/post-templates-list.tsxNew component for displaying/filtering templates. Auto-fetch bounded to 5 pages; 'Load More' button is visible. Two minor issues: sort comparator never returns 0 for equal timestamps, and there is no empty-state message when the name filter returns zero matches from a non-empty template set.
apps/web/src/app/publish/_api/use-save-template.tsNew mutation that saves current publish state as a draft with postTemplate: true in meta. Previously-flagged tagJ null-safety issue was fixed (?? ""); title! and content! remain non-null asserted but at runtime both resolve to at least "" (from clearAll's defaults), so no crash.
apps/web/src/app/publish/_hooks/use-apply-template.tsNew hook that hydrates publish state from a Draft. Correctly calls clearAll() first (which also resets appliedTemplateBody), then restores all fields. React batches the state updates so the final render sees only the template's values.
apps/web/src/features/shared/post-templates/post-templates-list-item.tsxIndividual template card. Uses useDeleteDraft(() => {}) with empty callback — safe because the SDK's mutation performs optimistic cache removal and post-success invalidation of both drafts and draftsInfinite query keys internally.
apps/web/src/features/shared/post-templates/index.tsxNew dialog shell with list/save mode toggle. Correctly resets mode and name when show becomes false so a dismissed save form doesn't reappear.
apps/web/src/features/shared/drafts/drafts-list.tsxFilters out postTemplate drafts from the list and adds a bounded (5-page) auto-fetch waterfall to skip template-only pages, addressing the previously-flagged unbounded chain-fetch concern.
apps/web/src/app/publish/_components/publish-validate-post.tsxAdds template-similarity warning using Sorensen-Dice coefficient; warning is advisory only and does not block publishing.
apps/web/src/utils/text-similarity.tsNew wordOverlapSimilarity utility implementing Sorensen-Dice over word multisets with unicode tokenization. Well-tested and correctly handles empty inputs.
apps/web/src/app/publish/_hooks/use-publish-state.tsxAdds appliedTemplateBody field to publish state context. clearAll properly resets it to null, preventing stale template-similarity warnings after publish or manual clear.
apps/web/src/app/publish/_components/publish-action-bar.tsxAdds 'Templates' dropdown entry gated behind the postTemplates feature flag and LoginRequired. Template hooks are called unconditionally (correct React rules) and their results only used inside feature-flag conditional blocks.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
actor User
participant ActionBar as PublishActionBar
participant Dialog as PostTemplatesDialog
participant List as PostTemplatesList
participant SaveAPI as useSaveTemplateApi
participant ApplyHook as useApplyTemplate
participant State as PublishState
participant SDK as @ecency/sdk
User->>ActionBar: Click "Templates"
ActionBar->>Dialog: "show=true"
Dialog->>List: "render (mode=list)"
List->>SDK: "getDraftsInfiniteQueryOptions (chain-fetch <= 5 pages)"
SDK-->>List: pages filtered to postTemplate:true
alt Save current as template
User->>Dialog: click Save as template
Dialog->>Dialog: setMode(save)
User->>Dialog: enter name, submit
Dialog->>SaveAPI: onSaveCurrent(name)
SaveAPI->>SDK: addDraft(token, title, body, tags, meta)
SDK-->>SaveAPI: resp.drafts
SaveAPI->>SDK: invalidateQueries(draftsInfinite)
end
alt Apply template
User->>List: click Apply
List->>ApplyHook: onApply(draft)
ApplyHook->>State: clearAll()
ApplyHook->>State: setTitle/setContent/setTags/setBeneficiaries
ApplyHook->>State: setAppliedTemplateBody(draft.body)
ApplyHook->>ActionBar: setEditorContent(draft.body)
Dialog->>Dialog: setShow(false)
end
alt Delete template
User->>List: click trash icon, confirm
List->>SDK: useDeleteDraft (optimistic remove)
SDK-->>SDK: invalidate drafts + draftsInfinite
end
User->>ActionBar: click Publish
ActionBar->>State: wordOverlapSimilarity(content, appliedTemplateBody)
State-->>ActionBar: "similarity >= 0.9, show warning"
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
actor User
participant ActionBar as PublishActionBar
participant Dialog as PostTemplatesDialog
participant List as PostTemplatesList
participant SaveAPI as useSaveTemplateApi
participant ApplyHook as useApplyTemplate
participant State as PublishState
participant SDK as @ecency/sdk
User->>ActionBar: Click "Templates"
ActionBar->>Dialog: "show=true"
Dialog->>List: "render (mode=list)"
List->>SDK: "getDraftsInfiniteQueryOptions (chain-fetch <= 5 pages)"
SDK-->>List: pages filtered to postTemplate:true
alt Save current as template
User->>Dialog: click Save as template
Dialog->>Dialog: setMode(save)
User->>Dialog: enter name, submit
Dialog->>SaveAPI: onSaveCurrent(name)
SaveAPI->>SDK: addDraft(token, title, body, tags, meta)
SDK-->>SaveAPI: resp.drafts
SaveAPI->>SDK: invalidateQueries(draftsInfinite)
end
alt Apply template
User->>List: click Apply
List->>ApplyHook: onApply(draft)
ApplyHook->>State: clearAll()
ApplyHook->>State: setTitle/setContent/setTags/setBeneficiaries
ApplyHook->>State: setAppliedTemplateBody(draft.body)
ApplyHook->>ActionBar: setEditorContent(draft.body)
Dialog->>Dialog: setShow(false)
end
alt Delete template
User->>List: click trash icon, confirm
List->>SDK: useDeleteDraft (optimistic remove)
SDK-->>SDK: invalidate drafts + draftsInfinite
end
User->>ActionBar: click Publish
ActionBar->>State: wordOverlapSimilarity(content, appliedTemplateBody)
State-->>ActionBar: "similarity >= 0.9, show warning"
Loading

Reviews (5): Last reviewed commit: "fix(publish): bound the template-skippin..." | Re-trigger Greptile

Comment threadapps/web/src/features/shared/post-templates/post-templates-list.tsx Outdated
Comment threadapps/web/src/app/publish/_api/use-save-template.ts Outdated
Comment threadapps/web/src/features/shared/drafts/drafts-list.tsx Outdated
@feruzm
feruzm merged commit 18407db into developJul 6, 2026
7 checks passed
@feruzm
feruzm deleted the feature/post-templates branch July 6, 2026 16:40
Sign up for freeto 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

@feruzm