Skip to content

Commit

Permalink
Serparate out eventCards rendering as a new component
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavberi committed Oct 31, 2024
1 parent 1c425b6 commit e586dd1
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 125 deletions.
64 changes: 64 additions & 0 deletions src/components/events/EventCards.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Grid, Typography, CircularProgress, Box } from "@mui/material";
import EventCard from "components/events/EventCard";

export function EventCards({
events,
loading,
noEventsMessage,
loadingIndicator = true,
}) {
if (loading) {
return (
<Box
display="flex"
justifyContent="center"
alignItems="center"
height="100%"
mt={3}
>
{loadingIndicator ? <CircularProgress /> : null}
</Box>
);
}

return (
<Grid container spacing={2}>
{events?.length ? (
events.map((event) => (
<Grid key={event._id} item xs={6} md={4} lg={3}>
<EventCard
_id={event._id}
name={event.name}
datetimeperiod={event.datetimeperiod}
poster={event.poster || event.clubbanner}
clubid={event.clubid}
blur={event.poster ? 0 : 0.3}
/>
</Grid>
))
) : (
<Typography
variant="h4"
color="text.secondary"
sx={{ flexGrow: 1, textAlign: "center", mt: 5 }}
>
{noEventsMessage}
</Typography>
)}
</Grid>
);
}

export function LoadingIndicator() {
return (
<Box
display="flex"
justifyContent="center"
alignItems="center"
height="100%"
mt={3}
>
<CircularProgress />
</Box>
);
}
35 changes: 6 additions & 29 deletions src/components/events/EventsGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { getClient } from "gql/client";
import { GET_ALL_EVENTS } from "gql/queries/events";
import { GET_CLUB } from "gql/queries/clubs";

import { Grid, Typography } from "@mui/material";
import EventCard from "components/events/EventCard";
import { EventCards } from "./EventCards";

export default async function EventsGrid({
type = "all", // must be one of: {recent, club, all}
Expand Down Expand Up @@ -32,33 +31,11 @@ export default async function EventsGrid({
);

return (
<Grid container spacing={2}>
{updatedEvents?.filter(filter).length ? (
updatedEvents
?.slice(0, limit)
?.filter(filter)
?.map((event) => (
<Grid key={event._id} item xs={6} md={4} lg={3}>
<EventCard
_id={event._id}
name={event.name}
datetimeperiod={event.datetimeperiod}
poster={event.poster || event.clubbanner}
clubid={event.clubid}
blur={event.poster ? 0 : 0.3}
/>
</Grid>
))
) : (
<Typography
variant="h4"
color="text.secondary"
sx={{ flexGrow: 1, textAlign: "center", mt: 5 }}
>
No events found.
</Typography>
)}
</Grid>
<EventCards
events={updatedEvents?.filter(filter)?.slice(0, limit)}
loading={false}
noEventsMessage="No events found."
/>
);
}

Expand Down
114 changes: 18 additions & 96 deletions src/components/events/PaginatedEventGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

import { useEffect, useState, useCallback, useRef } from "react";
import {
Box,
Grid,
Typography,
Divider,
CircularProgress,
} from "@mui/material";
import EventCard from "components/events/EventCard";
import { EventCards, LoadingIndicator } from "./EventCards";

export default function PaginatedEventGrid({
limit = 24, // Default limit if pagination is enabled
Expand Down Expand Up @@ -196,30 +193,11 @@ export default function PaginatedEventGrid({
Ongoing Events
</Typography>
</Divider>
<Grid container spacing={2}>
{futureEvents?.filter(ongoingEventsFilter)?.length ? (
futureEvents?.filter(ongoingEventsFilter)?.map((event) => (
<Grid key={event._id} item xs={6} md={4} lg={3}>
<EventCard
_id={event._id}
name={event.name}
datetimeperiod={event.datetimeperiod}
poster={event.poster || event.clubbanner}
clubid={event.clubid}
blur={event.poster ? 0 : 0.3}
/>
</Grid>
))
) : (
<Typography
variant="h4"
color="text.secondary"
sx={{ flexGrow: 1, textAlign: "center", mt: 5 }}
>
{loadingFuture ? <CircularProgress /> : "No events found."}
</Typography>
)}
</Grid>
<EventCards
events={futureEvents.filter(ongoingEventsFilter)}
loading={loadingFuture}
noEventsMessage="No events found."
/>

{targetState?.includes("upcoming") && (
<>
Expand All @@ -228,38 +206,11 @@ export default function PaginatedEventGrid({
Upcoming Events
</Typography>
</Divider>
<Grid container spacing={2}>
{futureEvents?.filter(upcomingEventsFilter)?.length ? (
futureEvents?.filter(upcomingEventsFilter)?.map((event) => (
<Grid key={event._id} item xs={6} md={4} lg={3}>
<EventCard
_id={event._id}
name={event.name}
datetimeperiod={event.datetimeperiod}
poster={event.poster || event.clubbanner}
clubid={event.clubid}
blur={event.poster ? 0 : 0.3}
/>
</Grid>
))
) : (
<Typography
variant="h4"
color="text.secondary"
sx={{ flexGrow: 1, textAlign: "center", mt: 5 }}
>
{loadingFuture ? (
targetState?.includes("completed") ? (
<CircularProgress />
) : (
""
)
) : (
"No events found."
)}
</Typography>
)}
</Grid>
<EventCards
events={futureEvents.filter(upcomingEventsFilter)}
loading={loadingFuture}
noEventsMessage="No events found."
/>
</>
)}

Expand All @@ -270,47 +221,18 @@ export default function PaginatedEventGrid({
Completed Events
</Typography>
</Divider>
<Grid container spacing={2}>
{completedevents?.length ? (
completedevents?.map((event) => (
<Grid key={event._id} item xs={6} md={4} lg={3}>
<EventCard
_id={event._id}
name={event.name}
datetimeperiod={event.datetimeperiod}
poster={event.poster || event.clubbanner}
clubid={event.clubid}
blur={event.poster ? 0 : 0.3}
/>
</Grid>
))
) : (
<Typography
variant="h4"
color="text.secondary"
sx={{ flexGrow: 1, textAlign: "center", mt: 5 }}
>
{loadingPast ? "" : "No events found."}
</Typography>
)}
</Grid>
<EventCards
events={completedevents}
loading={loadingPast}
loadingIndicator={false}
noEventsMessage="No events found."
/>
</>
)}

{/* "Load more" trigger */}
<div ref={loadMoreRef} style={{ height: "50px", marginBottom: "10px" }}>
{loadingPast && (
// center the circular progress
<Box
display="flex"
justifyContent="center"
alignItems="center"
height="100%"
mt={3}
>
<CircularProgress />
</Box>
)}
{loadingPast && <LoadingIndicator />}
</div>
</>
);
Expand Down

0 comments on commit e586dd1

Please sign in to comment.