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 ? ( - <> -

- {item.name} by {item.artist} -

-

- ({item.id + 1} of {sculptureList.length}) -

- {item.alt} -

{item.description}

- - ) : ( -

Item not found

- )} -
- ); + // render template + return ( +
+ {item ? ( + <> +

+ {item.art.name} by {item.art.artist} +

+ Next +

+ ({item.index + 1} of {sculptureList.length}) +

+ {item.art.alt} +

{item.art.description}

+ + ) : ( +

Item not found

+ )} +
+ ); }; export default GalleryItem; diff --git a/src/components/StyledComponent.js b/src/components/StyledComponent.js index 726cf75..5be0b3a 100644 --- a/src/components/StyledComponent.js +++ b/src/components/StyledComponent.js @@ -1,11 +1,26 @@ import React from "react"; export default function StyledComponent() { - return ( -
-
- This is a styled section with animation -
-
- ); + const [looptime, setLoopTime] = React.useState("3000"); + const animatedSection = { + color: "blue", + backgroundColor: "lightgray", + padding: "10px", + bordeRadius: "5px", + maxWidth: "100vw", + animation: `fadeInScale ${looptime}ms ease-in-out infinite`, + }; + const setLoop = event => { + setLoopTime(event.target.value); + }; + return ( +
+
+ +
+
+ This is a styled section with animation +
+
+ ); }