Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | 54x 54x 2x 54x 1x 2x 1x 1x | import { memo } from "react";
import { Link } from "@tanstack/react-router";
import {
FileText,
Edit,
Send,
Archive,
ArchiveRestore,
ExternalLink,
Clock,
BookOpen,
Trash2,
} from "lucide-react";
import { MARKETPLACE_URL } from "../../lib/env";
import { Card, CardContent } from "../ui/card";
import { Button } from "../ui/button";
import type { Blog } from "../../lib/api/blogs";
import { getImageUrl } from "../../lib/api";
import { formatRelativeDate } from "../../lib/format-date";
export interface BlogCardProps {
blog: Blog;
onPublish: (blogId: string) => void;
onArchive: (blogId: string) => void;
onUnarchive: (blogId: string) => void;
/** #587: drafts can be deleted from the list — handler shown only for drafts. */
onDelete?: (blogId: string) => void;
}
function getStatusBadge(status: string) {
const styles: Record<string, string> = {
draft: "bg-warning-light text-warning",
published: "bg-success-light text-success",
archived: "bg-background-muted text-foreground-muted",
};
return (
<span
className={`px-2 py-1 text-xs font-medium rounded-full ${styles[status] || styles.draft}`}
>
{status.charAt(0).toUpperCase() + status.slice(1)}
</span>
);
}
export const BlogCard = memo(function BlogCard({
blog,
onPublish,
onArchive,
onUnarchive,
onDelete,
}: BlogCardProps) {
return (
<Card className="overflow-hidden transition-shadow duration-200 hover:shadow-card-hover flex flex-col">
{/* Card Image - Clickable to edit */}
<Link to={`/blogs/${blog.id}/edit`}>
<div className="h-48 bg-background-muted flex items-center justify-center cursor-pointer hover:opacity-90 transition-opacity overflow-hidden relative">
{blog.featuredImageUrl ? (
<img
src={getImageUrl(blog.featuredImageUrl)}
alt={blog.featuredImageAlt || blog.title}
className="w-full h-full object-cover"
loading="lazy"
/>
) : (
<div className="w-full h-full bg-gradient-to-br from-gray-50 to-slate-50 flex flex-col items-center justify-center gap-2">
<FileText className="h-10 w-10 text-foreground-subtle/60" />
<span className="text-xs text-foreground-subtle font-medium">
No Featured Image
</span>
</div>
)}
</div>
</Link>
<CardContent className="p-4 flex flex-col flex-1">
<div className="flex items-start justify-between mb-2">
<Link
to={`/blogs/${blog.id}/edit`}
className="font-semibold text-foreground-default truncate hover:text-primary-600 transition-colors"
>
{blog.title}
</Link>
{getStatusBadge(blog.status)}
</div>
{blog.metaDescription && (
<p className="text-sm text-foreground-muted line-clamp-2 mb-4">
{blog.metaDescription}
</p>
)}
{/* Metadata row */}
<div className="flex items-center gap-3 text-xs text-foreground-subtle mb-3 mt-auto">
<span className="flex items-center gap-1">
<Clock className="h-3 w-3" />
{formatRelativeDate(blog.dateUpdated)}
</span>
{blog.readTimeMinutes && (
<span className="flex items-center gap-1">
<BookOpen className="h-3 w-3" />
{blog.readTimeMinutes} min read
</span>
)}
</div>
{/* Action buttons */}
<div className="flex items-center gap-1 sm:gap-2 pt-2 border-t border-border-default flex-wrap">
<Link to={`/blogs/${blog.id}/edit`}>
<Button
variant="ghost"
size="sm"
title="Edit"
className="p-2 sm:px-3"
>
<Edit className="h-4 w-4" />
</Button>
</Link>
{blog.status === "draft" && (
<Button
variant="ghost"
size="sm"
onClick={() => onPublish(blog.id)}
title="Publish"
className="p-2 sm:px-3"
>
<Send className="h-4 w-4" />
</Button>
)}
{blog.status === "draft" && onDelete && (
<Button
variant="ghost"
size="sm"
onClick={() => onDelete(blog.id)}
title="Delete"
className="p-2 sm:px-3 text-foreground-muted hover:text-error"
>
<Trash2 className="h-4 w-4" />
</Button>
)}
{blog.status === "published" && (
<>
<a
href={`${MARKETPLACE_URL}/blog/${blog.slug}`}
target="_blank"
rel="noopener noreferrer"
>
<Button
variant="ghost"
size="sm"
title="View Live"
className="p-2 sm:px-3"
>
<ExternalLink className="h-4 w-4" />
</Button>
</a>
<Button
variant="ghost"
size="sm"
onClick={() => onArchive(blog.id)}
title="Archive"
className="p-2 sm:px-3"
>
<Archive className="h-4 w-4" />
</Button>
</>
)}
{blog.status === "archived" && (
<Button
variant="ghost"
size="sm"
onClick={() => onUnarchive(blog.id)}
title="Restore"
className="p-2 sm:px-3"
>
<ArchiveRestore className="h-4 w-4" />
</Button>
)}
</div>
</CardContent>
</Card>
);
});
|