Moved admin hide/show operations to AdminActionsProvider#26298
Draft
rob-ghost wants to merge 3 commits intorefactor/comments-api-providerfrom
Draft
Moved admin hide/show operations to AdminActionsProvider#26298rob-ghost wants to merge 3 commits intorefactor/comments-api-providerfrom
rob-ghost wants to merge 3 commits intorefactor/comments-api-providerfrom
Conversation
…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
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ 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 |
52ad254 to
0d37b80
Compare
b8b609f to
ae7e3af
Compare
0d37b80 to
05e5010
Compare
ae7e3af to
376a143
Compare
08b0184 to
8c6c8d8
Compare
376a143 to
ae09ef0
Compare
8c6c8d8 to
c711065
Compare
ae09ef0 to
ed3ddfa
Compare
c711065 to
8f7f27d
Compare
ed3ddfa to
1c3248c
Compare
8f7f27d to
80a3b98
Compare
1c3248c to
9fce3c4
Compare
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
80a3b98 to
0ad9236
Compare
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
9fce3c4 to
346b586
Compare
0ad9236 to
64c53fc
Compare
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.
Building on the CommentApiProvider refactoring, this PR extracts the admin-only
hideCommentandshowCommentoperations fromactions.tsinto a dedicatedAdminActionsProvider.The previous implementation had these actions guarding on
commentApi.isAdminat runtime. Since we now haveAdminCommentApias 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
AdminActionsProvideralways renders (for tree stability, avoiding iframe remounts from conditional wrapping) but passesundefinedcontext when the user isn't an admin. TheuseAdminActions()hook throws if called outside an admin context, enforcing correct usage at the type level. TheAdminContextMenucomponent now callsuseAdminActions()directly instead of going throughdispatchAction.This follows the pattern of pushing the admin/member decision higher up the component tree, keeping action logic simple and type-safe.