import { useEffect, useState } from 'preact/hooks' const endpoint = 'https://kultar.sout.no/events/' const fetch_options = {} function Link(props) { return } function Facebook({ event_id }) { const facebook_event_url = `https://facebook.com/events/${event_id}/` return ( Mer info ) } function Tickets({ ticket_url }) { return ( Kjøp billett ) } function Time({ date }) { const hasTime = date.getHours() === 0 const time_option = hasTime ? undefined : 'numeric' const options = { month: 'long', weekday: 'long', day: 'numeric', hour: time_option, minute: time_option, } return

{new Intl.DateTimeFormat('no', options).format(date)}

} function Location({ location }) { const { location: area, host } = location const hasHost = host.length !== 0 const hasArea = area.length !== 0 if (hasHost && hasArea) { return (

{host}, {area}.

) } if (hasHost) { return

{host}.

} if (hasArea) { return

{area}.

} return '' } function Links({ event_id, ticket_url }) { if (ticket_url !== null) { return ( <>  –  ) } return } function EventImage({ images }) { const { square = null } = images return ( ) } function EventCard({ event }) { const { name, location, date, ticket_url, event_id } = event let { start: start_date } = date let date_array = [] if (start_date !== null && start_date.length > 0) { date_array = start_date.split('+') const tz = date_array[1].charAt(1) start_date = [date_array[0], `0${tz}:00`].join('+') } return (

{name}

) } function Event({ event }) { const { images } = event return (
) } export default function Events() { const [events, setEvents] = useState(null) useEffect(async () => { if (events === null) { let result = [] try { const res = await fetch(endpoint, fetch_options) result = await res.json() } catch (error) { console.error(error) } setEvents(result) } }, [events]) if (events === null) { return

Laster arrangement...

} if (events.length <= 0) { return

Det er ingen fremtidige arrangement.

} return events.map((event) => ) }