Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

PreviewRecentUrlCard.tsx

51 lines2.0 KB

1import type { ScopedThreadRef } from "@t3tools/contracts";
2import { X } from "lucide-react";
3​
4import { isValidHistoryTimestamp, type BrowserHistoryEntry } from "~/browserHistoryStore";
5import { RelativeTime } from "~/components/RelativeTime";
6​
7import { PreviewFaviconIcon } from "./PreviewFaviconIcon";
8​
9interface Props {
10 threadRef: ScopedThreadRef;
11 entry: BrowserHistoryEntry;
12 onOpen: () => void;
13 onRemove: () => void;
15​
16export function PreviewRecentUrlCard({ threadRef, entry, onOpen, onRemove }: Props) {
17 const parsed = new URL(entry.url);
18 const path = parsed.pathname === "/" ? "" : parsed.pathname;
19 const label = `${parsed.host}${path}${parsed.search}${parsed.hash}`;
20 const visitedAt = isValidHistoryTimestamp(entry.lastVisitedAt) ? (
21 <RelativeTime timestamp={new Date(entry.lastVisitedAt).toISOString()} />
22 ) : null;
23 return (
24 <div className="group relative flex w-full items-center">
25 <button
26 type="button"
27 onClick={onOpen}
28 className="flex w-full items-center gap-3 px-3 py-3 pr-10 text-left hover:bg-accent/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
29 >
30 <PreviewFaviconIcon threadRef={threadRef} url={entry.url} />
31 <div className="flex min-w-0 flex-1 flex-col">
32 <span className="truncate text-sm font-medium text-foreground">
33 {entry.title ?? label}
34 </span>
35 <span className="truncate text-xs text-muted-foreground">
36 {entry.title ? `${label} · ` : ""}
37 {visitedAt}
38 </span>
39 </div>
40 </button>
41 <button
42 type="button"
43 aria-label={`Remove ${label} from history`}
44 onClick={onRemove}
45 className="absolute right-3 rounded p-1 text-muted-foreground opacity-0 hover:bg-accent hover:text-foreground focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring group-hover:opacity-100"
46 >
47 <X className="size-3.5" />
48 </button>
49 </div>
50 );