diff --git a/src/components/GalleryItem.js b/src/components/GalleryItem.js index 4d6c5f3..d33bb0e 100644 --- a/src/components/GalleryItem.js +++ b/src/components/GalleryItem.js @@ -1,48 +1,51 @@ -import { useParams } from "react-router-dom"; +import { Link, useParams } from "react-router-dom"; import React, { useState, useEffect } from "react"; import { sculptureList } from "../data/list.js"; const GalleryItem = () => { - // get the param from the url - // 'http://localhost/gallery/1' - // useParams => 1 - const { id } = useParams(); + // get the param from the url + // 'http://localhost/gallery/1' + // useParams => 1 + const { id } = useParams(); - // create our state gfor the gallery item to show - // null default - const [item, setItem] = useState(null); + // create our state gfor the gallery item to show + // null default + const [item, setItem] = useState(null); - // use effect search the sculturelist array for the id taken from the params url - useEffect(() => { - // serach the scultureList array for the item with the id of 1 - // in the array find the item with the id of 1 - let sculpture = sculptureList.find((item) => { - return item.id == id; - }); + // use effect search the sculturelist array for the id taken from the params url + useEffect(() => { + // serach the scultureList array for the item with the id of 1 + // in the array find the item with the id of 1 + const itemIndex = sculptureList.findIndex(item => { + return item.id == id; + }); + let sculpture = sculptureList[itemIndex]; + let nextSculptureID = sculptureList[(itemIndex + 1) % sculptureList.length].id; - // set state of item to be the individual sculpture - setItem(sculpture); - }, [id]); + // set state of item to be the individual sculpture + setItem({ art: sculpture, next: nextSculptureID, index: itemIndex }); + }, [id]); - // render template - return ( -
{item.description}
- > - ) : ( -Item not found
- )} -{item.art.description}
+ > + ) : ( +Item not found
+ )} +