This repository was archived by the owner on Oct 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
React week2/amin #62
Open
Amin1245
wants to merge
2
commits into
HackYourFuture-CPH:main
Choose a base branch
from
Amin1245:react-week2/amin
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
React week2/amin #62
Changes from 1 commit
Commits
Show all changes
2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import styles from "./destination.module.css"; | ||
|
|
||
| export default function PlanetCard({ | ||
| name, | ||
| description, | ||
| thumbnail, | ||
| isSelected, | ||
| onAddOrRemovePlanet, | ||
| }) { | ||
| return ( | ||
| <div className={styles.planetCard}> | ||
| <img className={styles.planetThumbnail} src={thumbnail} alt={name} /> | ||
| <div className={styles.planetDescription}> | ||
| <h2> | ||
| {name.toUpperCase()} {isSelected ? "- SELECTED" : ""} | ||
| </h2> | ||
| <p>{description}</p> | ||
| </div> | ||
| <button className="roundButton" onClick={() => onAddOrRemovePlanet(name)}> | ||
| {isSelected ? "REMOVE" : "ADD PLANET"} | ||
| </button> | ||
| </div> | ||
| ); | ||
| } |
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,25 @@ | ||
| .planetGrid { | ||
| display: grid; | ||
| grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); | ||
| gap: 1.5rem; | ||
| margin-top: 1rem; | ||
| } | ||
|
|
||
| .planetCard { | ||
| background-color: #14213d; | ||
| color: white; | ||
| padding: 1rem; | ||
| border-radius: 8px; | ||
| text-align: center; | ||
| box-shadow: 0 4px 10px rgba(0,0,0,0.2); | ||
| } | ||
|
|
||
| .planetThumbnail { | ||
| width: 100%; | ||
| max-width: 180px; | ||
| border-radius: 4px; | ||
| } | ||
|
|
||
| .planetDescription { | ||
| margin: 1rem 0; | ||
| } | ||
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,24 @@ | ||
| const destinations = [ | ||
| { | ||
| name: "Europa", | ||
| description: "Europa is an icy moon of Jupiter with a hidden ocean.", | ||
| thumbnail: "/destination/image-europa.png" | ||
| }, | ||
| { | ||
| name: "Moon", | ||
| description: "The Moon is Earth's natural satellite and our closest neighbor.", | ||
| thumbnail: "/destination/image-moon.png" | ||
| }, | ||
| { | ||
| name: "Mars", | ||
| description: "Mars is the red planet with dusty landscapes and big dreams.", | ||
| thumbnail: "/destination/image-mars.png" | ||
| }, | ||
| { | ||
| name: "Titan", | ||
| description: "Titan is Saturn's largest moon, with a thick atmosphere and methane lakes.", | ||
| thumbnail: "/destination/image-titan.png" | ||
| } | ||
| ]; | ||
|
|
||
| export default destinations; |
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,114 +1,51 @@ | ||
| "use client"; | ||
|
|
||
| import { useState } from 'react'; | ||
|
|
||
| import styles from '@/components/destination/destination.module.css'; | ||
| import { AddWishlistItem } from '@/components/destination/AddWishlistItem'; | ||
|
|
||
| // TASK - React 1 week 2 | ||
| // Move this to its own file | ||
| const PlanetWishlistItem = ({ | ||
| name, | ||
| onRemove, | ||
| thumbnail, | ||
| }) => { | ||
| return ( | ||
| <div className={styles.wishlistItem}> | ||
| <img className={styles.wishlistItemThumbnail} src={thumbnail} alt="" /> | ||
| <b>{name.toUpperCase()}</b> | ||
| <button onClick={onRemove}>remove</button> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| export const Destinations = () => { | ||
| const [selectedPlanets, onAddPlanet] = useState([]); | ||
|
|
||
| let isPlanetSelected = false; | ||
| let numberOfPlanets = 0; | ||
|
|
||
| const onAddOrRemovePlanet = (name, index) => { | ||
| // TASK - React 1 week 2 | ||
| // Implement this function | ||
| // If you press the "ADD PLANET" the selected planet should display "SELECTED" | ||
| // And the counter should update, how many planets are selected (numberOfPlanets) | ||
| console.log(`You seleceted the following planet: ${name}, with the index of ${index}`); | ||
| } | ||
| import { useState } from "react"; | ||
| import destinations from "@/./app/destination/destinations"; | ||
| import PlanetCard from "@/app/destination/PlanetCard"; | ||
| import styles from "@/app/destination/destination.module.css"; | ||
|
|
||
| export default function DestinationsPage() { | ||
| const [selectedPlanets, setSelectedPlanets] = useState([]); | ||
|
|
||
| const onAddOrRemovePlanet = (name) => { | ||
| if (selectedPlanets.includes(name)) { | ||
| setSelectedPlanets(selectedPlanets.filter((planet) => planet !== name)); | ||
| } else { | ||
| setSelectedPlanets([...selectedPlanets, name]); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="fullBGpicture"> | ||
| <main className="mainContent"> | ||
| <h1>Travel destinations</h1> | ||
| <h1>Travel Destinations</h1> | ||
|
|
||
| <section className="card"> | ||
| <h2>Wishlist</h2> | ||
| {/* TASK - React 1 week 2 */} | ||
| {/* Display the number Of selected planets */} | ||
| {/* Display the "no planets" message if it is empty! */} | ||
| <p>No planets in wishlist :(</p> | ||
| <p>You have {numberOfPlanets} in your wishlist</p> | ||
| <b>List coming soon after lesson 3!</b> | ||
|
|
||
| {/* STOP! - this is for week 3!*/} | ||
| {/* TASK - React 1 week 3 */} | ||
| {/* Import the AddWishlistItem react component */} | ||
| {/* <AddWishlistItem /> */} | ||
| {/* TASK - React 1 week 3 */} | ||
| {/* Convert the list, so it is using selectedPlanets.map() to display the items */} | ||
| {/* Implement the "REMOVE" function */} | ||
| {/* uncomment the following code snippet: */} | ||
| {/* | ||
| <h3>Your current wishlist</h3> | ||
| <div className={styles.wishlistList}> | ||
| <PlanetWishlistItem | ||
| name="europa" | ||
| onRemove={() => removeFromWishlist('europa')} | ||
| thumbnail="/destination/image-europa.png" | ||
| /> | ||
| <PlanetWishlistItem | ||
| name="europa" | ||
| onRemove={() => removeFromWishlist('europa')} | ||
| thumbnail="/destination/image-europa.png" | ||
| /> | ||
| </div> */} | ||
| {selectedPlanets.length === 0 ? ( | ||
| <p>No planets in wishlist :(</p> | ||
| ) : ( | ||
| <p>You have {selectedPlanets.length} in your wishlist</p> | ||
| )} | ||
| </section> | ||
|
|
||
| <section className="card"> | ||
| <h2>Possible destinations</h2> | ||
| {/* TASK - React 1 week 2 */} | ||
| {/* Add all 4 planets! Europa, Moon, Mars, Titan */} | ||
| {/* Use the README.md file for descriptions */} | ||
| {/* Create a <PlanetCard /> component, which accepts the following properties: */} | ||
| {/* name, description, thumbnail, isSelected, onAddOrRemovePlanet */} | ||
| <div className={styles.planetCard}> | ||
| <img className={styles.planetThumbnail} src="/destination/image-europa.png" alt="" /> | ||
| <div className={styles.planetDescription}> | ||
| <h2>EUROPA {isPlanetSelected ? "- SELECTED" : ""}</h2> | ||
| <p>Lorem ipsum...</p> | ||
| </div> | ||
| <button | ||
| className="roundButton" | ||
| onClick={() => onAddOrRemovePlanet('Pluto', 0)} | ||
| > | ||
| {isPlanetSelected ? "REMOVE" : "ADD PLANET"} | ||
| </button> | ||
| </div> | ||
| <div className={styles.planetCard}> | ||
| <img className={styles.planetThumbnail} src="/destination/image-europa.png" alt="" /> | ||
| <div className={styles.planetDescription}> | ||
| <h2>EUROPA {isPlanetSelected ? "- SELECTED" : ""}</h2> | ||
| <p>Lorem ipsum...</p> | ||
| </div> | ||
| <button | ||
| className="roundButton" | ||
| onClick={() => onAddOrRemovePlanet('Pluto', 0)} | ||
| > | ||
| {isPlanetSelected ? "REMOVE" : "ADD PLANET"} | ||
| </button> | ||
| <h2>Possible Destinations</h2> | ||
| <div className={styles.planetGrid}> | ||
| {destinations.map((planet) => ( | ||
| <PlanetCard | ||
| key={planet.name} | ||
| name={planet.name} | ||
| description={planet.description} | ||
| thumbnail={planet.thumbnail} | ||
| isSelected={selectedPlanets.includes(planet.name)} | ||
| onAddOrRemovePlanet={onAddOrRemovePlanet} | ||
| /> | ||
| ))} | ||
| </div> | ||
| </section> | ||
| </main> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default Destinations; |
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.
CSS class names should be kebab case. It does not affect functionality but since it's the convention used among developers, it's better to follow it here as well 😉