diff --git a/src/App.tsx b/src/App.tsx index b16f189..7ebbb9a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -56,7 +56,9 @@ export default function App() {
- {/* TODO - shows.map((show)=>{ return })*/} + {shows.map((show) => { + return ; + })}
diff --git a/src/components/showCard/ShowCard.tsx b/src/components/showCard/ShowCard.tsx index 7e18a47..3721fe2 100644 --- a/src/components/showCard/ShowCard.tsx +++ b/src/components/showCard/ShowCard.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; export interface ShowCardProps { artist: string; @@ -8,65 +8,82 @@ export interface ShowCardProps { ticketsLeft: number; image: string; } +const BUTTON_INTERESTED_STATUS = { + ADDED: "Add to interested", + REMOVE: "Remove from interested", +}; -export default function ShowCard( - /* TODO 1: Accept props with ShowCardProps type here */ -) { - // TODO 2: Create state called isInterested of type boolean (default false) - // const [isInterested, setIsInterested] = ... +const INTERESTED_STATUS = { + ADDED: "This show is in your interested list ๐ŸŽŸ๏ธ", + NOT_ADDED: "You haven't added this show yet", +}; - // TODO 3: Function that toggles true/false in isInterested - // function handleToggleInterested() {} +const TICKETS_STATUS = { + SOLD_OUT: "SOLD OUT", + LAST_TICKETS: "Last tickets hurry up!", + AVAILABLE: "Tickets available", +}; - // TODO 4: Create ticketsStatusText (string): - // 0 โ†’ "SOLD OUT" - // 1โ€“30 โ†’ "Last tickets โ€“ hurry up!" - // >30 โ†’ "Tickets available" +export default function ShowCard({ + artist, + stage, + day, + hour, + ticketsLeft, + image, +}: ShowCardProps) { + const [isInterested, setIsInterested] = useState(false); + const [ticketsStatusText, setTicketsStatusText] = useState(""); - // TODO 5: Create text for interest status based on isInterested: - // false โ†’ "You haven't added this show yet" - // true โ†’ "This show is in your interested list ๐ŸŽŸ๏ธ" + useEffect(() => { + const handleTicketsStatusText = (ticketsLeft: number) => { + if (ticketsLeft === 0) { + setTicketsStatusText(TICKETS_STATUS.SOLD_OUT); + return; + } + if (ticketsLeft > 0 && ticketsLeft <= 30) { + setTicketsStatusText(TICKETS_STATUS.LAST_TICKETS); + return; + } + + setTicketsStatusText(TICKETS_STATUS.AVAILABLE); + }; + handleTicketsStatusText(ticketsLeft); + }, []); + + const handleToggleInterested = () => { + setIsInterested(!isInterested); + }; return (
- {/* TODO 6: Replace placeholder with real from props */} - {/* {artist} */} + {artist} +
Image goes here

- {/* TODO 7: If isInterested โ†’ show โญ before artist name */} - "Artist name here" + {isInterested ? "โญ " : ""} {artist}

- {/* TODO 8: Display stage, day, hour from props */} - "Stage ยท Day ยท Hour" + {stage}ยท {day} ยท{hour}

-

- {/* TODO 9: Display the ticketsStatusText */} - "Tickets status text" -

+

{ticketsStatusText}

- {/* TODO 10: Display the interestedText */} - "Interested status text" + {isInterested ? INTERESTED_STATUS.ADDED : INTERESTED_STATUS.NOT_ADDED}

-
);