diff --git a/src/api.js b/src/api.js new file mode 100644 index 00000000..88bb9c3a --- /dev/null +++ b/src/api.js @@ -0,0 +1,47 @@ +const apiURI = "https://boolean-uk-api-server.fly.dev" + +export function getUsers(){ + return fetch(apiURI + "/lucasholter00/contact", { + method: "GET", + headers: { + "Accept": "application/json" + } + }).then(res => { + if (!res.ok) { + // If response status is not 2xx, throw error to be caught below + throw new Error(`HTTP error! Status: ${res.status}`); + } + return res.json(); + }).catch(err => {throw err}) +} + +export function getArt(){ + return fetch(apiURI + "/art", { + method: "GET", + headers: { + "Accept": "application/json" + } + }).then(res => { + if (!res.ok) { + // If response status is not 2xx, throw error to be caught below + throw new Error(`HTTP error! Status: ${res.status}`); + } + return res.json(); + }).catch(err => {throw err}) +} + +export function getAdvice(){ + return fetch("https://api.adviceslip.com/advice", { + cache: "no-store", + method: "GET", + headers: { + "Accept": "application/json" + } + }).then(res => { + if (!res.ok) { + // If response status is not 2xx, throw error to be caught below + throw new Error(`HTTP error! Status: ${res.status}`); + } + return res.json(); + }).catch(err => {throw err}) +} diff --git a/src/sections/Advice/components/AdviceSlip.jsx b/src/sections/Advice/components/AdviceSlip.jsx index e69de29b..3d614068 100644 --- a/src/sections/Advice/components/AdviceSlip.jsx +++ b/src/sections/Advice/components/AdviceSlip.jsx @@ -0,0 +1,11 @@ +export default function AdviceSlip( { advice, newAdvice, addToFavorites } ){ + + return ( + <> +

Some Advice

+

{ advice.slip?.advice || "....loading" }

+ + + + ) +} diff --git a/src/sections/Advice/components/FavouriteSlipsList.jsx b/src/sections/Advice/components/FavouriteSlipsList.jsx index e69de29b..2e1e5c20 100644 --- a/src/sections/Advice/components/FavouriteSlipsList.jsx +++ b/src/sections/Advice/components/FavouriteSlipsList.jsx @@ -0,0 +1,10 @@ +export default function FavouriteSlipsList( { favoriteAdvice } ){ + + return( + + ) +} diff --git a/src/sections/Advice/index.jsx b/src/sections/Advice/index.jsx index 0405f11f..29b0e606 100644 --- a/src/sections/Advice/index.jsx +++ b/src/sections/Advice/index.jsx @@ -1,11 +1,43 @@ +import { useEffect, useState } from "react" +import { getAdvice } from "../../api" +import AdviceSlip from "./components/AdviceSlip" +import FavouriteSlipsList from "./components/FavouriteSlipsList" + function AdviceSection() { + + const [advice, setAdvice] = useState({}) + const [favoriteAdvice, setFavoriteAdvice] = useState([]) + + function newAdvice(){ + setAdvice({}) + getAdvice() + .then((data) => setAdvice(data)) + .catch((err) => console.log(err)) + } + + function addToFavorites(){ + setFavoriteAdvice([...favoriteAdvice, advice]) + } + + useEffect(() => { + newAdvice() + console.log(advice) + }, []) + return ( -
-

Advice Section

-
-
-
- ) + <> +
+

Advice Section

+
+ +
+
+

Favourite Advice Slips

+ +
+
+ + ) } export default AdviceSection diff --git a/src/sections/Art/components/ArtList.jsx b/src/sections/Art/components/ArtList.jsx index e69de29b..fb72d07b 100644 --- a/src/sections/Art/components/ArtList.jsx +++ b/src/sections/Art/components/ArtList.jsx @@ -0,0 +1,15 @@ +import ArtListItem from "./ArtListItem"; + +export default function ArtList({ artList }){ + + return ( + + + + ) + +} diff --git a/src/sections/Art/components/ArtListItem.jsx b/src/sections/Art/components/ArtListItem.jsx index e69de29b..478032d5 100644 --- a/src/sections/Art/components/ArtListItem.jsx +++ b/src/sections/Art/components/ArtListItem.jsx @@ -0,0 +1,24 @@ +import PublicationHistoryList from "./PublicationHistoryList"; + +export default function ArtListItem( { art, index } ){ + + return( + <> +
  • +
    + +
    +

    { art.title }

    +

    Artist: { art.artist }

    +

    Publication History:

    + +
  • + + ) +} diff --git a/src/sections/Art/components/PublicationHistoryList.jsx b/src/sections/Art/components/PublicationHistoryList.jsx index d3f5a12f..79a0ffb1 100644 --- a/src/sections/Art/components/PublicationHistoryList.jsx +++ b/src/sections/Art/components/PublicationHistoryList.jsx @@ -1 +1,6 @@ +export default function PublicationHistoryList({ pub, index }){ + return( +
  • { pub }
  • + ) +} diff --git a/src/sections/Art/index.jsx b/src/sections/Art/index.jsx index 0c74ffc2..a4b72d2d 100644 --- a/src/sections/Art/index.jsx +++ b/src/sections/Art/index.jsx @@ -1,8 +1,28 @@ +import { useEffect, useState } from "react" +import { getArt } from "../../api" +import ArtList from "./components/ArtList" + function ArtsSection() { + + const [artList, setArtList] = useState([]) + + useEffect(() => { + + getArt() + .then((data) => { + setArtList(data) + }).catch(err => console.log(err)) + }, []) + return (

    Arts Section

    -
    +
    + + + + +
    ) } diff --git a/src/sections/Users/components/UsersList.jsx b/src/sections/Users/components/UsersList.jsx index e69de29b..2ec17292 100644 --- a/src/sections/Users/components/UsersList.jsx +++ b/src/sections/Users/components/UsersList.jsx @@ -0,0 +1,14 @@ +import UsersListItem from "./UsersListItem"; + +export default function UsersList({ users }){ + + return ( + <> + + + ) +} diff --git a/src/sections/Users/components/UsersListItem.jsx b/src/sections/Users/components/UsersListItem.jsx index e69de29b..7efce0ae 100644 --- a/src/sections/Users/components/UsersListItem.jsx +++ b/src/sections/Users/components/UsersListItem.jsx @@ -0,0 +1,16 @@ + +export default function UsersListItem({ user, index }){ + + return ( + < > +
  • + { +

    { user.firstName } { user.lastName }

    +

    { user.email }

    +
  • + + ) +} diff --git a/src/sections/Users/index.jsx b/src/sections/Users/index.jsx index 77332830..c8958abb 100644 --- a/src/sections/Users/index.jsx +++ b/src/sections/Users/index.jsx @@ -1,8 +1,24 @@ +import { useEffect, useState } from "react" +import { getUsers } from "../../api" +import UsersList from "./components/UsersList" + function UsersSection() { + const [users, setUsers] = useState([]) + + useEffect(() => { + getUsers() + .then(data => setUsers(data)) + .catch(err => console.log(err)) + },[]) + return (

    Users Section

    -
    +
    +
    + +
    +
    ) }