From d9837b7cfd971924353e3bda3910f2f0fdbf3e3b Mon Sep 17 00:00:00 2001 From: Marie Helene Hansen Date: Tue, 2 Sep 2025 08:29:23 +0200 Subject: [PATCH] core + extension --- src/App.jsx | 2 +- src/sections/Advice/components/AdviceSlip.jsx | 41 +++++++++++++++++++ .../Advice/components/FavouriteSlipsList.jsx | 12 ++++++ src/sections/Advice/index.jsx | 20 ++++++++- src/sections/Art/components/ArtList.jsx | 33 +++++++++++++++ src/sections/Art/components/ArtListItem.jsx | 30 ++++++++++++++ .../Art/components/PublicationHistoryList.jsx | 13 ++++++ src/sections/Art/index.jsx | 9 +++- src/sections/Users/components/UsersList.jsx | 33 +++++++++++++++ .../Users/components/UsersListItem.jsx | 25 +++++++++++ src/sections/Users/index.jsx | 8 +++- 11 files changed, 219 insertions(+), 7 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 5ef8293f..26b2b3fb 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -13,4 +13,4 @@ function App() { ) } -export default App +export default App; diff --git a/src/sections/Advice/components/AdviceSlip.jsx b/src/sections/Advice/components/AdviceSlip.jsx index e69de29b..0d2ad541 100644 --- a/src/sections/Advice/components/AdviceSlip.jsx +++ b/src/sections/Advice/components/AdviceSlip.jsx @@ -0,0 +1,41 @@ +import { useEffect, useState } from 'react' + +function AdviceSlip({ onAddToFavourites }) { + + const url = "https://api.adviceslip.com/advice"; + const [data, setData] = useState([]); + + // had to move it outside the useEffect to use it in button for get more advice + const fetchData = async () => { + + const response = await fetch(url); + const jsonData = await response.json(); + setData(jsonData.slip); + }; + + useEffect(() => { + + fetchData(); + }, []) + + return ( + <> +
+

+ Some advice! +

+

+ {data.advice} +

+ + +
+ + ) +} + +export default AdviceSlip; \ No newline at end of file diff --git a/src/sections/Advice/components/FavouriteSlipsList.jsx b/src/sections/Advice/components/FavouriteSlipsList.jsx index e69de29b..f5134279 100644 --- a/src/sections/Advice/components/FavouriteSlipsList.jsx +++ b/src/sections/Advice/components/FavouriteSlipsList.jsx @@ -0,0 +1,12 @@ +function FavouriteSlipsList({ favourites }) { + + return ( + + ); +} + +export default FavouriteSlipsList; \ No newline at end of file diff --git a/src/sections/Advice/index.jsx b/src/sections/Advice/index.jsx index 0405f11f..24ced464 100644 --- a/src/sections/Advice/index.jsx +++ b/src/sections/Advice/index.jsx @@ -1,11 +1,27 @@ +import { useState } from 'react' + +import AdviceSlip from './components/AdviceSlip'; +import FavouriteSlipsList from './components/FavouriteSlipsList'; + function AdviceSection() { + + const [favourites, setFavourites] = useState([]); + + const addFavourite = (advice) => { + if (!favourites.some((favourites) => favourites.id === advice.id)) { + setFavourites((it) => [...it, advice]); + } + }; + return (

Advice Section

-
+
+
+
) } -export default AdviceSection +export default AdviceSection; diff --git a/src/sections/Art/components/ArtList.jsx b/src/sections/Art/components/ArtList.jsx index e69de29b..d4e8d97e 100644 --- a/src/sections/Art/components/ArtList.jsx +++ b/src/sections/Art/components/ArtList.jsx @@ -0,0 +1,33 @@ +import { useEffect, useState } from 'react' + +import ArtListItem from "./ArtListItem"; + +function ArtList() { + + const url = "https://boolean-uk-api-server.fly.dev/art"; + const [data, setData] = useState([]); + + useEffect(() => { + + const fetchData = async () => { + + const response = await fetch(url); + const jsonData = await response.json(); + setData(jsonData); + }; + + fetchData(); + }, []) + + return ( +
+ +
+ ); +} + +export default ArtList; \ No newline at end of file diff --git a/src/sections/Art/components/ArtListItem.jsx b/src/sections/Art/components/ArtListItem.jsx index e69de29b..c35d6793 100644 --- a/src/sections/Art/components/ArtListItem.jsx +++ b/src/sections/Art/components/ArtListItem.jsx @@ -0,0 +1,30 @@ +import PublicationHistoryList from "./PublicationHistoryList"; + +function ArtListItem({ art }) { + + const baseURL = "https://boolean-uk-api-server.fly.dev"; + + return ( + <> +
  • +
    + {art.imageURL ? ( + {`${art.title} + ) : ( + "No patch" + )} +
    +

    {art.title}

    +

    {art.artist}

    +

    {}

    +
  • + + ) +} + +export default ArtListItem; \ No newline at end of file diff --git a/src/sections/Art/components/PublicationHistoryList.jsx b/src/sections/Art/components/PublicationHistoryList.jsx index d3f5a12f..f32b18c3 100644 --- a/src/sections/Art/components/PublicationHistoryList.jsx +++ b/src/sections/Art/components/PublicationHistoryList.jsx @@ -1 +1,14 @@ +function PublicationHistoryList({ publication }) { + return ( + <> + + + ) +} + +export default PublicationHistoryList; \ No newline at end of file diff --git a/src/sections/Art/index.jsx b/src/sections/Art/index.jsx index 0c74ffc2..29daec47 100644 --- a/src/sections/Art/index.jsx +++ b/src/sections/Art/index.jsx @@ -1,10 +1,15 @@ +import ArtList from "./components/ArtList" + function ArtsSection() { return (

    Arts Section

    -
    +
    + +
    +
    ) } -export default ArtsSection +export default ArtsSection; diff --git a/src/sections/Users/components/UsersList.jsx b/src/sections/Users/components/UsersList.jsx index e69de29b..02929780 100644 --- a/src/sections/Users/components/UsersList.jsx +++ b/src/sections/Users/components/UsersList.jsx @@ -0,0 +1,33 @@ +import { useEffect, useState } from 'react' + +import UsersListItem from './UsersListItem'; + +function UsersList() { + + const url = "https://boolean-uk-api-server.fly.dev/mariehhansen/contact" + const [data, setData] = useState([]); + + useEffect(() => { + + const fetchData = async () => { + + const response = await fetch(url); + const jsonData = await response.json(); + setData(jsonData); + }; + + fetchData(); + }, []) + return ( +
    + +
    + ) +} + +export default UsersList; \ No newline at end of file diff --git a/src/sections/Users/components/UsersListItem.jsx b/src/sections/Users/components/UsersListItem.jsx index e69de29b..3fef70bb 100644 --- a/src/sections/Users/components/UsersListItem.jsx +++ b/src/sections/Users/components/UsersListItem.jsx @@ -0,0 +1,25 @@ +function UsersListItem({ user }) { + + return ( + <> +
  • +
    + {user.profileImage ? ( + {`${user.firstName} + ) : ( + "No profile image" + )} +
    +

    {(user.gender === "Male") ? ( + "Mr. " + user.firstName + " " + user.lastName + ) : ("Mrs. " + user.firstName + " " + user.lastName)}

    +

    {"Email: " + user.email}

    +
  • + + ); +} + +export default UsersListItem; \ No newline at end of file diff --git a/src/sections/Users/index.jsx b/src/sections/Users/index.jsx index 77332830..16af794c 100644 --- a/src/sections/Users/index.jsx +++ b/src/sections/Users/index.jsx @@ -1,10 +1,14 @@ +import UsersList from "./components/UsersList" + function UsersSection() { return (

    Users Section

    -
    +
    + +
    ) } -export default UsersSection +export default UsersSection;