Skip to content

Commit c929898

Browse files
committed
feat_favorites_homepage_section
1 parent 6581b3a commit c929898

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { useNavigate } from "@tanstack/react-router";
2+
import { Star } from "lucide-react";
3+
4+
import { FavoriteToggle } from "@/components/shared/FavoriteToggle";
5+
import { Badge } from "@/components/ui/badge";
6+
import { InlineStack } from "@/components/ui/layout";
7+
import { Paragraph, Text } from "@/components/ui/typography";
8+
import { type FavoriteItem, useFavorites } from "@/hooks/useFavorites";
9+
import { EDITOR_PATH, RUNS_BASE_PATH } from "@/routes/router";
10+
11+
function getFavoriteUrl(item: FavoriteItem): string {
12+
if (item.type === "pipeline") return `${EDITOR_PATH}/${item.id}`;
13+
return `${RUNS_BASE_PATH}/${item.id}`;
14+
}
15+
16+
const FavoriteCard = ({ item }: { item: FavoriteItem }) => {
17+
const navigate = useNavigate();
18+
19+
const handleClick = () => {
20+
navigate({ to: getFavoriteUrl(item) });
21+
};
22+
23+
return (
24+
<div
25+
onClick={handleClick}
26+
className="w-48 shrink-0 p-3 border rounded-lg cursor-pointer hover:bg-muted/50 flex flex-col gap-2"
27+
>
28+
<Paragraph className="truncate text-sm font-medium" title={item.name}>
29+
{item.name}
30+
</Paragraph>
31+
<InlineStack align="space-between" blockAlign="center">
32+
<Badge variant="secondary" size="sm">
33+
{item.type === "pipeline" ? "Pipeline" : "Run"}
34+
</Badge>
35+
<FavoriteToggle type={item.type} id={item.id} name={item.name} />
36+
</InlineStack>
37+
</div>
38+
);
39+
};
40+
41+
export const FavoritesSection = () => {
42+
const { favorites } = useFavorites();
43+
44+
return (
45+
<div className="flex flex-col gap-2">
46+
<InlineStack blockAlign="center" gap="1">
47+
<Star className="h-4 w-4 text-warning" fill="oklch(79.5% 0.184 86.047)" />
48+
<Text as="h2" size="sm" weight="semibold">
49+
Favorites
50+
</Text>
51+
</InlineStack>
52+
53+
{favorites.length === 0 ? (
54+
<Paragraph tone="subdued" size="sm">
55+
No favorites yet. Star a pipeline or run to pin it here.
56+
</Paragraph>
57+
) : (
58+
<div className="flex gap-3 overflow-x-auto pb-1">
59+
{favorites.map((item) => (
60+
<FavoriteCard key={`${item.type}-${item.id}`} item={item} />
61+
))}
62+
</div>
63+
)}
64+
</div>
65+
);
66+
};

src/routes/Dashboard/Dashboard.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { FavoritesSection } from "@/components/Home/FavoritesSection/FavoritesSection";
12
import { BlockStack, InlineStack } from "@/components/ui/layout";
23
import { Text } from "@/components/ui/typography";
34

@@ -17,6 +18,7 @@ export const Dashboard = () => {
1718
Beta
1819
</Text>
1920
</InlineStack>
21+
<FavoritesSection />
2022
</BlockStack>
2123
);
2224
};

0 commit comments

Comments
 (0)