import React, { useState } from 'react'; import { Link, useParams } from 'react-router-dom'; import { useCell, useCellPosts, useForumActions, usePermissions, useUserVotes, useAuth, } from '@/hooks'; import { EVerificationStatus } from '@/types/identity'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Textarea } from '@/components/ui/textarea'; import { Skeleton } from '@/components/ui/skeleton'; import { ArrowLeft, MessageSquare, MessageCircle, ArrowUp, ArrowDown, RefreshCw, Eye, } from 'lucide-react'; import { formatDistanceToNow } from 'date-fns'; import { CypherImage } from './ui/CypherImage'; import { Badge } from '@/components/ui/badge'; import { AuthorDisplay } from './ui/author-display'; const PostList = () => { const { cellId } = useParams<{ cellId: string }>(); // ✅ Use reactive hooks for data and actions const cell = useCell(cellId); const cellPosts = useCellPosts(cellId, { sortBy: 'relevance' }); const { createPost, votePost, moderatePost, moderateUser, refreshData, isCreatingPost, isVoting, } = useForumActions(); const { canPost, canVote, canModerate } = usePermissions(); const userVotes = useUserVotes(); const { currentUser, verificationStatus } = useAuth(); const [newPostTitle, setNewPostTitle] = useState(''); const [newPostContent, setNewPostContent] = useState(''); if (!cellId || cellPosts.isLoading) { return (
Back to Cells
{[...Array(3)].map((_, i) => (
))}
); } if (!cell) { return (
Back to Cells

Cell Not Found

The cell you're looking for doesn't exist.

); } const handleCreatePost = async (e: React.FormEvent) => { e.preventDefault(); if (!newPostContent.trim()) return; // ✅ All validation handled in hook const post = await createPost(cellId, newPostTitle, newPostContent); if (post) { setNewPostTitle(''); setNewPostContent(''); } }; const handleVotePost = async (postId: string, isUpvote: boolean) => { // ✅ Permission checking handled in hook await votePost(postId, isUpvote); }; const getPostVoteType = (postId: string) => { return userVotes.getPostVoteType(postId); }; // ✅ Posts already filtered by hook based on user permissions const visiblePosts = cellPosts.posts; const handleModerate = async (postId: string) => { const reason = window.prompt('Enter a reason for moderation (optional):') || undefined; if (!cell) return; // ✅ All validation handled in hook await moderatePost(cell.id, postId, reason); }; const handleModerateUser = async (userAddress: string) => { const reason = window.prompt('Reason for moderating this user? (optional)') || undefined; if (!cell) return; // ✅ All validation handled in hook await moderateUser(cell.id, userAddress, reason); }; return (
Back to Cells

{cell.name}

{cell.description}

{canPost && (

New Thread

setNewPostTitle(e.target.value)} className="mb-3 bg-cyber-muted/50 border-cyber-muted" disabled={isCreatingPost} />