diff --git a/README.md b/README.md index 891dcb4d..f8827421 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## Personal Information: -Full Name: Enter Your Full Name +Full Name: Ankur Haritosh ## Getting Started First, fork this repository and clone it to your local machine. @@ -43,4 +43,4 @@ To learn more about React.js, take a look at the [React Documentation](https://l ## What to Submit? -Submit all changes made to files in `src/pages/qcomps` in Canvas class activity for the day. \ No newline at end of file +Submit all changes made to files in `src/pages/qcomps` in Canvas class activity for the day. diff --git a/src/pages/qcomps/arrObj.js b/src/pages/qcomps/arrObj.js index 68d5e9c5..19efde7b 100644 --- a/src/pages/qcomps/arrObj.js +++ b/src/pages/qcomps/arrObj.js @@ -1,73 +1,57 @@ -import { useState } from 'react'; +import React, { useState } from 'react'; -let nextId = 3; const initialList = [ - { id: 0, title: 'Big Bellies', seen: false }, - { id: 1, title: 'Lunar Landscape', seen: false }, - { id: 2, title: 'Terracotta Army', seen: true }, + { id: 0, title: 'Big Bellies', seen: false }, + { id: 1, title: 'Lunar Landscape', seen: false }, + { id: 2, title: 'Terracotta Army', seen: true }, ]; export default function BucketList() { - const [myList, setMyList] = useState(initialList); - const [yourList, setYourList] = useState( - initialList - ); + const [myList, setMyList] = useState(initialList); + const [yourList, setYourList] = useState(initialList); - function handleToggleMyList(artworkId, nextSeen) { - const tmpList = myList.map(e => { - if (e.id === artworkId) { - e.seen = nextSeen - } - return e - }); - setMyList(tmpList); - } + function handleToggleMyList(artworkId, nextSeen) { + const updatedList = myList.map(item => + item.id === artworkId ? { ...item, seen: nextSeen } : item + ); + setMyList(updatedList); + } - function handleToggleYourList(artworkId, nextSeen) { - const tmpList = yourList.map(e => { - if (e.id === artworkId) { - e.seen = nextSeen - } - return e - }); - setYourList(tmpList); - } + function handleToggleYourList(artworkId, nextSeen) { + const updatedList = yourList.map(item => + item.id === artworkId ? { ...item, seen: nextSeen } : item + ); + setYourList(updatedList); + } - return ( - <> -

Art Bucket List

-

My list of art to see:

- -

Your list of art to see:

