-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPackageDashboard.tsx
More file actions
92 lines (87 loc) · 2.52 KB
/
PackageDashboard.tsx
File metadata and controls
92 lines (87 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import React from "react";
import {
Box,
Card,
CardContent,
Typography,
Grid,
CircularProgress,
Container,
} from "@mui/material";
import { useNavigate } from "react-router-dom";
import useFetchRecentPackages, {
RecentPackage,
} from "../hooks/useFetchRecentPackages";
import "./PackageDashboard.css";
const PackageDashboard: React.FC = () => {
const navigate = useNavigate();
const { data, loading } = useFetchRecentPackages();
if (loading) {
return (
<Box
display="flex"
justifyContent="center"
alignItems="center"
minHeight="50vh"
>
<CircularProgress />
</Box>
);
}
const renderPackages = (packages: RecentPackage[], type: string) => (
<>
<Typography variant="h5" gutterBottom className="section-title">
{type}
</Typography>
{packages.map((pkg, i) => (
<Card
key={i}
className="package-card"
onClick={() => navigate("/package/" + pkg.name)}
onMouseEnter={(e) =>
(e.currentTarget.className = "package-card package-card-hover")
}
onMouseLeave={(e) => (e.currentTarget.className = "package-card")}
>
<CardContent className="card-content">
<Box flex={1}>
<Typography variant="h6" gutterBottom className="package-name">
{pkg.name} (v{pkg.version})
</Typography>
<Typography
variant="body2"
color="textSecondary"
gutterBottom
className="package-timestamp"
>
{type === "Just Updated"
? `Updated: ${new Date(pkg.updatedAt!).toLocaleString()}`
: `Added: ${new Date(pkg.createdAt!).toLocaleString()}`}
</Typography>
<Typography
variant="body1"
paragraph
className="package-description"
>
{pkg.description || "No description available."}
</Typography>
</Box>
</CardContent>
</Card>
))}
</>
);
return (
<Container maxWidth="md" className="dashboard-container">
<Grid container spacing={4}>
<Grid item xs={12} md={6}>
{renderPackages(data.recentlyUpdated, "Just Updated")}
</Grid>
<Grid item xs={12} md={6}>
{renderPackages(data.recentlyCreated, "New Packages")}
</Grid>
</Grid>
</Container>
);
};
export default PackageDashboard;