-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from ChangePlusPlusVandy/admin_main_page
Scrollable Container in Main Dashboard which Displays Featured Events
- Loading branch information
Showing
10 changed files
with
199 additions
and
15 deletions.
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// FeaturedEvents.tsx | ||
import React, { Suspense, useEffect, useState } from 'react'; | ||
import { useRouter } from 'next/router'; | ||
|
||
const EventCard = React.lazy(() => import('@/components/shared/EventCard')); // Lazy loading the EventCard | ||
import { QueriedVolunteerEventData } from 'bookem-shared/src/types/database'; | ||
import { fetchData } from '@/utils/utils'; | ||
|
||
import { | ||
FeaturedEventsContainer, | ||
EventsScrollContainer, | ||
Header, | ||
Events, | ||
} from '@/styles/components/featuredEvents.styles'; // Assume you have similar styles to upcomingEvents.styles | ||
|
||
// Vertical list of sample FeaturedEvents | ||
const FeaturedEvents = () => { | ||
const [events, setEvents] = useState<QueriedVolunteerEventData[]>(); | ||
const [error, setError] = useState<Error>(); | ||
const router = useRouter(); | ||
|
||
// Fetch featured events when rendered | ||
useEffect(() => { | ||
fetchData('/api/events/featured') | ||
.then(data => setEvents(data)) | ||
.catch(err => setError(err)); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
{error && <div>404 Event not found!</div>} | ||
{!events && !error && <div>Loading...</div>} | ||
{events && ( | ||
<div style={{ marginTop: '50px' }}> | ||
<Header>Featured events</Header> | ||
<FeaturedEventsContainer> | ||
<EventsScrollContainer> | ||
<Suspense fallback={<Header>Please Wait...</Header>}> | ||
{events.map(event => ( | ||
<EventCard | ||
key={event._id.toString()} | ||
eventData={event} | ||
size={'small'} | ||
href={'/event/' + event._id} | ||
/> | ||
))} | ||
</Suspense> | ||
<button onClick={() => router.push('/event/')}>Show More</button> | ||
</EventsScrollContainer> | ||
</FeaturedEventsContainer> | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default FeaturedEvents; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,50 @@ | ||
import dbConnect from '@/lib/dbConnect'; | ||
import VolunteerEvents from 'bookem-shared/src/models/VolunteerEvents'; | ||
import Tags from 'bookem-shared/src/models/Tags'; // Replace with the actual path to your Tags model | ||
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/featured | ||
* @desc Get all events with the tag 'featured' | ||
* @res QueriedVolunteerEventData[] | ||
*/ | ||
case 'GET': | ||
try { | ||
await dbConnect(); | ||
|
||
// First, find the ObjectId for the 'featured' tag | ||
const featuredTag = await Tags.findOne({ tagName: 'featured' }); | ||
if (!featuredTag) { | ||
return res.status(404).json({ message: 'Featured tag not found.' }); | ||
} | ||
|
||
// Now, use the ObjectId to query for events | ||
const featuredEvents = await VolunteerEvents.find({ | ||
tags: featuredTag._id, // Use the ObjectId of the 'featured' tag | ||
}).sort({ startDate: 1 }); | ||
|
||
return res.status(200).json(featuredEvents); | ||
} catch (error) { | ||
console.error(error); | ||
res.status(500).json({ message: 'Failed to fetch featured events.' }); | ||
} | ||
break; | ||
|
||
// case 'POST': | ||
// case 'PUT': | ||
// case 'DELETE': | ||
default: | ||
// Inform the client about allowed methods if necessary | ||
// res.setHeader('Allow', ['GET']); // Uncomment and adjust according to supported methods | ||
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
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,69 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const EventsScrollContainer = styled.div` | ||
display: flex; | ||
overflow-x: auto; // Allows horizontal scrolling | ||
overflow-y: hidden; // Prevents vertical scrolling | ||
padding: 10px; | ||
white-space: nowrap; | ||
max-width: 100%; // Ensures the container does not exceed the viewport width | ||
width: 100%; // Optionally set a fixed width | ||
&::-webkit-scrollbar { | ||
display: none; | ||
} | ||
.event-card { | ||
display: inline-block; | ||
margin-right: 20px; | ||
background-color: #ffffff; | ||
border-radius: 10px; | ||
} | ||
`; | ||
|
||
export const FeaturedEventsContainer = styled.div` | ||
background-color: #d9d9d9; | ||
padding: 10px; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
`; | ||
|
||
/** | ||
* Header for featured events | ||
*/ | ||
export const Header = styled.p` | ||
font-size: 25px; | ||
margin-top: 0; // Assuming no top margin if it's at the start of the container | ||
text-align: left; // Align to the left based on the screenshot | ||
padding-left: 10px; // Padding to match the container | ||
`; | ||
|
||
/** | ||
* Container for list of featured events | ||
*/ | ||
export const Events = styled.ul` | ||
list-style: none; // Remove bullet points | ||
padding: 0; // Remove padding | ||
margin-top: 20px; // Space below the header | ||
`; | ||
|
||
// Additional styles for the event cards can be added here. For example: | ||
export const EventCardContainer = styled.li` | ||
background-color: #ffffff; | ||
padding: 15px; | ||
margin-bottom: 10px; // Space between cards | ||
border-radius: 8px; // Rounded corners for the cards | ||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); // Optional shadow for cards | ||
&:last-child { | ||
margin-bottom: 0; // No margin for the last card | ||
} | ||
`; | ||
|
||
// If you have a line or separator in your design, add it here | ||
export const SeparatorLine = styled.div` | ||
height: 1px; | ||
background-color: #d9d9d9; // Use a color that suits your design | ||
margin: 20px 0; | ||
`; |
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