diff --git a/src/components/Home/FavoritesSection/FavoritesSection.tsx b/src/components/Home/FavoritesSection/FavoritesSection.tsx new file mode 100644 index 000000000..f90f87be2 --- /dev/null +++ b/src/components/Home/FavoritesSection/FavoritesSection.tsx @@ -0,0 +1,116 @@ +import { useNavigate } from "@tanstack/react-router"; +import { ChevronLeft, ChevronRight, GitBranch, Play, Star, X } from "lucide-react"; +import { useState } from "react"; + +import { Button } from "@/components/ui/button"; +import { InlineStack } from "@/components/ui/layout"; +import { Paragraph, Text } from "@/components/ui/typography"; +import { type FavoriteItem, useFavorites } from "@/hooks/useFavorites"; +import { EDITOR_PATH, RUNS_BASE_PATH } from "@/routes/router"; + +const PAGE_SIZE = 10; + +function getFavoriteUrl(item: FavoriteItem): string { + if (item.type === "pipeline") return `${EDITOR_PATH}/${item.id}`; + return `${RUNS_BASE_PATH}/${item.id}`; +} + +const FavoriteChip = ({ item }: { item: FavoriteItem }) => { + const navigate = useNavigate(); + const { removeFavorite } = useFavorites(); + + const handleClick = () => { + navigate({ to: getFavoriteUrl(item) }); + }; + + const handleRemove = (e: React.MouseEvent) => { + e.stopPropagation(); + removeFavorite(item.type, item.id); + }; + + return ( +
+ {item.type === "pipeline" ? ( + + ) : ( + + )} + {item.name} + +
+ ); +}; + +export const FavoritesSection = () => { + const { favorites } = useFavorites(); + const [page, setPage] = useState(0); + + const totalPages = Math.ceil(favorites.length / PAGE_SIZE); + // Reset to last valid page if favorites shrink (e.g. after removing items) + const safePage = Math.min(page, Math.max(0, totalPages - 1)); + const paginated = favorites.slice(safePage * PAGE_SIZE, (safePage + 1) * PAGE_SIZE); + + return ( +
+ + + + Favorites + + + + {favorites.length === 0 ? ( + + No favorites yet. Star a pipeline or run to pin it here. + + ) : ( +
+
+ {paginated.map((item) => ( + + ))} +
+ + {totalPages > 1 && ( + + + + {safePage + 1} / {totalPages} + + + + )} +
+ )} +
+ ); +}; diff --git a/src/routes/Dashboard/Dashboard.tsx b/src/routes/Dashboard/Dashboard.tsx index aaf8a2a1b..e7d490a59 100644 --- a/src/routes/Dashboard/Dashboard.tsx +++ b/src/routes/Dashboard/Dashboard.tsx @@ -1,3 +1,4 @@ +import { FavoritesSection } from "@/components/Home/FavoritesSection/FavoritesSection"; import { BlockStack, InlineStack } from "@/components/ui/layout"; import { Text } from "@/components/ui/typography"; @@ -17,6 +18,7 @@ export const Dashboard = () => { Beta + ); };