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