Add post templates to publish flow - #1079
Conversation
|
Warning Review limit reached
Next review available in: 14 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (19)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 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), |
There was a problem hiding this comment.
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 SummaryThis PR adds a reusable post-templates feature to the publish flow, storing templates as private-api drafts with
Confidence Score: 5/5Safe 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
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"
%%{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"
Reviews (5): Last reviewed commit: "fix(publish): bound the template-skippin..." | Re-trigger Greptile |
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
meta.postTemplate: trueandmeta.templateName, so no backend changes are needed. The drafts dialog filters them out of the normal drafts list.Templatesentry in the publish action bar dropdown opens a dialog (list/apply/delete plus a save-as-template form), gated behind a newvisionFeatures.postTemplatesflag and login.Notes
wordOverlapSimilaritywith unit tests; no new type errors vs develop baseline.