Skip to content

Commit

Permalink
Fixed EventsGrid
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavberi committed Oct 30, 2024
1 parent 1ac9788 commit 0682208
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 122 deletions.
1 change: 0 additions & 1 deletion src/components/events/EventCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Link from "next/link";
import { Box, Card, CardActionArea, Typography, Stack } from "@mui/material";

import EventPoster from "components/events/EventPoster";
// import EventFallbackPoster from "components/events/EventFallbackPoster";

const DateTime = dynamic(() => import("components/DateTime"), { ssr: false });

Expand Down
156 changes: 72 additions & 84 deletions src/components/events/EventsGrid.jsx
Original file line number Diff line number Diff line change
@@ -1,99 +1,87 @@
import { getClient } from "gql/client";
import { GET_CLUB_EVENTS, GET_ALL_EVENTS } from "gql/queries/events";
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";


export default async function EventsGrid({
type = "all", // must be one of: {recent, club, all}
clubid = null,
limit = undefined,
filter = () => true,
events = null,
type = "all", // must be one of: {recent, club, all}
clubid = null,
limit = undefined,
filter = () => true,
events = null,
}) {
let data;
if (events) {
data = { data: { events } };
} else {
data = await getClient().query(...constructQuery({ type, clubid, limit }));
}
let data;
if (events) {
data = { data: { events } };
} else {
data = await getClient().query(...constructQuery({ type, clubid, limit }));
}

const updatedEvents = await Promise.all(
data?.data?.events?.map(async (event) => {
if (!event.poster || event.poster == null) {
const { data: { club } = {} } = await getClient().query(GET_CLUB, {
clubInput: { cid: event?.clubid },
});
event.clubbanner = club?.banner || null;
}
return event;
})
);
const updatedEvents = await Promise.all(
data?.data?.events?.map(async (event) => {
if (!event.poster || event.poster == null) {
const { data: { club } = {} } = await getClient().query(GET_CLUB, {
clubInput: { cid: event?.clubid },
});
event.clubbanner = club?.banner || club?.logo;
}
return event;
})
);

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>
);
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>
);
}

// construct graphql query based on type
function constructQuery({ type, clubid, limit }) {
if (type === "recent") {
return [
GET_ALL_EVENTS,
{
clubid: null,
limit: limit || 12,
public: true,
},
];
} else if (type === "club") {
return [
GET_CLUB_EVENTS,
{
clubid,
clubInput: {
cid: clubid,
},
public: true,
},
];
} else if (type === "all") {
return [
GET_ALL_EVENTS,
{
clubid: null,
public: true,
},
];
} else {
throw new Error("Invalid event type");
}
if (type === "recent") {
return [
GET_ALL_EVENTS,
{
clubid: null,
limit: limit || 12,
public: true,
},
];
} else if (type === "club") {
return [
GET_ALL_EVENTS,
{
clubid,
public: true,
},
];
} else {
throw new Error("Invalid event type");
}
}
37 changes: 0 additions & 37 deletions src/components/events/EventsGridPage.jsx

This file was deleted.

0 comments on commit 0682208

Please sign in to comment.