|
1 | | -import React, { useEffect } from 'react'; |
| 1 | +import React, { useEffect, useState } from 'react'; |
2 | 2 | import { makeStyles } from '@material-ui/styles'; |
3 | 3 | import { Button, Card, Grid, Typography } from '@material-ui/core'; |
| 4 | +import { useSelector } from 'react-redux'; |
| 5 | +import { firebase } from 'src/services/authService'; |
4 | 6 |
|
5 | 7 | const useStyles = makeStyles(() => ({ |
6 | 8 | root: { |
@@ -62,101 +64,82 @@ const useStyles = makeStyles(() => ({ |
62 | 64 |
|
63 | 65 | function NewEvents() { |
64 | 66 | const classes = useStyles(); |
65 | | - useEffect(() => {}, []); |
| 67 | + const user = useSelector(state => state.account.user); |
| 68 | + const [attendingEvent, setAttendingEvent] = useState([]); |
| 69 | + |
| 70 | + const readIds = async (collection, ids) => { |
| 71 | + const reads = ids.map(id => collection.doc(id).get()); |
| 72 | + const result = await Promise.all(reads); |
| 73 | + return result.map(r => r.data()); |
| 74 | + }; |
| 75 | + |
| 76 | + useEffect(() => { |
| 77 | + const fetchAttendingEvents = async () => { |
| 78 | + if (user === undefined || user === null) return; |
| 79 | + |
| 80 | + const userID = user.uid; |
| 81 | + const db = firebase.firestore(); |
| 82 | + const userRef = await db.collection('users').doc(userID); |
| 83 | + userRef.get().then(doc => { |
| 84 | + if (doc.exists) { |
| 85 | + let data = doc.data(); |
| 86 | + readIds(db.collection('events'), data.attending).then(result => |
| 87 | + setAttendingEvent(result) |
| 88 | + ); |
| 89 | + } |
| 90 | + }); |
| 91 | + }; |
| 92 | + fetchAttendingEvents(); |
| 93 | + }, [user]); |
| 94 | + |
| 95 | + const handleClick = link => { |
| 96 | + if (link.length <= 0) return; |
| 97 | + const win = window.open(`${link}`, '_blank'); |
| 98 | + win.focus(); |
| 99 | + }; |
| 100 | + |
66 | 101 | return ( |
67 | 102 | <Card className={classes.root}> |
68 | 103 | <Grid container> |
69 | 104 | <Grid item className={classes.topContainer}> |
70 | 105 | <Typography variant="h1" className={classes.topText}> |
71 | | - New Events |
| 106 | + Attending Events |
72 | 107 | </Typography> |
73 | 108 | </Grid> |
74 | 109 | </Grid> |
75 | 110 | <Grid container className={classes.event}> |
76 | | - <Grid className={classes.eventText}> |
77 | | - <img |
78 | | - style={{ borderRadius: '8px' }} |
79 | | - src=".././static/images/icons/event.svg" |
80 | | - alt="event" |
81 | | - /> |
82 | | - <Grid className={classes.eventInfo}> |
83 | | - <Typography variant="h5">Intro to Open Source</Typography> |
84 | | - <div style={{ display: 'flex' }}> |
85 | | - <Typography variant="subtitle2" className={classes.eventDate}> |
86 | | - 16 Jan 2021 (2 days left) |
87 | | - </Typography> |
88 | | - </div> |
89 | | - <Button |
90 | | - variant="contained" |
91 | | - style={{ backgroundColor: 'white' }} |
92 | | - className={classes.rsvp} |
93 | | - > |
94 | | - <img |
95 | | - src=".././static/images/icons/event_calendar.svg" |
96 | | - alt="rsvp" |
97 | | - height="12px" |
98 | | - style={{ marginRight: '6px' }} |
99 | | - /> |
100 | | - RSVP |
101 | | - </Button> |
102 | | - </Grid> |
103 | | - </Grid> |
104 | | - <Grid className={classes.eventText}> |
105 | | - <img |
106 | | - style={{ borderRadius: '8px' }} |
107 | | - src=".././static/images/icons/event.svg" |
108 | | - alt="event" |
109 | | - /> |
110 | | - <Grid className={classes.eventInfo}> |
111 | | - <Typography variant="h5">Intro to Open Source</Typography> |
112 | | - <div style={{ display: 'flex' }}> |
113 | | - <Typography variant="subtitle2" className={classes.eventDate}> |
114 | | - 16 Jan 2021 (2 days left) |
115 | | - </Typography> |
116 | | - </div> |
117 | | - <Button |
118 | | - variant="contained" |
119 | | - style={{ backgroundColor: 'white' }} |
120 | | - className={classes.rsvp} |
121 | | - > |
122 | | - <img |
123 | | - src=".././static/images/icons/event_calendar.svg" |
124 | | - alt="rsvp" |
125 | | - height="12px" |
126 | | - style={{ marginRight: '6px' }} |
127 | | - /> |
128 | | - RSVP |
129 | | - </Button> |
130 | | - </Grid> |
131 | | - </Grid> |
132 | | - <Grid className={classes.eventText}> |
133 | | - <img |
134 | | - style={{ borderRadius: '8px' }} |
135 | | - src=".././static/images/icons/event.svg" |
136 | | - alt="event" |
137 | | - /> |
138 | | - <Grid className={classes.eventInfo}> |
139 | | - <Typography variant="h5">Intro to Open Source</Typography> |
140 | | - <div style={{ display: 'flex' }}> |
141 | | - <Typography variant="subtitle2" className={classes.eventDate}> |
142 | | - 16 Jan 2021 (2 days left) |
143 | | - </Typography> |
144 | | - </div> |
145 | | - <Button |
146 | | - variant="contained" |
147 | | - style={{ backgroundColor: 'white' }} |
148 | | - className={classes.rsvp} |
149 | | - > |
| 111 | + {attendingEvent.length > 0 && |
| 112 | + attendingEvent.map((event, idx) => ( |
| 113 | + <Grid key={idx} className={classes.eventText}> |
150 | 114 | <img |
151 | | - src=".././static/images/icons/event_calendar.svg" |
152 | | - alt="rsvp" |
153 | | - height="12px" |
154 | | - style={{ marginRight: '6px' }} |
| 115 | + style={{ borderRadius: '8px', width: '74px', height: '71px' }} |
| 116 | + src={event.bannerImg} |
| 117 | + alt="event" |
155 | 118 | /> |
156 | | - RSVP |
157 | | - </Button> |
158 | | - </Grid> |
159 | | - </Grid> |
| 119 | + <Grid className={classes.eventInfo}> |
| 120 | + <Typography variant="h5">{event.eventName}</Typography> |
| 121 | + <div style={{ display: 'flex' }}> |
| 122 | + <Typography variant="subtitle2" className={classes.eventDate}> |
| 123 | + {event.date} |
| 124 | + </Typography> |
| 125 | + </div> |
| 126 | + <Button |
| 127 | + variant="contained" |
| 128 | + style={{ backgroundColor: 'white' }} |
| 129 | + className={classes.rsvp} |
| 130 | + onClick={() => handleClick(`${event.eventLink}`)} |
| 131 | + > |
| 132 | + <img |
| 133 | + src=".././static/images/icons/event_calendar.svg" |
| 134 | + alt="rsvp" |
| 135 | + height="12px" |
| 136 | + style={{ marginRight: '6px' }} |
| 137 | + /> |
| 138 | + RSVP |
| 139 | + </Button> |
| 140 | + </Grid> |
| 141 | + </Grid> |
| 142 | + ))} |
160 | 143 | </Grid> |
161 | 144 | </Card> |
162 | 145 | ); |
|
0 commit comments