Spaces:
Build error
Build error
Create src/components/grabber/PostGrid.tsx
#7
by launch-calcium - opened
src/components/grabber/PostGrid.tsx
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Checkbox } from '@/components/ui/checkbox';
|
| 2 |
+
import { Badge } from '@/components/ui/badge';
|
| 3 |
+
import { Lightbox } from './Lightbox';
|
| 4 |
+
|
| 5 |
+
export function PostGrid({ posts, onSelect }: { posts: any[], onSelect: (ids: string[]) => void }) {
|
| 6 |
+
const selected = new Set();
|
| 7 |
+
const toggle = (id: string) => {
|
| 8 |
+
selected.has(id) ? selected.delete(id) : selected.add(id);
|
| 9 |
+
onSelect(Array.from(selected));
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
return (
|
| 13 |
+
<div className="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-5 gap-4 p-4">
|
| 14 |
+
{posts.map((post) => (
|
| 15 |
+
<PostCard key={post.id} post={post} selected={selected.has(post.id)} onToggle={() => toggle(post.id)} />
|
| 16 |
+
))}
|
| 17 |
+
</div>
|
| 18 |
+
);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
export function PostCard({ post, selected, onToggle }: any) {
|
| 22 |
+
return (
|
| 23 |
+
<div className="relative border rounded overflow-hidden group">
|
| 24 |
+
<Checkbox checked={selected} onCheckedChange={() => onToggle()} className="absolute top-2 left-2 z-10" />
|
| 25 |
+
<img src={post.previewUrl} alt="" className="w-full aspect-square object-cover" />
|
| 26 |
+
<div className="p-2 flex justify-between items-center">
|
| 27 |
+
<Badge variant="outline">{post.rating}</Badge>
|
| 28 |
+
<span className="text-xs font-bold">{post.score}</span>
|
| 29 |
+
</div>
|
| 30 |
+
</div>
|
| 31 |
+
);
|
| 32 |
+
}
|