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 (
-
- );
+ return (
+
+ );
}
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}{' '}
- {
- artists.splice(artist.id, 1)
- }}>
- Delete
-
-
- ))}
-
- >
- );
+ 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}{' '}
+ handleDeleteArtist(artist.id)}>
+ Delete
+
+
+ ))}
+
+ >
+ );
}
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}
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
-
-
-
- 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}
+
Profession: {person.profession}
+
Accomplishment: {person.accomplishment}
+
+
+ ));
+
return ;
-}
\ 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 (
-
- {children}
-
- );
+function AButton({ id, color, size, children }) {
+ const handleClick = () => {
+ document.getElementById(`${id}`).style.backgroundColor = color;
+ document.getElementById(`${id}`).style.fontSize = size;
+ };
+
+ return (
+
+ {children}
+
+ );
}
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
- ;
+export default function Profile() {
+ return (
+
+ );
}
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 (
-
+
);
}
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}
-
-
- Buy
-
- >
- );
+ return (
+ <>
+ Pending: {pending}
+ Completed: {completed}
+ Buy
+ >
+ );
}
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}
- {
- setNumber(number + 5);
- alert(number);
- }}>+5
- >
- )
+ return (
+ <>
+ {number}
+ {
+ setNumber(prevNumber => prevNumber + 5); // Use functional update
+ alert(number); // This will show the previous value of number
+ }}>+5
+ >
+ )
}
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 (
- <>
-
- Next
-
-
- {sculpture.name}
- by {sculpture.artist}
-
-
- ({index + 1} of {sculptureList.length})
-
-
- {showMore ? 'Hide' : 'Show'} details
-
- {showMore && {sculpture.description}
}
-
- >
- );
-}
\ No newline at end of file
+ const sculpture = sculptureList[index];
+
+ return (
+ <>
+
+ {index === sculptureList.length - 1 ? 'Restart' : 'Next'}
+
+
+ {sculpture.name} by {sculpture.artist}
+
+
+ ({index + 1} of {sculptureList.length})
+
+
+ {showMore ? 'Hide details' : 'Show details'}
+
+ {showMore && {sculpture.description}
}
+
+ >
+ );
+}
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 (
-
- );
+ return (
+
+ );
}
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 (
-
+
+ Send
+
);
}
-}
\ No newline at end of file
+}
diff --git a/src/pages/qcomps/todos.js b/src/pages/qcomps/todos.js
index 99713488..0ec5d72f 100644
--- a/src/pages/qcomps/todos.js
+++ b/src/pages/qcomps/todos.js
@@ -1,22 +1,24 @@
+import React from 'react';
+
const baseUrl = 'https://i.imgur.com/';
const person = {
- name: 'Gregorio Y. Zara',
- imageId: '7vQD0fP',
- imageSize: 's',
- theme: {
- backgroundColor: 'black',
- color: 'pink'
- }
+ name: 'Gregorio Y. Zara',
+ imageId: '7vQD0fP',
+ imageSize: 's',
+ theme: {
+ backgroundColor: 'black',
+ color: 'pink'
+ }
};
export default function TodoList() {
- return (
-
-
Person Name's Todos
-
-
- );
+ const { name, imageId, imageSize, theme } = person;
+ const imageUrl = `${baseUrl}${imageId}${imageSize}.jpg`;
+
+ return (
+
+
{name}'s Todos
+
+
+ );
}
diff --git a/src/pages/qcomps/updObjectsForm.js b/src/pages/qcomps/updObjectsForm.js
index c0df1e82..bee73e69 100644
--- a/src/pages/qcomps/updObjectsForm.js
+++ b/src/pages/qcomps/updObjectsForm.js
@@ -8,7 +8,10 @@ export default function Scoreboard() {
});
function handlePlusClick() {
- player.likescore++;
+ setPlayer(prevPlayer => ({
+ ...prevPlayer,
+ likescore: prevPlayer.likescore + 1,
+ }));
}
function handleFirstNameChange(e) {
@@ -20,33 +23,32 @@ export default function Scoreboard() {
function handleLastNameChange(e) {
setPlayer({
- lastName: e.target.value
+ ...player,
+ lastName: e.target.value,
});
}
return (
- <>
-
- Like Score: {player.likescore}
- {' '}
-
- +1
-
-
-
- First name:
-
-
-
- Last name:
-
-
- >
+ <>
+
+ Like Score: {player.likescore}
+ {' '}
+ +1
+
+
+ First name:
+
+
+
+ Last name:
+
+
+ >
);
}