-
Notifications
You must be signed in to change notification settings - Fork 0
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
Past activities el #62
Merged
Merged
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
dc49eb3
msg
7cc57e1
msg2
402657e
adding past activities
a4a91fd
replaced past activities with 5 real data and added show more button
97bf06a
prettier
7560919
Revert changes to package.json
JiashuHarryHuang 9988554
prettier
JiashuHarryHuang d3533ae
Change the back arrow to history.back()
JiashuHarryHuang d995bd3
moved slicing to backend
b9be155
forgot mobile
2aa2151
Merge branch 'main' into past-activities-EL
JiashuHarryHuang fcf97ec
Revert changes to package-lock
JiashuHarryHuang 176fc6d
Revert changes to pid.tsx'
JiashuHarryHuang aa72b1f
Merge branch 'main' into past-activities-EL
JiashuHarryHuang 5c2be01
Merge branch 'main' into past-activities-EL
JiashuHarryHuang e47d6c5
changed books distributed to date joined, addressed past activities r…
1dde5ec
Fix mobile
JiashuHarryHuang 10630c5
Modified scripts to generate more events
JiashuHarryHuang d27a67b
Update sign up logic
JiashuHarryHuang 1778c8e
Add comments
JiashuHarryHuang bb64311
Edit API name
JiashuHarryHuang 99ff84a
Use Arrow function to refactor
JiashuHarryHuang 2cc62b5
Clean up
JiashuHarryHuang a440a2f
Remove massive comments
JiashuHarryHuang 5741124
Revert package-lock.json
JiashuHarryHuang 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 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
This file contains 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,5 +1,6 @@ | ||
import React, { Suspense, useState } from 'react'; | ||
import React, { Suspense, useState, useEffect } from 'react'; | ||
import mongoose from 'mongoose'; | ||
import { useRouter } from 'next/router'; | ||
import { Media } from '@/lib/media'; | ||
import { QueriedVolunteerEventData } from 'bookem-shared/src/types/database'; | ||
import Image from 'next/image'; | ||
|
@@ -14,34 +15,30 @@ import { | |
Events, | ||
} from '@/styles/components/pastActivity.styles'; | ||
|
||
/** | ||
* Dummy data for event cards | ||
*/ | ||
const dummyEventData: QueriedVolunteerEventData = { | ||
_id: new mongoose.Types.ObjectId(), | ||
name: 'Distribute books (BNFK)', | ||
description: 'blablabla', | ||
startDate: new Date('2005-12-17T13:24:00'), | ||
endDate: new Date('2005-12-17T13:24:00'), | ||
maxSpot: 11, | ||
location: { | ||
street: '3593 Cedar Rd', | ||
city: 'Nashville', | ||
}, | ||
phone: '123-456-7890', | ||
email: '[email protected]', | ||
program: new mongoose.Types.ObjectId(), | ||
requireApplication: true, | ||
volunteers: [], | ||
tags: [], | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}; | ||
|
||
// vertical list of sample PastEvents | ||
const PastActivity = ({ userData }: any) => { | ||
// state for hiding/showing mobile Past Activities | ||
const [onMobileHide, setOnMobileHide] = useState(false); | ||
const [events, setEvents] = useState<QueriedVolunteerEventData[]>(); | ||
const [error, setError] = useState<Error>(); | ||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
// Assuming your API endpoint for past activities is '/api/pastActivities' | ||
fetch('/api/events/past') | ||
.then(response => response.json()) | ||
.then(data => { | ||
setEvents(data); // Set the activities in state | ||
}) | ||
.catch(error => { | ||
console.error('Error fetching past activities:', error); | ||
}); | ||
}, []); | ||
|
||
const showMoreHandler = () => { | ||
// Navigate to the volunteerHistory page | ||
router.push('/volunteerHistory'); // Replace with your actual path to the volunteerHistory page | ||
}; | ||
|
||
return ( | ||
<> | ||
|
@@ -52,16 +49,24 @@ const PastActivity = ({ userData }: any) => { | |
|
||
<Events> | ||
{/* if PastEvents aren't loading in yet, component will display "Please Wait..." */} | ||
{/* display the retrieved past*/} | ||
<Suspense fallback={<Header>Please Wait...</Header>}> | ||
{/* TODO: integrate with backend */} | ||
<EventCard eventData={dummyEventData} size="small" /> | ||
<EventCard eventData={dummyEventData} size="small" /> | ||
<EventCard eventData={dummyEventData} size="small" /> | ||
<EventCard eventData={dummyEventData} size="small" /> | ||
<EventCard eventData={dummyEventData} size="small" /> | ||
<EventCard eventData={dummyEventData} size="small" /> | ||
<Container> | ||
{events && | ||
events.map(event => ( | ||
// Iterate through events to and pass data to EventCard | ||
<EventCard | ||
key={event._id.toString()} | ||
eventData={event} | ||
size={'large'} | ||
href={'/event/' + event._id} | ||
/> | ||
))} | ||
</Container> | ||
</Suspense> | ||
</Events> | ||
<button onClick={showMoreHandler}>Show More</button> | ||
</Container> | ||
</Media> | ||
|
||
|
@@ -94,12 +99,18 @@ const PastActivity = ({ userData }: any) => { | |
{/* if PastEvents aren't loading in yet, component will display "Please Wait..." */} | ||
<Suspense fallback={<Header>Please Wait...</Header>}> | ||
{/* TODO: integrate with backend */} | ||
<EventCard eventData={dummyEventData} size="small" /> | ||
<EventCard eventData={dummyEventData} size="small" /> | ||
<EventCard eventData={dummyEventData} size="small" /> | ||
<EventCard eventData={dummyEventData} size="small" /> | ||
<EventCard eventData={dummyEventData} size="small" /> | ||
<EventCard eventData={dummyEventData} size="small" /> | ||
<Container> | ||
{events && | ||
events.map(event => ( | ||
// Iterate through events to and pass data to EventCard | ||
<EventCard | ||
key={event._id.toString()} | ||
eventData={event} | ||
size={'large'} | ||
href={'/event/' + event._id} | ||
/> | ||
))} | ||
</Container> | ||
</Suspense> | ||
</Events> | ||
</Container> | ||
|
This file contains 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
This file contains 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,40 @@ | ||
import dbConnect from '@/lib/dbConnect'; | ||
import VolunteerEvents from 'bookem-shared/src/models/VolunteerEvents'; | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
// Get request method | ||
const { method } = req; | ||
|
||
switch (method) { | ||
/** | ||
* @route GET /api/events/past | ||
* @desc Get all events in the past | ||
* @res QueriedVolunteerEventData[] | ||
*/ | ||
case 'GET': | ||
try { | ||
await dbConnect(); | ||
// Select all events where eventDate > today order by progamDate ascending | ||
const events = await VolunteerEvents.find({ | ||
endDate: { $lt: new Date() }, | ||
}).sort({ endDate: 1 }); | ||
return res.status(200).json(events.slice(0, 5)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just get five rather than getting all events and choose five. Use the |
||
} catch (error) { | ||
console.error(error); | ||
res.status(500).json({ message: error }); | ||
} | ||
break; | ||
|
||
// case 'POST': | ||
// case 'PUT': | ||
// case 'DELETE': | ||
default: | ||
// res.setHeader('Allow', ['GET', 'PUT', 'DELETE', 'POST']); | ||
res.status(405).end(`Method ${method} Not Allowed`); | ||
break; | ||
} | ||
} |
This file contains 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
Oops, something went wrong.
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.
Use fetchData() helper function. Refer to pages/event/[pid].tsx