import { useForumData, useAuth, useUserDisplay, useUserVotes, useForumActions, useUserActions, useAuthActions, usePermissions, useNetworkStatus, useForumSelectors, } from '@/hooks'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Separator } from '@/components/ui/separator'; /** * Demonstration component showing how to use the new reactive hooks * This replaces direct context usage and business logic in components */ export function HookDemoComponent() { // Core data hooks - reactive and optimized const forumData = useForumData(); const auth = useAuth(); const userDisplay = useUserDisplay(auth.currentUser?.address || ''); // Derived hooks for specific data const userVotes = useUserVotes(); // Action hooks with loading states and error handling const forumActions = useForumActions(); const userActions = useUserActions(); const authActions = useAuthActions(); // Utility hooks for permissions and status const permissions = usePermissions(); const networkStatus = useNetworkStatus(); // Selector hooks for data transformation const selectors = useForumSelectors(forumData); // Example of using selectors const trendingPosts = selectors.selectTrendingPosts(); const stats = selectors.selectStats(); // Example action handlers (no business logic in component!) const handleCreatePost = async () => { const result = await forumActions.createPost( 'example-cell-id', 'Example Post Title', 'This is an example post created using the new hook system!' ); if (result) { console.log('Post created successfully:', result); } }; const handleVotePost = async (postId: string, isUpvote: boolean) => { const success = await forumActions.votePost(postId, isUpvote); if (success) { console.log(`${isUpvote ? 'Upvoted' : 'Downvoted'} post ${postId}`); } }; const handleUpdateCallSign = async () => { const success = await userActions.updateCallSign('NewCallSign'); if (success) { console.log('Call sign updated successfully'); } }; const handleDelegateKey = async () => { const success = await authActions.delegateKey('7days'); if (success) { console.log('Key delegated successfully'); } }; if (forumData.isInitialLoading) { return
Loading forum data...
; } return (

Reactive Hook System Demo

{/* Network Status */} Network Status {networkStatus.getStatusMessage()}
Waku: {networkStatus.connections.waku.status}
Wallet: {networkStatus.connections.wallet.status}
Delegation:{' '} {networkStatus.connections.delegation.status}
{/* Auth Status */} Authentication Status
User: {auth.getDisplayName()} {auth.getVerificationBadge() && ( {auth.getVerificationBadge()} )}
Verification Level:{' '} {auth.verificationStatus.level}
Delegation Active:{' '} {auth.delegationInfo.isActive ? 'Yes' : 'No'}
{userDisplay.badges.length > 0 && (
Badges: {userDisplay.badges.map((badge, index) => ( {badge.icon} {badge.label} ))}
)}
{/* Permissions */} User Permissions
Can Vote: {permissions.canVote ? 'Yes' : 'No'}
Can Post: {permissions.canPost ? 'Yes' : 'No'}
Can Comment: {permissions.canComment ? 'Yes' : 'No'}
Vote Reason: {permissions.voteReason}
Post Reason: {permissions.postReason}
Comment Reason: {permissions.commentReason}
{/* Forum Data Overview */} Forum Statistics
{stats.totalCells}
Cells
{stats.totalPosts}
Posts
{stats.totalComments}
Comments
{stats.verifiedUsers}
Verified Users
{/* Trending Posts */} Trending Posts (via Selectors) {trendingPosts.slice(0, 3).map(post => (

{post.title}

Score: {post.upvotes.length - post.downvotes.length} | Author:{' '} {post.author.slice(0, 8)}... | Cell:{' '} {forumData.cells.find(c => c.id === post.cellId)?.name || 'Unknown'}

))}
{/* User Voting History */} Your Voting Activity
{userVotes.totalVotes}
Total Votes
{Math.round(userVotes.upvoteRatio * 100)}%
Upvote Ratio
{userVotes.votedPosts.size}
Posts Voted
{/* Action States */} Action States
Creating Post: {forumActions.isCreatingPost ? 'Active' : 'Idle'}
Voting: {forumActions.isVoting ? 'Active' : 'Idle'}
Updating Profile: {userActions.isUpdatingProfile ? 'Active' : 'Idle'}
{/* Actions */} Example Actions

Key Benefits Demonstrated:

  • ✅ Zero business logic in this component - all handled by hooks
  • ✅ Reactive updates - data changes automatically trigger re-renders
  • ✅ Centralized permissions - consistent across all components
  • ✅ Optimized selectors - expensive computations are memoized
  • ✅ Loading states and error handling built into actions
  • ✅ Type-safe interfaces for all hook returns
); }