- - - ); + return ( + <> +

Art Bucket List

+

My list of art to see:

+ +

Your list of art to see:

+ + + ); } function ItemList({ artworks, onToggle }) { - return ( -
    - {artworks.map(artwork => ( -
  • - -
  • - ))} -
- ); + return ( +
    + {artworks.map(artwork => ( +
  • + +
  • + ))} +
+ ); } diff --git a/src/pages/qcomps/artistsRemoveArr.js b/src/pages/qcomps/artistsRemoveArr.js index 5c4709f5..0f48b5bd 100644 --- a/src/pages/qcomps/artistsRemoveArr.js +++ b/src/pages/qcomps/artistsRemoveArr.js @@ -1,31 +1,33 @@ -import { useState } from 'react'; +import React, { useState } from 'react'; let initialArtists = [ - { id: 0, name: 'Marta Colvin Andrade' }, - { id: 1, name: 'Lamidi Olonade Fakeye'}, - { id: 2, name: 'Louise Nevelson'}, + { id: 0, name: 'Marta Colvin Andrade' }, + { id: 1, name: 'Lamidi Olonade Fakeye'}, + { id: 2, name: 'Louise Nevelson'}, ]; export default function List() { - const [artists, setArtists] = useState( - initialArtists - ); + const [artists, setArtists] = useState(initialArtists); - return ( - <> -

Inspiring sculptors:

-
    - {artists.map(artist => ( -
  • - {artist.name}{' '} - -
  • - ))} -
- - ); + const handleDeleteArtist = (artistId) => { + // Create a new array with the artist removed + const updatedArtists = artists.filter(artist => artist.id !== artistId); + setArtists(updatedArtists); + }; + + return ( + <> +

Inspiring sculptors:

+
    + {artists.map(artist => ( +
  • + {artist.name}{' '} + +
  • + ))} +
+ + ); } diff --git a/src/pages/qcomps/bios.js b/src/pages/qcomps/bios.js index cc9350fd..e1bfa649 100644 --- a/src/pages/qcomps/bios.js +++ b/src/pages/qcomps/bios.js @@ -1,12 +1,14 @@ +import React from 'react'; + export default function Bio() { return ( -
-

Welcome to my website!

-
-

- You can find my thoughts here. -

- And pictures of people! -

+
+

Welcome to my website!

+

+ You can find my thoughts here. +

+ And pictures of people! +

+
); -} \ No newline at end of file +} diff --git a/src/pages/qcomps/firstcomp.js b/src/pages/qcomps/firstcomp.js index 9cce715e..bc77fe5a 100644 --- a/src/pages/qcomps/firstcomp.js +++ b/src/pages/qcomps/firstcomp.js @@ -1 +1,12 @@ -function MyComp() {} \ No newline at end of file +import React from 'react'; + +function MyComp() { + return ( +
+

Hello from MyComp!

+

This is a simple functional component.

+
+ ); +} + +export default MyComp; diff --git a/src/pages/qcomps/gallery_props.js b/src/pages/qcomps/gallery_props.js index fc118123..c62bbcf4 100644 --- a/src/pages/qcomps/gallery_props.js +++ b/src/pages/qcomps/gallery_props.js @@ -1,55 +1,58 @@ -export default function Gallery() { +import React from 'react'; + +const scientistsData = [ + { + name: 'Maria Skłodowska-Curie', + imageUrl: 'https://i.imgur.com/szV5sdGs.jpg', + profession: 'physicist and chemist', + awards: ['Nobel Prize in Physics', 'Nobel Prize in Chemistry', 'Davy Medal', 'Matteucci Medal'], + discovery: 'polonium (element)' + }, + { + name: 'Katsuko Saruhashi', + imageUrl: 'https://i.imgur.com/YfeOqp2s.jpg', + profession: 'geochemist', + awards: ['Miyake Prize for geochemistry', 'Tanaka Prize'], + discovery: 'a method for measuring carbon dioxide in seawater' + } +]; + +function ScientistProfile({ scientist }) { return ( -
-

Notable Scientists

-

Maria Skłodowska-Curie

+

{scientist.name}

Maria Skłodowska-Curie
  • Profession: - physicist and chemist + {scientist.profession}
  • - Awards: 4 - (Nobel Prize in Physics, Nobel Prize in Chemistry, Davy Medal, Matteucci Medal) + Awards: + {scientist.awards.join(', ')}
  • Discovered: - polonium (element) + {scientist.discovery}
-
-

Katsuko Saruhashi

- Katsuko Saruhashi -
    -
  • - Profession: - geochemist -
  • -
  • - Awards: 2 - (Miyake Prize for geochemistry, Tanaka Prize) -
  • -
  • - Discovered: - a method for measuring carbon dioxide in seawater -
  • -
-
-
+ ); +} + +export default function Gallery() { + return ( +
+

Notable Scientists

+ {scientistsData.map((scientist, index) => ( + + ))} +
); } diff --git a/src/pages/qcomps/list_keys_id.js b/src/pages/qcomps/list_keys_id.js index f10c9b88..bd9e4b97 100644 --- a/src/pages/qcomps/list_keys_id.js +++ b/src/pages/qcomps/list_keys_id.js @@ -1,3 +1,5 @@ +import React from 'react'; + export const people = [{ id: 0, name: 'Creola Katherine Johnson', @@ -13,12 +15,25 @@ export const people = [{ }]; function getImageUrl(imageId) { - return "https://i.imgur.com/" + imageId + "s.jpg" + return "https://i.imgur.com/" + imageId + "s.jpg" } + export default function List() { - const listItems = people.map(person => -
  • -
  • - ); + const listItems = people.map(person => ( +
  • + {person.name} +
    +

    {person.name}

    +

    Profession: {person.profession}

    +

    Accomplishment: {person.accomplishment}

    +
    +
  • + )); + return
      {listItems}
    ; -} \ No newline at end of file +} diff --git a/src/pages/qcomps/menuBar.js b/src/pages/qcomps/menuBar.js index 0fb8894e..c52b46db 100644 --- a/src/pages/qcomps/menuBar.js +++ b/src/pages/qcomps/menuBar.js @@ -1,24 +1,27 @@ +import React from 'react'; + export default function MenuBar() { - return ( -
    - - Button 1 - - - Button 2 - -
    - ); + return ( +
    + + Button 1 + + + Button 2 + +
    + ); } -function AButton() { - const handleClick = () => { - document.getElementById(`${id}`).style.backgroundColor = color; - document.getElementById(`${id}`).style.fontSize = size; - } - return ( - - ); +function AButton({ id, color, size, children }) { + const handleClick = () => { + document.getElementById(`${id}`).style.backgroundColor = color; + document.getElementById(`${id}`).style.fontSize = size; + }; + + return ( + + ); } diff --git a/src/pages/qcomps/profile_mistake.js b/src/pages/qcomps/profile_mistake.js index ac318d70..f2a3fd7d 100644 --- a/src/pages/qcomps/profile_mistake.js +++ b/src/pages/qcomps/profile_mistake.js @@ -1,4 +1,5 @@ -export default function profile() { - return - Katsuko Saruhashi; +export default function Profile() { + return ( + Katsuko Saruhashi + ); } diff --git a/src/pages/qcomps/props_item.js b/src/pages/qcomps/props_item.js index 79a9e151..2b8ccd43 100644 --- a/src/pages/qcomps/props_item.js +++ b/src/pages/qcomps/props_item.js @@ -2,27 +2,27 @@ function Item({ name, isPacked }) { if (isPacked) { return
  • {name} ✔
  • ; } - return
  • {name}
  • + return
  • {name}
  • ; } export default function PackingList() { return ( -
    -

    My Packing List

    -
      - - - -
    -
    +
    +

    My Packing List

    +
      + + + +
    +
    ); } diff --git a/src/pages/qcomps/recipes.js b/src/pages/qcomps/recipes.js index 37803925..100bd847 100644 --- a/src/pages/qcomps/recipes.js +++ b/src/pages/qcomps/recipes.js @@ -1,22 +1,23 @@ -export const recipes = [{ - id: 'greek-salad', - name: 'Greek Salad', - ingredients: new Set(['tomatoes', 'cucumber', 'onion', 'olives', 'feta']) -}, { - id: 'hawaiian-pizza', - name: 'Hawaiian Pizza', - ingredients: new Set(['pizza crust', 'pizza sauce', 'mozzarella', 'ham', 'pineapple']) -}, { - id: 'hummus', - name: 'Hummus', - ingredients: new Set(['chickpeas', 'olive oil', 'garlic cloves', 'lemon', 'tahini']) -}]; +import React from 'react'; +import { recipes } from './recipes'; // Import the recipes array export default function RecipeList() { return ( -
    -

    Recipes

    - {} -
    +
    +

    Recipes

    +
      + {recipes.map(recipe => ( +
    • +

      {recipe.name}

      +

      Ingredients:

      +
        + {Array.from(recipe.ingredients).map((ingredient, index) => ( +
      • {ingredient}
      • + ))} +
      +
    • + ))} +
    +
    ); -} \ No newline at end of file +} diff --git a/src/pages/qcomps/shoppingCart.js b/src/pages/qcomps/shoppingCart.js index d26decf8..b9adbe78 100644 --- a/src/pages/qcomps/shoppingCart.js +++ b/src/pages/qcomps/shoppingCart.js @@ -1,33 +1,27 @@ import { useState } from 'react'; export default function RequestTracker() { - const [pending, setPending] = useState(0); - const [completed, setCompleted] = useState(0); + const [pending, setPending] = useState(0); + const [completed, setCompleted] = useState(0); - async function handleClick() { - setPending(pending + 1); - await delay(3000); - setPending(pending - 1); - setCompleted(completed + 1); - } + async function handleClick() { + setPending(prevPending => prevPending + 1); // Update pending using functional form + await delay(3000); + setPending(prevPending => prevPending - 1); // Update pending using functional form + setCompleted(prevCompleted => prevCompleted + 1); // Update completed using functional form + } - return ( - <> -

    - Pending: {pending} -

    -

    - Completed: {completed} -

    - - - ); + return ( + <> +

    Pending: {pending}

    +

    Completed: {completed}

    + + + ); } function delay(ms) { - return new Promise(resolve => { - setTimeout(resolve, ms); - }); -} \ No newline at end of file + return new Promise(resolve => { + setTimeout(resolve, ms); + }); +} diff --git a/src/pages/qcomps/snapshot.js b/src/pages/qcomps/snapshot.js index 2c3c9801..5bd06c4a 100644 --- a/src/pages/qcomps/snapshot.js +++ b/src/pages/qcomps/snapshot.js @@ -1,15 +1,15 @@ import { useState } from 'react'; export default function Counter() { - const [number, setNumber] = useState(0); + const [number, setNumber] = useState(0); - return ( - <> -

    {number}

    - - - ) + return ( + <> +

    {number}

    + + + ) } diff --git a/src/pages/qcomps/state.js b/src/pages/qcomps/state.js index 35953a6a..e2b9eafc 100644 --- a/src/pages/qcomps/state.js +++ b/src/pages/qcomps/state.js @@ -1,39 +1,40 @@ -import { useState } from 'react'; +import React, { useState } from 'react'; import { sculptureList } from '../../data/data.js'; export default function Gallery() { - const [index, setIndex] = useState(0); - const [showMore, setShowMore] = useState(false); + const [index, setIndex] = useState(0); + const [showMore, setShowMore] = useState(false); - function handleNextClick() { - setIndex(index + 1); - } + function handleNextClick() { + const newIndex = index + 1; + setIndex(newIndex >= sculptureList.length ? 0 : newIndex); + } - function handleMoreClick() { - setShowMore(!showMore); - } + function handleMoreClick() { + setShowMore(!showMore); + } - let sculpture = sculptureList[index]; - return ( - <> - -

    - {sculpture.name} - by {sculpture.artist} -

    -

    - ({index + 1} of {sculptureList.length}) -

    - - {showMore &&

    {sculpture.description}

    } - {sculpture.alt} - - ); -} \ No newline at end of file + const sculpture = sculptureList[index]; + + return ( + <> + +

    + {sculpture.name} by {sculpture.artist} +

    +

    + ({index + 1} of {sculptureList.length}) +

    + + {showMore &&

    {sculpture.description}

    } + {sculpture.alt} + + ); +} diff --git a/src/pages/qcomps/stuckForm.js b/src/pages/qcomps/stuckForm.js index 7cc952e0..977ed8e2 100644 --- a/src/pages/qcomps/stuckForm.js +++ b/src/pages/qcomps/stuckForm.js @@ -1,36 +1,36 @@ -import { useState } from 'react'; +import React, { useState } from 'react'; export default function Form() { - let firstName = ''; - let lastName = ''; + const [firstName, setFirstName] = useState(''); + const [lastName, setLastName] = useState(''); - function handleFirstNameChange(e) { - firstName = e.target.value; - } + function handleFirstNameChange(e) { + setFirstName(e.target.value); + } - function handleLastNameChange(e) { - lastName = e.target.value; - } + function handleLastNameChange(e) { + setLastName(e.target.value); + } - function handleReset() { - firstName = ''; - lastName = ''; - } + function handleReset() { + setFirstName(''); + setLastName(''); + } - return ( -
    e.preventDefault()}> - - -

    Hi, {firstName} {lastName}

    - -
    - ); + return ( +
    e.preventDefault()}> + + +

    Hi, {firstName} {lastName}

    + +
    + ); } diff --git a/src/pages/qcomps/thankYouCrash.js b/src/pages/qcomps/thankYouCrash.js index 07e1ba52..4e219442 100644 --- a/src/pages/qcomps/thankYouCrash.js +++ b/src/pages/qcomps/thankYouCrash.js @@ -1,26 +1,26 @@ -import { useState } from 'react'; +import React, { useState } from 'react'; export default function FeedbackForm() { const [isSent, setIsSent] = useState(false); + const [message, setMessage] = useState(''); + if (isSent) { return

    Thank you!

    ; } else { - // eslint-disable-next-line - const [message, setMessage] = useState(''); return ( -
    { - e.preventDefault(); - alert(`Sending: "${message}"`); - setIsSent(true); - }}> + { + e.preventDefault(); + alert(`Sending: "${message}"`); + setIsSent(true); + }}>