-
Notifications
You must be signed in to change notification settings - Fork 20
Add follow controls to directory fidget #1563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add follow controls to directory fidget #1563
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThis change adds Farcaster viewer context hydration to the token directory, enabling follow relationship tracking between viewers and directory members. It introduces viewerFid and signer propagation through components, defines new viewer context types, extends API query parameters, and implements a new DirectoryFollowButton component for managing follow actions. Changes
Sequence DiagramsequenceDiagram
participant User
participant Directory as Directory Component
participant FollowBtn as DirectoryFollowButton
participant API as Farcaster/Neynar API
participant Store as Global Store
User->>Directory: Load directory with viewerFid
Directory->>Directory: Hydrate viewerContext for members<br/>(batch request)
Directory->>FollowBtn: Pass member, viewerFid, signer
User->>FollowBtn: Click follow/unfollow button
FollowBtn->>Store: Check account readiness
alt Account ready & valid props
FollowBtn->>FollowBtn: Optimistic state update
FollowBtn->>API: Call followUser or unfollowUser
alt API success
API-->>FollowBtn: Success
FollowBtn->>FollowBtn: Set idle state
else API error
API-->>FollowBtn: Error
FollowBtn->>FollowBtn: Revert optimistic change<br/>Set error state
FollowBtn->>FollowBtn: Return to idle after delay
end
else Missing validation
FollowBtn->>FollowBtn: Persist error state
end
FollowBtn-->>User: Update button label & style
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/fidgets/token/Directory/types.ts (1)
16-18: Viewer context type wiring is consistent with usageThe
DirectoryMemberViewerContextshape and the optionalviewerContextfield onDirectoryMemberDatamatch how you consume it elsewhere (viewerContext?.followingand explicitnullwhen cleared). If you rely on the distinction betweenundefinedandnull(unknown vs “no relationship”), consider capturing that in a brief type-level comment, but the current design is sound.Also applies to: 38-39
src/pages/api/token/directory.ts (1)
85-88: Consider de‑duplicatingextractViewerContextlogic
DirectoryMemberViewerContextandextractViewerContexthere closely mirror the versions insrc/fidgets/token/Directory/utils/memberData.ts. Even though the Neynar user types differ between API and fidget layers, the viewer_context shape is effectively the same.If layering allows it, consider centralizing this logic (e.g., a small shared helper in a common Farcaster/Neynar utils module) to avoid future drift if Neynar’s
viewer_contextcontract changes.Also applies to: 734-748
src/fidgets/token/Directory/components/DirectoryFollowButton.tsx (1)
1-12: Follow button logic is robust; consider surfacing error stateThe button correctly:
- Hides itself for invalid
memberFid/self‑profile.- Opens the account modal if the Farcaster account isn’t ready.
- Guards against missing signer or invalid
viewerFid.- Performs an optimistic follow/unfollow toggle and reverts on failure.
Currently, the
"error"status doesn’t change the UI (label and styling are the same as"idle"). If you want to signal failures, you could optionally tweak the label or style whenstatus === "error", or else simplify by dropping the"error"state entirely.Also applies to: 20-37, 38-41, 46-81, 83-105
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
src/fidgets/token/Directory/Directory.tsx(18 hunks)src/fidgets/token/Directory/components/DirectoryCardView.tsx(5 hunks)src/fidgets/token/Directory/components/DirectoryFollowButton.tsx(1 hunks)src/fidgets/token/Directory/components/DirectoryListView.tsx(5 hunks)src/fidgets/token/Directory/types.ts(2 hunks)src/fidgets/token/Directory/utils.ts(1 hunks)src/fidgets/token/Directory/utils/memberData.ts(6 hunks)src/pages/api/token/directory.ts(10 hunks)
🧰 Additional context used
🧬 Code graph analysis (6)
src/fidgets/token/Directory/components/DirectoryCardView.tsx (1)
src/fidgets/token/Directory/components/DirectoryFollowButton.tsx (2)
DirectoryFollowButtonProps(7-12)DirectoryFollowButton(14-105)
src/pages/api/token/directory.ts (3)
src/fidgets/token/Directory/types.ts (1)
DirectoryMemberViewerContext(16-18)src/fidgets/token/Directory/utils/memberData.ts (2)
extractViewerContext(25-40)NeynarUser(14-23)src/common/data/api/token/types.ts (1)
NeynarUser(53-57)
src/fidgets/token/Directory/components/DirectoryFollowButton.tsx (2)
src/fidgets/token/Directory/types.ts (1)
DirectoryMemberData(20-39)src/fidgets/farcaster/utils.ts (2)
followUser(108-126)unfollowUser(128-146)
src/fidgets/token/Directory/components/DirectoryListView.tsx (1)
src/fidgets/token/Directory/components/DirectoryFollowButton.tsx (2)
DirectoryFollowButtonProps(7-12)DirectoryFollowButton(14-105)
src/fidgets/token/Directory/Directory.tsx (4)
src/fidgets/farcaster/index.tsx (1)
useFarcasterSigner(59-105)src/fidgets/token/Directory/types.ts (3)
DirectoryFidgetData(41-47)DirectoryMemberData(20-39)DirectoryMemberViewerContext(16-18)src/fidgets/token/Directory/utils/csv.ts (1)
chunkArray(85-89)src/fidgets/token/Directory/utils/memberData.ts (2)
getNestedUser(46-53)extractViewerContext(25-40)
src/fidgets/token/Directory/utils/memberData.ts (2)
src/common/data/api/token/types.ts (1)
NeynarUser(53-57)src/fidgets/token/Directory/types.ts (1)
DirectoryMemberViewerContext(16-18)
🔇 Additional comments (6)
src/fidgets/token/Directory/utils.ts (1)
152-160: Re‑export ofextractViewerContextlooks correctThe new re‑export aligns this module with
utils/memberData.tsand keeps viewer context extraction centralized and reusable. No changes needed.src/fidgets/token/Directory/components/DirectoryCardView.tsx (1)
8-13: Card view follow button integration is coherentNew props (
viewerFid,signer) and theDirectoryFollowButtonoverlay are wired correctly and respect the existing card link behavior (viastopPropagationin the button and the pointer-events container). This looks good.Also applies to: 25-28, 30-40, 70-71, 154-161
src/pages/api/token/directory.ts (1)
21-30: API viewer context support is correctly threadedThe API now:
- Accepts an optional, validated
viewerFidinDIRECTORY_QUERY_SCHEMA.- Passes it through to Neynar bulk calls.
- Extracts
viewerContextper profile and attaches it to both per‑fid aggregates and per‑address members.The guards around
viewerFidand the aggregation logic look consistent with the front‑end expectations (viewerContext?.following), and they shouldn’t affect behavior whenviewerFidis omitted.Also applies to: 85-88, 89-108, 773-787, 815-833, 873-874, 997-1043, 1048-1081
src/fidgets/token/Directory/components/DirectoryListView.tsx (1)
8-13: List view follow controls and layout update look solidThe additional props (
viewerFid,signer) and the new right‑side layout (follow button plus the metrics column) are wired correctly, preserve previous conditional rendering for balances/followers/last activity, and delegate follow logic cleanly toDirectoryFollowButton.Also applies to: 25-28, 30-38, 123-144
src/fidgets/token/Directory/utils/memberData.ts (1)
6-9: Viewer context mapping for Neynar users and CSV defaults is consistentExtending
NeynarUserwithviewer_context, addingextractViewerContext, wiring it intomapNeynarUserToMember, and initializing CSV members withviewerContext: nullgives a clean, predictable contract for downstream components (DirectoryFollowButtonand hydration logic). This matches the API behavior and looks correct.Also applies to: 14-23, 25-40, 58-81, 87-113, 114-136, 138-158
src/fidgets/token/Directory/Directory.tsx (1)
29-39: Viewer context lifecycle and wiring are well designedThis module now cleanly owns the viewer‑specific concerns:
- Obtains
viewerFid/signerviauseFarcasterSigner.- Clears all member
viewerContextwhen there is no valid viewer.- Lazily hydrates
viewerContextfor only the members that need it, with chunking and abort handling.- Uses
lastViewerContextFidandstripViewerContextto ensure persistedDirectoryFidgetDataremains viewer‑agnostic while still triggering refreshes when the viewer changes.- Plumbs
viewerFidthrough all relevant fetch paths and into the list/card views, matching the new API contracts.The flow looks coherent and avoids obvious stale‑state pitfalls.
Also applies to: 45-59, 77-79, 163-173, 208-235, 270-379, 381-441, 443-473, 475-518, 520-588, 645-649, 677-680, 701-705, 840-847, 898-915, 1056-1065, 1067-1077
Summary
Testing
Codex Task
Summary by CodeRabbit