- Created WatchBuddy model - M:N junctions to EntrySeen/EpisodeSeen and Media relation for profile pictures - Full CRUD + search + profile picture upload - WatchBuddySelect multi-select with search and inline create, replaced all seen_with text inputs - WatchBuddiesPage (grid) and WatchBuddyProfilePage (edit form, icon-based contacts, poster-grid watch history, monthly timeline)
103 lines
3.5 KiB
TypeScript
103 lines
3.5 KiB
TypeScript
import { format } from "date-fns";
|
|
import { Link } from "react-router-dom";
|
|
import type { EntrySeen, EpisodeSeen } from "@/types";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { Pencil, Trash2, Users } from "lucide-react";
|
|
|
|
interface EpisodeWatchHistoryProps {
|
|
watchHistory: (EntrySeen | EpisodeSeen)[];
|
|
onEdit?: (id: number) => void;
|
|
onDelete?: (id: number) => void;
|
|
}
|
|
|
|
export function EpisodeWatchHistory({
|
|
watchHistory,
|
|
onEdit,
|
|
onDelete,
|
|
}: EpisodeWatchHistoryProps) {
|
|
if (watchHistory.length === 0) {
|
|
return (
|
|
<p className="text-sm text-muted-foreground">No watch history yet.</p>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-3">
|
|
<h3 className="text-lg font-semibold">Watch History</h3>
|
|
<div className="overflow-x-auto rounded-lg border border-border">
|
|
<table className="w-full text-sm">
|
|
<thead>
|
|
<tr className="border-b border-border bg-muted/50">
|
|
<th className="px-4 py-2 text-left font-medium">Date</th>
|
|
<th className="px-4 py-2 text-left font-medium">
|
|
<span className="flex items-center gap-1">
|
|
<Users className="h-3 w-3" />
|
|
Buddies
|
|
</span>
|
|
</th>
|
|
<th className="px-4 py-2 text-right font-medium">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{watchHistory.map((record) => (
|
|
<tr
|
|
key={record.id}
|
|
className="border-b border-border last:border-0"
|
|
>
|
|
<td className="px-4 py-2">
|
|
{record.date_seen
|
|
? format(new Date(record.date_seen), "MMM d, yyyy")
|
|
: "-"}
|
|
</td>
|
|
<td className="px-4 py-2">
|
|
<div className="flex flex-wrap gap-1">
|
|
{record.buddies && record.buddies.length > 0 ? (
|
|
record.buddies.map((b) => (
|
|
<Link key={b.id} to={`/watch-buddies/${b.id}`}>
|
|
<Badge
|
|
variant="secondary"
|
|
className="cursor-pointer text-xs hover:bg-accent"
|
|
>
|
|
{b.name}
|
|
</Badge>
|
|
</Link>
|
|
))
|
|
) : (
|
|
<span className="text-muted-foreground">-</span>
|
|
)}
|
|
</div>
|
|
</td>
|
|
<td className="px-4 py-2">
|
|
<div className="flex justify-end gap-1">
|
|
{onEdit && (
|
|
<Button
|
|
size="icon"
|
|
variant="ghost"
|
|
className="h-7 w-7"
|
|
onClick={() => onEdit(record.id)}
|
|
>
|
|
<Pencil className="h-3 w-3" />
|
|
</Button>
|
|
)}
|
|
{onDelete && (
|
|
<Button
|
|
size="icon"
|
|
variant="ghost"
|
|
className="h-7 w-7 text-destructive"
|
|
onClick={() => onDelete(record.id)}
|
|
>
|
|
<Trash2 className="h-3 w-3" />
|
|
</Button>
|
|
)}
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|