From 636de186421dbfd7a5f6eecc480b9fd4395c26f3 Mon Sep 17 00:00:00 2001 From: diced Date: Mon, 6 Sep 2021 15:58:01 -0700 Subject: [PATCH] feat(pages): add recent images to dashboard --- src/components/Card.tsx | 2 +- src/components/pages/Dashboard.tsx | 31 ++++++++++++++++++++++++++++-- src/pages/api/user/recent.ts | 5 ++++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/components/Card.tsx b/src/components/Card.tsx index 7c123a0..715f240 100644 --- a/src/components/Card.tsx +++ b/src/components/Card.tsx @@ -9,7 +9,7 @@ export default function Card(props) { const { name, children, ...other } = props; return ( - + {name} {children} diff --git a/src/components/pages/Dashboard.tsx b/src/components/pages/Dashboard.tsx index 2957e50..a011dce 100644 --- a/src/components/pages/Dashboard.tsx +++ b/src/components/pages/Dashboard.tsx @@ -11,7 +11,10 @@ import { ButtonGroup, Typography, Grid, - Skeleton + Skeleton, + CardActionArea, + CardMedia, + Card as MuiCard } from '@material-ui/core'; import Link from 'components/Link'; @@ -85,15 +88,18 @@ export default function Dashboard() { const user = useStoreSelector(state => state.user); const [images, setImages] = useState([]); + const [recent, setRecent] = useState([]); const [page, setPage] = useState(0); const [stats, setStats] = useState(null); const [rowsPerPage, setRowsPerPage] = useState(10); const updateImages = async () => { const imgs = await useFetch('/api/user/images'); + const recent = await useFetch('/api/user/recent'); const stts = await useFetch('/api/stats'); setImages(imgs); setStats(stts); + setRecent(recent); }; const handleChangePage = (event, newPage) => { @@ -119,6 +125,26 @@ export default function Dashboard() { Welcome back {user?.username} You have {images.length ? images.length : '...'} images + Recent Images + + {recent.length ? recent.map(image => ( + + + + + + + + )) : [1,2,3,4].map(x => ( + + + + ))} + Stats @@ -140,7 +166,8 @@ export default function Dashboard() { {stats ? stats.count_users : } - + + View Gallery diff --git a/src/pages/api/user/recent.ts b/src/pages/api/user/recent.ts index feccb41..7eb6b70 100644 --- a/src/pages/api/user/recent.ts +++ b/src/pages/api/user/recent.ts @@ -5,7 +5,7 @@ async function handler(req: NextApiReq, res: NextApiRes) { const user = await req.user(); if (!user) return res.forbid('not logged in'); - const take = Number(req.query.take ?? 3); + const take = Number(req.query.take ?? 4); if (take > 50) return res.error('take can\'t be more than 50'); @@ -21,6 +21,9 @@ async function handler(req: NextApiReq, res: NextApiRes) { } }); + // @ts-ignore + images.map(image => image.url = `/r/${image.file}`); + return res.json(images); }