Skip to content
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

completeed #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 17 additions & 188 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,78 +1,20 @@
import { useState } from "react";
import eventsData from "./data";
import { v1 as generateUniqueID } from "uuid";
// import Attendees from "./Attendees";
// import Event from "./Components/Event";
// import Footer from "./Components/Footer";
// import Header from "./Components/Header";
// import NewEventForm from "./Components/NewEventForm";
import Event from "./Components/Event";
import Footer from "./Components/Footer";
import Header from "./Components/Header";
import NewEventForm from "./Components/NewEventForm";

function App() {
const [events, setEvents] = useState(eventsData);

const [showAttendees, setShowAttendees] = useState(false);

const [selectOption, setSelectOption] = useState("");

const [newEvent, setNewEvent] = useState({
id: "",
eventType: "",
name: "",
organizer: "",
eventImage: "",
date: "",
people: [],
});

function addEvent() {
const createEvent = {
id: generateUniqueID(),
eventType: selectOption,
name: newEvent.name,
organizer: newEvent.organizer,
eventImage: newEvent.eventImage || "https://loremflickr.com/640/480/",
date: newEvent.date,
people: [],
};
handleAddEvent(createEvent);
}

function handleSelectChange(e) {
setSelectOption(e.target.value);
}

function handleSubmit(e) {
e.preventDefault();
addEvent();
resetEventForm();
}

function handleTextChange(e) {
setNewEvent({
...newEvent,
[e.target.id]: e.target.value,
});
}

function resetEventForm() {
setNewEvent({
id: "",
eventType: "",
name: "",
organizer: "",
eventImage: "",
date: "",
});
setSelectOption("");
}
const [events, setEvents] = useState(eventsData.map((event) => ({ ...event, showAttendees: false }))
);


function handleAddEvent(event) {
setEvents([event, ...events]);
}

function toggleEventAttendees() {
setShowAttendees(!showAttendees);
}


function updateEventAttendance(eventId, attendeeId) {
const eventArray = [...events];
Expand All @@ -88,133 +30,20 @@ function App() {
setEvents(eventArray);
}

function updateEvents(updateEvents) {
setEvents(updateEvents);
}

return (
<div className="App">
<>
<header>
<h1 className="color-change-5x">RSVP App</h1>
</header>
</>
<Header />
<main>
<div className="new-event">
<>
<form onSubmit={handleSubmit}>
<h3>Create a new event</h3>
<label htmlFor="name">Event name:</label>
<input
type="text"
id="name"
onChange={handleTextChange}
value={newEvent.name}
/>

<label htmlFor="organizer">Organizer:</label>
<input
type="text"
id="organizer"
onChange={handleTextChange}
value={newEvent.organizer}
/>

<label htmlFor="eventImage">Event image:</label>
<input
type="text"
id="eventImage"
onChange={handleTextChange}
value={newEvent.eventImage}
/>
<label htmlFor="eventType">Event type:</label>
<select id="eventType" onChange={handleSelectChange}>
<option value=""></option>
<option value="Birthday">Birthday</option>
<option value="Anniversary">Anniversary</option>
<option value="Intramural Sport">Intramural Sport</option>
<option value="Watch Party">Watch Party</option>
<option value="wedding">Wedding</option>
</select>
<br />
<input type="submit" />
</form>
</>
</div>
<div className="events">
<ul>
{events.map((event) => {
const { people: attendees } = event;

return (
<>
<li key={event.id}>
<img src={event.eventImage} alt={event.name} />
<h5>
{event.name} {event.eventType}
</h5>
<br />
<span>Organized by: {event.organizer} </span>
<br />
<>
<button onClick={toggleEventAttendees}>
{!showAttendees ? "Show Attendees" : "Hide Attendees"}
</button>

{showAttendees ? (
<div className="attendees">
{attendees.map((attendee, index) => (
<>
<div key={attendee.id} className="attendee">
<p>
<img
src={attendee.avatar}
alt={attendee.firstName}
/>
{" "}
<span>
{" "}
{attendee.firstName} {attendee.lastName}{" "}
</span>
</p>
<p>
<button
className="clickable"
onClick={() =>
updateEventAttendance(
event.id,
attendee.id
)
}
>
Attending:
</button>
<span>
{attendee.attendance ? "✅" : "❌"}
</span>
</p>

<p>
<span>Note:</span> {attendee.note}
</p>
</div>
</>
))}
</div>
) : null}
</>
</li>
</>
);
})}
</ul>
<NewEventForm handleAddEvent={handleAddEvent} />
</div>
</main>
<>
<footer>
<ul>
<li>Contact</li>
<li>About</li>
<li>Legal</li>
</ul>
</footer>
</>
<Event events={events} updateEvents={updateEvents} updateEventAttendance={updateEventAttendance} />
</main>
<Footer />
</div>
);
}
Expand Down
28 changes: 26 additions & 2 deletions src/Components/Attendee.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
export default function Attendee() {
return;
export default function Attendee({ attendee, eventId, updateEventAttendance}) {
return (
<div key={attendee.id} className="attendee">
<p>
<img src={attendee.avatar} alt={attendee.firstName} />
{" "}
<span>
{" "}
{attendee.firstName} {attendee.lastName}{" "}
</span>
</p>
<p>
<button
className="clickable"
onClick={() => updateEventAttendance(eventId, attendee.id)}
>
Attending:
</button>
<span>{attendee.attendance ? "✅" : "❌"}</span>
</p>

<p>
<span>Note:</span> {attendee.note}
</p>
</div>
);
}
26 changes: 24 additions & 2 deletions src/Components/Attendees.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
export default function Attendees() {
return;
import Attendee from "./Attendee";

export default function Attendees({
updateEventAttendance,
showAttendees,
attendees,
eventId,
}) {
return (
<>
{showAttendees ? (
<div className="attendees">
{attendees.map((attendee, index) => (
<Attendee
key={attendee.id}
attendee={attendee}
eventId={eventId}
updateEventAttendance={updateEventAttendance}
/>
))}
</div>
) : null}
</>
);
}
46 changes: 44 additions & 2 deletions src/Components/Event.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
export default function Event() {
return;
import Attendees from "./Attendees";

export default function Event({ events, updateEvents, updateEventAttendance }) {
const toggleEventAttendees = (id) => {
const updatedEvents = events.map((event) => {
if (event.id === id) {
return { ...event, showAttendees: !event.showAttendees };
}
return event;
});
updateEvents(updatedEvents);
};

return (
<div className="events">
<ul>
{events.map((event) => {

return (
<li key={event.id}>
<img src={event.eventImage} alt={event.name} />
<h5>
{event.name} {event.eventType}
</h5>
<br />
<span>Organized by: {event.organizer} </span>
<br />
<button onClick={() => toggleEventAttendees(event.id)}>
{!event.showAttendees ? "Show Attendees" : "Hide Attendees"}
</button>
{event.showAttendees && (
<Attendees
attendees={event.people}
updateEventAttendance={updateEventAttendance}
showAttendees={event.showAttendees}
eventId={event.id}
/>
)}
</li>
);
})}
</ul>
</div>
);
}
10 changes: 9 additions & 1 deletion src/Components/Footer.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
export default function Footer() {
return;
return (
<footer>
<ul>
<li>Contact</li>
<li>About</li>
<li>Legal</li>
</ul>
</footer>
);
}
4 changes: 3 additions & 1 deletion src/Components/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export default function Header() {
return;
return (
<h1 className="color-change-5x">RSVP App</h1>
);
}
Loading