Skip to content

Commit

Permalink
gg
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfyh committed Jul 14, 2024
1 parent 5f67535 commit b6b6982
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
44 changes: 36 additions & 8 deletions web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ const Sidebar: React.FC<SidebarProps> = ({
userId: localStorage.getItem("user_id"),
}
);

onEventCreated();
} catch (error) {
console.log("Error: ", error);
}
Expand Down Expand Up @@ -215,6 +217,22 @@ const Sidebar: React.FC<SidebarProps> = ({
getEvents();
}, [selectedMarker, data]);

async function handleOptOut() {
try {
await axios.post(
`${import.meta.env.VITE_SERVER_URL}/api/event/remove-attendee`,

{
eventId: selectedEvent._id,
userId: localStorage.getItem("user_id"),
}
);
onEventCreated();
} catch (error) {
console.log("Error: ", error);
}
}

return (
<div className="sidebar">
{selectedMarker ? (
Expand Down Expand Up @@ -277,14 +295,24 @@ const Sidebar: React.FC<SidebarProps> = ({
<p>{formatDate(selectedEvent.date)}</p>
<p>{selectedEvent.description}</p>
</div>
{isUser && (
<button
className="bg-navy text-primary font-semibold text-xl w-full rounded-xl py-3 mt-auto"
onClick={handleInterestedEvent}
>
INTERESTED
</button>
)}
{isUser &&
(selectedEvent.atendees.includes(user) ? (
// User is attending
<button
className="bg-navy text-primary font-semibold text-xl w-full rounded-xl py-3 mt-auto"
onClick={handleOptOut}
>
Opt Out
</button>
) : (
// User is not attending, show the interested button
<button
className="bg-navy text-primary font-semibold text-xl w-full rounded-xl py-3 mt-auto"
onClick={handleInterestedEvent}
>
Attend Event!
</button>
))}
</div>
) : (
<div className="flex flex-col h-full text-left">
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const Home: React.FC = () => {
`${import.meta.env.VITE_SERVER_URL}/api/location/`
);
setData(response.data);
console.log(response.data);
// console.log(response.data);
} catch (err) {
console.error("Error fetching data:", err);
// Handle error
Expand Down

0 comments on commit b6b6982

Please sign in to comment.