2025-08-30 18:34:50 +05:30
|
|
|
import { useState, useMemo } from 'react';
|
2025-04-15 16:28:03 +05:30
|
|
|
import { Link } from 'react-router-dom';
|
2025-07-30 13:22:06 +05:30
|
|
|
import { useForum } from '@/contexts/useForum';
|
2025-08-30 18:34:50 +05:30
|
|
|
import {
|
|
|
|
|
Layout,
|
|
|
|
|
MessageSquare,
|
|
|
|
|
RefreshCw,
|
|
|
|
|
Loader2,
|
|
|
|
|
TrendingUp,
|
|
|
|
|
Clock,
|
|
|
|
|
} 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-08-30 18:34:50 +05:30
|
|
|
import {
|
|
|
|
|
Select,
|
|
|
|
|
SelectContent,
|
|
|
|
|
SelectItem,
|
|
|
|
|
SelectTrigger,
|
|
|
|
|
SelectValue,
|
|
|
|
|
} from '@/components/ui/select';
|
2025-04-22 11:05:49 +05:30
|
|
|
import { CypherImage } from './ui/CypherImage';
|
2025-08-11 12:14:19 +05:30
|
|
|
import { RelevanceIndicator } from './ui/relevance-indicator';
|
|
|
|
|
import { sortCells, SortOption } from '@/lib/forum/sorting';
|
2025-04-15 16:28:03 +05:30
|
|
|
|
|
|
|
|
const CellList = () => {
|
2025-08-30 18:34:50 +05:30
|
|
|
const { cells, isInitialLoading, posts, refreshData, isRefreshing } =
|
|
|
|
|
useForum();
|
2025-08-11 12:14:19 +05:30
|
|
|
const [sortOption, setSortOption] = useState<SortOption>('relevance');
|
|
|
|
|
|
|
|
|
|
// Apply sorting to cells
|
|
|
|
|
const sortedCells = useMemo(() => {
|
|
|
|
|
return sortCells(cells, sortOption);
|
|
|
|
|
}, [cells, sortOption]);
|
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-08-13 13:53:47 +05:30
|
|
|
<div className="container mx-auto px-4 pt-24 pb-16 text-center">
|
2025-04-24 17:35:31 +05:30
|
|
|
<Loader2 className="w-8 h-8 mx-auto mb-4 animate-spin text-primary" />
|
2025-08-30 18:34:50 +05:30
|
|
|
<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 (
|
2025-08-13 13:53:47 +05:30
|
|
|
<div className="container mx-auto px-4 pt-24 pb-8 max-w-4xl">
|
2025-04-15 16:28:03 +05:30
|
|
|
<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">
|
2025-08-30 18:34:50 +05:30
|
|
|
<Select
|
|
|
|
|
value={sortOption}
|
|
|
|
|
onValueChange={(value: SortOption) => setSortOption(value)}
|
|
|
|
|
>
|
2025-08-11 12:14:19 +05:30
|
|
|
<SelectTrigger className="w-40">
|
|
|
|
|
<SelectValue />
|
|
|
|
|
</SelectTrigger>
|
2025-08-30 18:34:50 +05:30
|
|
|
<SelectContent>
|
|
|
|
|
<SelectItem value="relevance">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<TrendingUp className="w-4 h-4" />
|
|
|
|
|
<span>Relevance</span>
|
|
|
|
|
</div>
|
|
|
|
|
</SelectItem>
|
|
|
|
|
<SelectItem value="time">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<Clock className="w-4 h-4" />
|
|
|
|
|
<span>Newest</span>
|
|
|
|
|
</div>
|
|
|
|
|
</SelectItem>
|
|
|
|
|
</SelectContent>
|
2025-08-11 12:14:19 +05:30
|
|
|
</Select>
|
2025-08-30 18:34:50 +05:30
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
2025-08-13 13:53:47 +05:30
|
|
|
size="icon"
|
2025-08-30 18:34:50 +05:30
|
|
|
onClick={refreshData}
|
2025-04-22 10:39:32 +05:30
|
|
|
disabled={isRefreshing}
|
|
|
|
|
title="Refresh data"
|
2025-08-13 13:53:47 +05:30
|
|
|
className="px-3"
|
2025-04-22 10:39:32 +05:30
|
|
|
>
|
2025-08-30 18:34:50 +05:30
|
|
|
<RefreshCw
|
|
|
|
|
className={`w-4 h-4 ${isRefreshing ? 'animate-spin' : ''}`}
|
|
|
|
|
/>
|
2025-04-22 10:39:32 +05:30
|
|
|
</Button>
|
|
|
|
|
<CreateCellDialog />
|
|
|
|
|
</div>
|
2025-04-15 16:28:03 +05:30
|
|
|
</div>
|
2025-08-30 18:34:50 +05:30
|
|
|
|
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>
|
|
|
|
|
) : (
|
2025-08-30 18:34:50 +05:30
|
|
|
sortedCells.map(cell => (
|
|
|
|
|
<Link
|
|
|
|
|
to={`/cell/${cell.id}`}
|
|
|
|
|
key={cell.id}
|
|
|
|
|
className="board-card group"
|
|
|
|
|
>
|
2025-04-22 10:39:32 +05:30
|
|
|
<div className="flex gap-4 items-start">
|
2025-08-30 18:34:50 +05:30
|
|
|
<CypherImage
|
|
|
|
|
src={cell.icon}
|
|
|
|
|
alt={cell.name}
|
2025-04-22 10:39:32 +05:30
|
|
|
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">
|
2025-08-30 18:34:50 +05:30
|
|
|
<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>
|
2025-08-11 12:14:19 +05:30
|
|
|
<div className="flex items-center text-xs text-cyber-neutral gap-2">
|
|
|
|
|
<div className="flex items-center">
|
|
|
|
|
<MessageSquare className="w-3 h-3 mr-1" />
|
|
|
|
|
<span>{getPostCount(cell.id)} threads</span>
|
|
|
|
|
</div>
|
|
|
|
|
{cell.relevanceScore !== undefined && (
|
2025-08-30 18:34:50 +05:30
|
|
|
<RelevanceIndicator
|
|
|
|
|
score={cell.relevanceScore}
|
2025-08-11 12:14:19 +05:30
|
|
|
details={cell.relevanceDetails}
|
|
|
|
|
type="cell"
|
|
|
|
|
className="text-xs"
|
|
|
|
|
showTooltip={true}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2025-04-22 10:39:32 +05:30
|
|
|
</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;
|