2025-04-15 16:28:03 +05:30
|
|
|
import React from 'react';
|
|
|
|
|
import { Link } from 'react-router-dom';
|
2025-07-30 13:22:06 +05:30
|
|
|
import { useForum } from '@/contexts/useForum';
|
2025-04-24 17:35:31 +05:30
|
|
|
import { Layout, MessageSquare, RefreshCw, Loader2 } from 'lucide-react';
|
2025-04-15 16:28:03 +05:30
|
|
|
import { CreateCellDialog } from './CreateCellDialog';
|
2025-04-22 10:39:32 +05:30
|
|
|
import { Button } from '@/components/ui/button';
|
2025-04-22 11:05:49 +05:30
|
|
|
import { CypherImage } from './ui/CypherImage';
|
2025-04-15 16:28:03 +05:30
|
|
|
|
|
|
|
|
const CellList = () => {
|
2025-04-22 10:39:32 +05:30
|
|
|
const { cells, isInitialLoading, posts, refreshData, isRefreshing } = useForum();
|
2025-04-15 16:28:03 +05:30
|
|
|
|
2025-04-22 10:39:32 +05:30
|
|
|
if (isInitialLoading) {
|
2025-04-15 16:28:03 +05:30
|
|
|
return (
|
2025-04-24 17:35:31 +05:30
|
|
|
<div className="container mx-auto px-4 py-16 text-center">
|
|
|
|
|
<Loader2 className="w-8 h-8 mx-auto mb-4 animate-spin text-primary" />
|
|
|
|
|
<p className="text-lg font-medium text-muted-foreground">Loading Cells...</p>
|
|
|
|
|
<p className="text-sm text-muted-foreground/70 mt-1">Connecting to the network and fetching data...</p>
|
2025-04-15 16:28:03 +05:30
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getPostCount = (cellId: string) => {
|
|
|
|
|
return posts.filter(post => post.cellId === cellId).length;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="container mx-auto px-4 py-8 max-w-4xl">
|
|
|
|
|
<div className="flex items-center justify-between mb-6">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<Layout className="text-cyber-accent w-6 h-6" />
|
|
|
|
|
<h1 className="text-2xl font-bold text-glow">Cells</h1>
|
|
|
|
|
</div>
|
2025-04-22 10:39:32 +05:30
|
|
|
<div className="flex gap-2">
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="icon"
|
|
|
|
|
onClick={refreshData}
|
|
|
|
|
disabled={isRefreshing}
|
|
|
|
|
title="Refresh data"
|
|
|
|
|
>
|
|
|
|
|
<RefreshCw className={`w-4 h-4 ${isRefreshing ? 'animate-spin' : ''}`} />
|
|
|
|
|
</Button>
|
|
|
|
|
<CreateCellDialog />
|
|
|
|
|
</div>
|
2025-04-15 16:28:03 +05:30
|
|
|
</div>
|
|
|
|
|
|
2025-04-24 17:35:31 +05:30
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
2025-04-22 10:39:32 +05:30
|
|
|
{cells.length === 0 ? (
|
|
|
|
|
<div className="col-span-2 text-center py-12">
|
|
|
|
|
<div className="text-cyber-neutral mb-4">
|
|
|
|
|
No cells found. Be the first to create one!
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
cells.map((cell) => (
|
|
|
|
|
<Link to={`/cell/${cell.id}`} key={cell.id} className="board-card group">
|
|
|
|
|
<div className="flex gap-4 items-start">
|
2025-04-22 11:05:49 +05:30
|
|
|
<CypherImage
|
2025-04-22 10:39:32 +05:30
|
|
|
src={cell.icon}
|
|
|
|
|
alt={cell.name}
|
|
|
|
|
className="w-16 h-16 object-cover rounded-sm border border-cyber-muted group-hover:border-cyber-accent transition-colors"
|
2025-04-22 11:05:49 +05:30
|
|
|
generateUniqueFallback={true}
|
2025-04-22 10:39:32 +05:30
|
|
|
/>
|
|
|
|
|
<div className="flex-1">
|
|
|
|
|
<h2 className="text-xl font-bold mb-1 group-hover:text-cyber-accent transition-colors">{cell.name}</h2>
|
|
|
|
|
<p className="text-sm text-cyber-neutral mb-2">{cell.description}</p>
|
|
|
|
|
<div className="flex items-center text-xs text-cyber-neutral">
|
|
|
|
|
<MessageSquare className="w-3 h-3 mr-1" />
|
|
|
|
|
<span>{getPostCount(cell.id)} threads</span>
|
|
|
|
|
</div>
|
2025-04-15 16:28:03 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-04-22 10:39:32 +05:30
|
|
|
</Link>
|
|
|
|
|
))
|
|
|
|
|
)}
|
2025-04-15 16:28:03 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default CellList;
|