-
Notifications
You must be signed in to change notification settings - Fork 1
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 #627 from nwplus/daniel/attended-events
Attended Events component
- Loading branch information
Showing
8 changed files
with
245 additions
and
17 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,83 @@ | ||
import styled, { useTheme } from 'styled-components' | ||
import { TagLegendContainer, TagLegends } from '../Schedule/Tag' | ||
import { H1 } from '../Typography' | ||
import AttendedEventsCard from './AttendedEventsCard' | ||
import { EVENT_TYPES } from '../Schedule/Constants' | ||
import { getEvents } from '../../utility/firebase' | ||
import { useHackathon } from '../../utility/HackathonProvider' | ||
import { useEffect } from 'react' | ||
import { useState } from 'react' | ||
|
||
const AttendedEventsContainer = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.75em; | ||
` | ||
|
||
const AttendedEventsHeader = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
` | ||
|
||
const TagLegendsContainer = styled(TagLegendContainer)` | ||
justify-content: start; | ||
padding-right: 0; | ||
` | ||
|
||
const EventsList = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.75em; | ||
overflow-y: scroll; | ||
width: 85%; | ||
${p => p.theme.mediaQueries.mobile} { | ||
width: 100%; | ||
} | ||
` | ||
|
||
const AttendedEvents = ({ userDetails }) => { | ||
const { dbHackathonName } = useHackathon() | ||
const theme = useTheme() | ||
const event_type = EVENT_TYPES(theme) | ||
const [events, setEvents] = useState([]) | ||
|
||
useEffect(() => { | ||
// prettier insisted on the semicolon | ||
;(async () => { | ||
if (userDetails && dbHackathonName) { | ||
console.log(userDetails) | ||
const eventIds = userDetails.dayOf.events.map(event => event.eventId) | ||
const events = await getEvents(dbHackathonName) | ||
const filteredEvents = events.filter(event => eventIds.includes(event.key)) | ||
setEvents(filteredEvents) | ||
} | ||
})() | ||
}, [userDetails, dbHackathonName]) | ||
|
||
return ( | ||
<AttendedEventsContainer> | ||
<AttendedEventsHeader> | ||
<H1>Attended events</H1> | ||
<TagLegendsContainer> | ||
<TagLegends theme={theme} /> | ||
</TagLegendsContainer> | ||
</AttendedEventsHeader> | ||
{userDetails && ( | ||
<EventsList> | ||
{events.map((event, i) => ( | ||
<AttendedEventsCard | ||
key={i} | ||
name={event.title} | ||
time={new Date(event.date.seconds * 1000).toLocaleString()} | ||
points={event.points} | ||
color={event_type[event.type]?.colour ?? 'gray'} | ||
/> | ||
))} | ||
</EventsList> | ||
)} | ||
</AttendedEventsContainer> | ||
) | ||
} | ||
|
||
export default AttendedEvents |
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,86 @@ | ||
import styled from 'styled-components' | ||
import { StyledSVG } from '../Schedule/Tag' | ||
import { P } from '../Typography' | ||
import Icon from '../../assets/checkmark.svg?react' | ||
|
||
const AttendedEventsCardContainer = styled.div` | ||
display: flex; | ||
align-items: center; | ||
gap: 1em; | ||
color: ${p => p.theme.colors.cardText}; | ||
background: ${p => p.theme.colors.backgroundTertiary}; | ||
border-radius: 5px; | ||
padding: 0.875em 1em; | ||
` | ||
|
||
const EventDetailsContainer = styled.div` | ||
flex-grow: 1; | ||
display: flex; | ||
justify-content: space-between; | ||
gap: 2em; | ||
align-items: center; | ||
` | ||
|
||
const TagPointsContainer = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
align-items: end; | ||
` | ||
|
||
const CheckmarkSVG = styled(Icon)` | ||
fill: ${props => props.color}; | ||
${p => p.theme.mediaQueries.mobile} { | ||
height: 0.75em; | ||
width: 0.75em; | ||
} | ||
` | ||
|
||
const EventDetails = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
` | ||
|
||
const EventName = styled(P)` | ||
margin: 0; | ||
font-weight: 700; | ||
` | ||
|
||
const EventTime = styled(P)` | ||
margin: 0; | ||
font-size: 0.875em; | ||
` | ||
|
||
const PointsText = styled(P)` | ||
font-weight: 700; | ||
color: ${props => props.color}; | ||
font-size: 0.875em; | ||
margin: 0; | ||
` | ||
|
||
/** | ||
* @typedef {{name: string, time: string, points: number, color: string}} AttendedEventsCardProps | ||
*/ | ||
|
||
/** | ||
* @param {AttendedEventsCardProps} param0 | ||
*/ | ||
const AttendedEventsCard = ({ name, time, points, color }) => { | ||
return ( | ||
<AttendedEventsCardContainer> | ||
<CheckmarkSVG color={color} /> | ||
<EventDetailsContainer> | ||
<EventDetails> | ||
<EventName>{name}</EventName> | ||
<EventTime>{time}</EventTime> | ||
</EventDetails> | ||
<TagPointsContainer> | ||
<StyledSVG color={color} /> | ||
<PointsText color={color}>{points} pts earned</PointsText> | ||
</TagPointsContainer> | ||
</EventDetailsContainer> | ||
</AttendedEventsCardContainer> | ||
) | ||
} | ||
|
||
export default AttendedEventsCard |
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 |
---|---|---|
@@ -1,3 +1,49 @@ | ||
const Rewards = () => {} | ||
import styled from 'styled-components' | ||
import AttendedEvents from '../components/Rewards/AttendedEvents' | ||
import { useAuth } from '../utility/Auth' | ||
import { getUserApplication } from '../utility/firebase' | ||
import { useHackathon } from '../utility/HackathonProvider' | ||
import { useState } from 'react' | ||
import { useEffect } from 'react' | ||
|
||
const RewardsContainer = styled.div` | ||
display: flex; | ||
height: 100%; | ||
width: 100%; | ||
${p => p.theme.mediaQueries.mobile} { | ||
flex-direction: column; | ||
} | ||
` | ||
|
||
const RewardsSummaryContainer = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
flex-basis: 35%; | ||
flex-shrink: 0; | ||
` | ||
|
||
const RewardsContentContainer = styled.div`` | ||
|
||
const Rewards = () => { | ||
const { user } = useAuth() | ||
const { dbHackathonName } = useHackathon() | ||
const [userDetails, setUserDetails] = useState(null) | ||
|
||
useEffect(() => { | ||
getUserApplication(user.uid, dbHackathonName).then(user => { | ||
setUserDetails(user) | ||
}) | ||
}, [user, dbHackathonName]) | ||
|
||
return ( | ||
<RewardsContainer> | ||
<RewardsSummaryContainer> | ||
<AttendedEvents userDetails={userDetails} /> | ||
</RewardsSummaryContainer> | ||
<RewardsContentContainer></RewardsContentContainer> | ||
</RewardsContainer> | ||
) | ||
} | ||
|
||
export default Rewards |
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