import React, { useState, useEffect } from 'react'
function filterEvent (past = false) {
return (event) => {
const date = new Date(event.time)
return past ? date < new Date() : date > new Date()
}
}
const EVENTS_URL = 'https://events.webdriver.io/api/events'
const DEFAULT_PHOTO = 'https://events.webdriver.io/webdriverio.png'
export function Host ({ name, photo, social }) {
return (
{name}
)
}
export function EventDetails ({ event: eventInput }: any) {
/**
* re-fetch event data to get the latest sign-ups
*/
const [event, setEvent] = useState(eventInput)
useEffect(() => {
/**
* except the event has no signup, we don't need to re-fetch the data
*/
if (!eventInput.signup) {
return
}
fetch(EVENTS_URL).then(async (res) => {
const events = await res.json()
setEvent(events.find((e) => e.id === eventInput.id))
}).catch((err) => {
console.log(err)
})
}, [])
/**
* only show attendee list if event has a signup
*/
const attendeeList = event.signup
? <>👥 Attendees: {event.signups} ({event.maxattendees - event.signups} spots left)
>
: <>>
const dateMerged = new Date(event.time)
return (
<>
📅 Date: {dateMerged.toDateString()}
⏰ Time: {dateMerged.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true })} {new Date().toTimeString().slice(9)}
📍 Location: {event.location} (Google Maps)
{attendeeList}
🎤 Hosts: {JSON.parse(event.hosts).map((host, i) => (
Loading...
} const upcomingEvents = events.filter(filterEvent()) const pastEvents = events.filter(filterEvent(true)) return (No upcoming events
} {upcomingEvents.map((event) => ( ))}No past events!
} {pastEvents.map((event) => { const date = new Date(event.time) return ( {event.title} - {date.toDateString()} ) })}We would love to see you at the event. Please make sure to rsvp to secure your spot.
* We will store your email only for the purpose of communicating with you in case we need to send information on the event, e.g. eventual cancellations or instruction on how to enter the venue. All data will be removed after the event.
> ) }