-
Notifications
You must be signed in to change notification settings - Fork 13
elad-abutbul #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Elad-Abutbul
wants to merge
3
commits into
ColmanDevClubORG:main
Choose a base branch
from
Elad-Abutbul:elad-abutbul
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
elad-abutbul #2
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,72 +1,48 @@ | ||
| import { useState } from "react"; | ||
|
|
||
| export interface ShowCardProps { | ||
| artist: string; | ||
| stage: string; | ||
| day: string; | ||
| hour: string; | ||
| ticketsLeft: number; | ||
| image: string; | ||
| } | ||
|
|
||
| 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] = ... | ||
|
|
||
| // TODO 3: Function that toggles true/false in isInterested | ||
| // function handleToggleInterested() {} | ||
|
|
||
| // TODO 4: Create ticketsStatusText (string): | ||
| // 0 → "SOLD OUT" | ||
| // 1–30 → "Last tickets – hurry up!" | ||
| // >30 → "Tickets available" | ||
|
|
||
| // 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 🎟️" | ||
| import { getArtistPrefix, getInterestedButtonText } from "../../utils/showCardUtils"; | ||
| import {getInterestedStatusText,getTicketsStatusText} from "../../utils/showCardUtils"; | ||
| import type { Show } from "../../interfaces/show"; | ||
| import { useInterested } from "../../hooks/useInterested"; | ||
|
|
||
| export default function ShowCard({ | ||
| artist, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good work destructing those props |
||
| stage, | ||
| day, | ||
| hour, | ||
| ticketsLeft, | ||
| image, | ||
| }: Show) { | ||
|
|
||
| const { isInterested, toggleInterested } = useInterested(); | ||
|
|
||
| const ticketsStatusText = getTicketsStatusText(ticketsLeft); | ||
| const interestedText = getInterestedStatusText(isInterested); | ||
| const artistPrefix = getArtistPrefix(isInterested); | ||
| const buttonText = getInterestedButtonText(isInterested); | ||
|
|
||
| return ( | ||
| <article className="show-card"> | ||
| <div className="show-image-wrapper"> | ||
| {/* TODO 6: Replace placeholder with real <img> from props */} | ||
| {/* <img src={image} alt={artist} className="show-image" /> */} | ||
| <div className="show-image-placeholder">Image goes here</div> | ||
| <img src={image} alt={artist} className="show-image" /> | ||
| </div> | ||
|
|
||
| <header className="show-header"> | ||
| <h2 className="show-artist"> | ||
| {/* TODO 7: If isInterested → show ⭐ before artist name */} | ||
| "Artist name here" | ||
| {artistPrefix} | ||
| {artist} | ||
| </h2> | ||
| <p className="show-meta"> | ||
| {/* TODO 8: Display stage, day, hour from props */} | ||
| "Stage · Day · Hour" | ||
| {stage} · {day} · {hour} | ||
| </p> | ||
| </header> | ||
|
|
||
| <section className="show-info"> | ||
| <p className="tickets-status"> | ||
| {/* TODO 9: Display the ticketsStatusText */} | ||
| "Tickets status text" | ||
| </p> | ||
| <p className="tickets-status">{ticketsStatusText}</p> | ||
|
|
||
| <p className="interested-status"> | ||
| {/* TODO 10: Display the interestedText */} | ||
| "Interested status text" | ||
| </p> | ||
| <p className="interested-status">{interestedText}</p> | ||
| </section> | ||
|
|
||
| <button | ||
| className="interested-button" | ||
| // TODO 11: Connect onClick to handleToggleInterested function | ||
| > | ||
| {/* TODO 12: Button text: | ||
| false → "Mark as interested" | ||
| true → "Remove from my list" | ||
| */} | ||
| "Button text" | ||
| <button className="interested-button" onClick={toggleInterested}> | ||
| {buttonText} | ||
| </button> | ||
| </article> | ||
| ); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| export const SHOW_CARD_CONSTANTS = { | ||
| SOLD_OUT: "SOLD OUT", | ||
| LAST_TICKETS: "Last tickets – hurry up!", | ||
| TICKETS_AVAILABLE: "Tickets available", | ||
| YOUR_INTERESTED_LIST: "This show is in your interested list 🎟️", | ||
| NO_ADDED_SHOW: "You haven't added this show yet", | ||
| } as const; | ||
|
|
||
| export const SHOW_CARD_LIMITS = { | ||
| SOLD_OUT: 0, | ||
| LAST_TICKETS_THRESHOLD: 30, | ||
| } as const; | ||
|
|
||
| export const SHOW_CARD_BUTTON_TEXT = { | ||
| REMOVE: "Remove from my list", | ||
| ADD: "Mark as interested", | ||
| } as const; | ||
|
|
||
| export const SHOW_CARD_UI = { | ||
| INTERESTED_ICON: "⭐ ", | ||
| } as const; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { useState } from "react"; | ||
|
|
||
| export function useInterested() { | ||
| const [isInterested, setIsInterested] = useState<boolean>(false); | ||
|
|
||
| function toggleInterested() { | ||
| setIsInterested((prev) => !prev); | ||
| } | ||
|
|
||
| return { | ||
| isInterested, | ||
| toggleInterested, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export interface Show { | ||
| artist: string; | ||
| stage: string; | ||
| day: string; | ||
| hour: string; | ||
| ticketsLeft: number; | ||
| image: string; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { | ||
| SHOW_CARD_BUTTON_TEXT, | ||
| SHOW_CARD_CONSTANTS, | ||
| SHOW_CARD_LIMITS, | ||
| SHOW_CARD_UI, | ||
| } from "../constants/showCardConstants"; | ||
|
|
||
| export function getTicketsStatusText(ticketsLeft: number): string { | ||
| if (ticketsLeft === SHOW_CARD_LIMITS.SOLD_OUT) { | ||
| return SHOW_CARD_CONSTANTS.SOLD_OUT; | ||
| } | ||
| if (ticketsLeft <= SHOW_CARD_LIMITS.LAST_TICKETS_THRESHOLD) { | ||
| return SHOW_CARD_CONSTANTS.LAST_TICKETS; | ||
| } | ||
| return SHOW_CARD_CONSTANTS.TICKETS_AVAILABLE; | ||
| } | ||
|
|
||
| export function getInterestedStatusText(isInterested: boolean): string { | ||
| if (isInterested) { | ||
| return SHOW_CARD_CONSTANTS.YOUR_INTERESTED_LIST; | ||
| } | ||
| return SHOW_CARD_CONSTANTS.NO_ADDED_SHOW; | ||
| } | ||
|
|
||
| export function getArtistPrefix(isInterested: boolean): string { | ||
| return isInterested ? SHOW_CARD_UI.INTERESTED_ICON : ""; | ||
| } | ||
|
|
||
| export function getInterestedButtonText(isInterested: boolean): string { | ||
| return isInterested | ||
| ? SHOW_CARD_BUTTON_TEXT.REMOVE | ||
| : SHOW_CARD_BUTTON_TEXT.ADD; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the name of the prop is the same as what you are sending you can spread the
show objectsomething like this :Notice that I added the
keyprop, why is that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i read we use key so react can uniquely identify each component in a list and preserve the correct state between renders and the key is not passed as a prop