Skip to content

Moved admin hide/show operations to AdminActionsProvider#26298

Draft
rob-ghost wants to merge 3 commits intorefactor/comments-api-providerfrom
refactor/comments-admin-actions
Draft

Moved admin hide/show operations to AdminActionsProvider#26298
rob-ghost wants to merge 3 commits intorefactor/comments-api-providerfrom
refactor/comments-admin-actions

Conversation

@rob-ghost
Copy link
Copy Markdown
Contributor

Building on the CommentApiProvider refactoring, this PR extracts the admin-only hideComment and showComment operations from actions.ts into a dedicated AdminActionsProvider.

The previous implementation had these actions guarding on commentApi.isAdmin at runtime. Since we now have AdminCommentApi as a distinct type from the discriminated union, we can create a provider that only exposes admin actions when the user is actually an admin—no runtime guards needed in the action handlers themselves.

The new AdminActionsProvider always renders (for tree stability, avoiding iframe remounts from conditional wrapping) but passes undefined context when the user isn't an admin. The useAdminActions() hook throws if called outside an admin context, enforcing correct usage at the type level. The AdminContextMenu component now calls useAdminActions() directly instead of going through dispatchAction.

This follows the pattern of pushing the admin/member decision higher up the component tree, keeping action logic simple and type-safe.

…om actions

Every hybrid action (loadMoreComments, setOrder, loadMoreReplies, showComment) had inline
`if (state.admin && state.adminApi)` branching. This commit creates a polymorphic CommentApi
interface that encapsulates the admin/member decision, removing all conditionals from actions.

- Created `comment-api-provider.tsx` with discriminated union types (MemberCommentApi | AdminCommentApi)
- `createCommentApi()` factory produces the appropriate facade based on admin status
- Updated all actions to use `commentApi` parameter instead of branching on state
- App.tsx creates `commentApi` at dispatch time from existing state.adminApi
- Auth flow unchanged — state.admin/adminApi/isAdmin remain in EditableAppContext for now
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 9, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/comments-admin-actions

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 and usage tips.

@rob-ghost rob-ghost force-pushed the refactor/comments-api-provider branch from 52ad254 to 0d37b80 Compare February 9, 2026 13:01
@rob-ghost rob-ghost force-pushed the refactor/comments-admin-actions branch from b8b609f to ae7e3af Compare February 9, 2026 13:03
@rob-ghost rob-ghost force-pushed the refactor/comments-api-provider branch from 0d37b80 to 05e5010 Compare February 9, 2026 13:37
@rob-ghost rob-ghost force-pushed the refactor/comments-admin-actions branch from ae7e3af to 376a143 Compare February 9, 2026 13:40
@rob-ghost rob-ghost force-pushed the refactor/comments-api-provider branch 3 times, most recently from 08b0184 to 8c6c8d8 Compare February 9, 2026 16:12
@rob-ghost rob-ghost force-pushed the refactor/comments-admin-actions branch from 376a143 to ae09ef0 Compare February 10, 2026 11:34
@rob-ghost rob-ghost force-pushed the refactor/comments-api-provider branch from 8c6c8d8 to c711065 Compare February 10, 2026 11:52
@rob-ghost rob-ghost force-pushed the refactor/comments-admin-actions branch from ae09ef0 to ed3ddfa Compare February 10, 2026 11:56
@rob-ghost rob-ghost force-pushed the refactor/comments-api-provider branch from c711065 to 8f7f27d Compare February 10, 2026 13:51
@rob-ghost rob-ghost force-pushed the refactor/comments-admin-actions branch from ed3ddfa to 1c3248c Compare February 10, 2026 13:51
@rob-ghost rob-ghost force-pushed the refactor/comments-api-provider branch from 8f7f27d to 80a3b98 Compare February 10, 2026 14:56
@rob-ghost rob-ghost force-pushed the refactor/comments-admin-actions branch from 1c3248c to 9fce3c4 Compare February 10, 2026 15:33
The first commit introduced the CommentApi facade but still created it inline
at dispatch time from state.adminApi. This commit lifts facade creation and
admin auth into a dedicated provider, removing admin state from the app context.

- Added CommentApiProvider component that manages admin auth initialization
- Exposed initAdminAuth, setMember, and adminComments through provider context
- Split app.tsx into App (wraps provider) and AppContent (uses useCommentApi)
- Removed admin, adminApi from EditableAppContext (now managed by provider)
- Added smart adminComments sync that preserves paginated/expanded permalink data
- Replaced createRef with useRef for consistency
@rob-ghost rob-ghost force-pushed the refactor/comments-api-provider branch from 80a3b98 to 0ad9236 Compare February 11, 2026 20:21
The CommentApi facade introduced a discriminated union (MemberCommentApi | AdminCommentApi),
but hideComment/showComment in actions.ts still guarded on commentApi.isAdmin at runtime.
This commit leverages the type system by extracting admin operations into a dedicated provider.

- Created AdminActionsProvider that only exposes actions when admin is authenticated
- useAdminActions() hook throws if called outside admin context (enforces correct usage)
- Removed hideComment/showComment from actions.ts (no more runtime isAdmin checks)
- AdminContextMenu now calls useAdminActions() directly instead of dispatchAction
@rob-ghost rob-ghost force-pushed the refactor/comments-admin-actions branch from 9fce3c4 to 346b586 Compare February 11, 2026 20:21
@rob-ghost rob-ghost force-pushed the refactor/comments-api-provider branch from 0ad9236 to 64c53fc Compare March 12, 2026 13:52
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