Skip to content

Commit ea60d9f

Browse files
committed
Updates revently viewed
1 parent 1e454af commit ea60d9f

2 files changed

Lines changed: 99 additions & 3 deletions

File tree

src/hooks/useRecentlyViewed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useCallback, useSyncExternalStore } from "react";
33
import { getStorage } from "@/utils/typedStorage";
44

55
const RECENTLY_VIEWED_KEY = "Home/recently_viewed";
6-
const MAX_ITEMS = 5;
6+
const MAX_ITEMS = 10;
77

88
type RecentlyViewedType = "pipeline" | "run" | "component";
99

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,101 @@
1-
import { RecentlyViewedSection } from "@/components/Home/RecentlyViewedSection/RecentlyViewedSection";
1+
import { useNavigate } from "@tanstack/react-router";
2+
import { GitBranch, Play } from "lucide-react";
3+
4+
import { BlockStack, InlineStack } from "@/components/ui/layout";
5+
import { Paragraph, Text } from "@/components/ui/typography";
6+
import {
7+
type RecentlyViewedItem,
8+
useRecentlyViewed,
9+
} from "@/hooks/useRecentlyViewed";
10+
import { EDITOR_PATH, RUNS_BASE_PATH } from "@/routes/router";
11+
12+
function getRecentlyViewedUrl(item: RecentlyViewedItem): string {
13+
if (item.type === "pipeline") return `${EDITOR_PATH}/${item.id}`;
14+
if (item.type === "run") return `${RUNS_BASE_PATH}/${item.id}`;
15+
return "/";
16+
}
17+
18+
function formatRelativeTime(viewedAt: number): string {
19+
const diff = Date.now() - viewedAt;
20+
const minutes = Math.floor(diff / 60_000);
21+
if (minutes < 1) return "just now";
22+
if (minutes < 60) return `${minutes}m ago`;
23+
const hours = Math.floor(minutes / 60);
24+
if (hours < 24) return `${hours}h ago`;
25+
const days = Math.floor(hours / 24);
26+
return `${days}d ago`;
27+
}
28+
29+
const RecentlyViewedCard = ({ item }: { item: RecentlyViewedItem }) => {
30+
const navigate = useNavigate();
31+
const isPipeline = item.type === "pipeline";
32+
33+
return (
34+
<div
35+
onClick={() => navigate({ to: getRecentlyViewedUrl(item) })}
36+
className={`flex flex-col gap-2 p-3 border rounded-lg cursor-pointer transition-colors ${
37+
isPipeline
38+
? "bg-violet-50/40 hover:bg-violet-50 border-violet-100"
39+
: "bg-emerald-50/40 hover:bg-emerald-50 border-emerald-100"
40+
}`}
41+
>
42+
{/* Type badge */}
43+
<InlineStack gap="1" blockAlign="center" align="space-between">
44+
<InlineStack gap="1" blockAlign="center">
45+
{isPipeline ? (
46+
<GitBranch className="h-3.5 w-3.5 shrink-0 text-violet-500" />
47+
) : (
48+
<Play className="h-3.5 w-3.5 shrink-0 text-emerald-500" />
49+
)}
50+
<Text
51+
size="xs"
52+
weight="semibold"
53+
className={isPipeline ? "text-violet-600" : "text-emerald-600"}
54+
>
55+
{isPipeline ? "Pipeline" : "Run"}
56+
</Text>
57+
</InlineStack>
58+
<Text size="xs" className="text-muted-foreground">
59+
{formatRelativeTime(item.viewedAt)}
60+
</Text>
61+
</InlineStack>
62+
63+
{/* Name */}
64+
<Text size="sm" weight="semibold" className="truncate leading-tight">
65+
{item.name}
66+
</Text>
67+
68+
{/* ID */}
69+
<Text size="xs" className="truncate text-muted-foreground font-mono">
70+
{item.id}
71+
</Text>
72+
</div>
73+
);
74+
};
275

376
export function DashboardRecentlyViewedView() {
4-
return <RecentlyViewedSection />;
77+
const { recentlyViewed } = useRecentlyViewed();
78+
79+
return (
80+
<BlockStack gap="4">
81+
<Text as="h2" size="lg" weight="semibold">
82+
Recently Viewed
83+
</Text>
84+
85+
{recentlyViewed.length === 0 ? (
86+
<Paragraph tone="subdued" size="sm">
87+
Nothing viewed yet. Open a pipeline or run to see it here.
88+
</Paragraph>
89+
) : (
90+
<div className="grid grid-cols-4 gap-3">
91+
{recentlyViewed.map((item) => (
92+
<RecentlyViewedCard
93+
key={`${item.type}-${item.id}`}
94+
item={item}
95+
/>
96+
))}
97+
</div>
98+
)}
99+
</BlockStack>
100+
);
5101
}

0 commit comments

Comments
 (0)