From 31528d6932c419d2ed856b09cd5a3a6410dcd663 Mon Sep 17 00:00:00 2001 From: imhson Date: Mon, 26 Aug 2024 10:32:33 +0700 Subject: [PATCH] update artist --- src/components/pages/artist/Artworks.tsx | 71 ++++++++++++++++++------ 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/src/components/pages/artist/Artworks.tsx b/src/components/pages/artist/Artworks.tsx index b449c235..0b1f2fb0 100644 --- a/src/components/pages/artist/Artworks.tsx +++ b/src/components/pages/artist/Artworks.tsx @@ -17,7 +17,7 @@ import { Controller } from 'swiper/modules' export default function ArtworkList({ id }) { const [page, setPage] = useState(1) const [open, setOpen] = useState(false) - const [index, setIndex] = useState(1) + const [selectedArtwork, setSelectedArtwork] = useState(null) const { data, isLoading } = useSWR( { key: 'fetch-artist-artworks', @@ -27,6 +27,19 @@ export default function ArtworkList({ id }) { ) const { t } = useTranslation() + + const prevHandler = () => { + const idx = data?.artworks?.findIndex((artwork) => artwork.url == selectedArtwork.url) + if (data?.artworks[idx - 1]) { + setSelectedArtwork(data?.artworks[idx - 1]) + } + } + const nextHandler = () => { + const idx = data?.artworks?.findIndex((artwork) => artwork.url == selectedArtwork.url) + if (data?.artworks[idx + 1]) { + setSelectedArtwork(data?.artworks[idx + 1]) + } + } if (isLoading) { return (
@@ -44,21 +57,47 @@ export default function ArtworkList({ id }) {
{data?.artworks?.length ? ( <> - -
- - {data?.artworks?.map((artwork, index) => ( - - +
+ +
+
+ + - - ))} - + +
+
+ + + +
+
@@ -66,7 +105,7 @@ export default function ArtworkList({ id }) {
{ - setIndex(index) + setSelectedArtwork(artwork) setOpen(true) }}>