import React, { useState } from 'react'; import { Link, useParams } from 'react-router-dom'; import { useForum } from '@/contexts/useForum'; import { useAuth } from '@/contexts/useAuth'; 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 }>(); const { getCellById, getPostsByCell, createPost, isInitialLoading, isPostingPost, isRefreshing, refreshData, votePost, isVoting, posts, moderatePost, moderateUser, userVerificationStatus, } = useForum(); const { isAuthenticated, currentUser, verificationStatus } = useAuth(); const [newPostTitle, setNewPostTitle] = useState(''); const [newPostContent, setNewPostContent] = useState(''); if (!cellId || isInitialLoading) { return (
Back to Cells
{[...Array(3)].map((_, i) => (
))}
); } const cell = getCellById(cellId); const cellPosts = getPostsByCell(cellId); 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; try { const post = await createPost(cellId, newPostTitle, newPostContent); if (post) { setNewPostTitle(''); setNewPostContent(''); } } catch (error) { console.error('Error creating post:', error); } }; const handleVotePost = async (postId: string, isUpvote: boolean) => { if (!isAuthenticated) return; await votePost(postId, isUpvote); }; const isPostVoted = (postId: string, isUpvote: boolean) => { if (!currentUser) return false; const post = posts.find(p => p.id === postId); if (!post) return false; const votes = isUpvote ? post.upvotes : post.downvotes; return votes.some(vote => vote.author === currentUser.address); }; // Only show unmoderated posts, or all if admin const isCellAdmin = currentUser && cell && currentUser.address === cell.signature; const visiblePosts = isCellAdmin ? cellPosts : cellPosts.filter(post => !post.moderated); const handleModerate = async (postId: string) => { const reason = window.prompt('Enter a reason for moderation (optional):') || undefined; if (!cell) return; await moderatePost(cell.id, postId, reason, cell.signature); }; const handleModerateUser = async (userAddress: string) => { const reason = window.prompt('Reason for moderating this user? (optional)') || undefined; if (!cell) return; await moderateUser(cell.id, userAddress, reason, cell.signature); }; return (
Back to Cells

{cell.name}

{cell.description}

{verificationStatus === 'verified-owner' && (

New Thread

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