import React, { useState } from 'react'; import { Link, useParams } from 'react-router-dom'; import { useForum } from '@/contexts/ForumContext'; import { useAuth } from '@/contexts/AuthContext'; 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, Clock, RefreshCw } from 'lucide-react'; import { formatDistanceToNow } from 'date-fns'; import { CypherImage } from './ui/CypherImage'; const PostList = () => { const { cellId } = useParams<{ cellId: string }>(); const { getCellById, getPostsByCell, getCommentsByPost, createPost, isInitialLoading, isPostingPost, isRefreshing, refreshData } = useForum(); const { isAuthenticated } = 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 posts = 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); } }; return (
Back to Cells

{cell.name}

{cell.description}

{isAuthenticated && (

New Thread

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