Skip to content

Commit

Permalink
Fix recently attended events (#133)
Browse files Browse the repository at this point in the history
* Fix recently attended events

* Improve some code

---------

Co-authored-by: Faris Ashai <[email protected]>
  • Loading branch information
raymosun and farisashai authored Feb 7, 2024
1 parent 3b0f64e commit 380ac23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
17 changes: 10 additions & 7 deletions src/components/profile/UserProfilePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export interface UserProfilePageProps {
handleUser: PublicProfile;
isSignedInUser: boolean;
signedInAttendances: PublicAttendance[];
attendances?: PublicAttendance[];
recentAttendances?: PublicAttendance[];
}

export const UserProfilePage = ({
handleUser,
attendances,
recentAttendances,
signedInAttendances,
isSignedInUser,
}: UserProfilePageProps) => {
Expand Down Expand Up @@ -143,7 +143,7 @@ export const UserProfilePage = ({
</div>
)}
</div>
{(attendances || isSignedInUser) && (
{(recentAttendances || isSignedInUser) && (
<div className={styles.section}>
<Typography variant="h2/bold">
Recently Attended Events
Expand All @@ -154,16 +154,19 @@ export const UserProfilePage = ({
)}
</Typography>
<Carousel>
{(isSignedInUser ? signedInAttendances : (attendances as PublicAttendance[])).map(
({ event }) => (
{(isSignedInUser
? signedInAttendances.slice(-10)
: (recentAttendances as PublicAttendance[])
)
.reverse()
.map(({ event }) => (
<EventCard
className={styles.card}
key={event.uuid}
event={event}
attended={signedInAttendances.some(({ event: { uuid } }) => uuid === event.uuid)}
/>
)
)}
))}
</Carousel>
</div>
)}
Expand Down
8 changes: 5 additions & 3 deletions src/pages/u/[handle].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,19 @@ const getServerSidePropsFunc: GetServerSideProps = async ({ params, req, res })

const isSignedInUser = handleUser.uuid === user.uuid;

let attendances = null;
let recentAttendances = null;
if (!isSignedInUser && handleUser.isAttendancePublic)
attendances = (await UserAPI.getAttendancesForUserByUUID(token, user.uuid)).slice(0, 10);
recentAttendances = (await UserAPI.getAttendancesForUserByUUID(token, handleUser.uuid)).slice(
-10
);

// render UserProfilePage
return {
props: {
handleUser,
isSignedInUser,
signedInAttendances,
attendances,
recentAttendances,
},
};
} catch (err: any) {
Expand Down

0 comments on commit 380ac23

Please sign in to comment.