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
const { start: start_date } = date
return (
{name}
)
}
function Event({ event, index }) {
const isFirstEvent = index === 0
const { images } = event
return (
)
}
export default function Events() {
const [events, setEvents] = useState(null)
useEffect(async () => {
const res = await fetch(endpoint, fetch_options)
const result = await res.json()
setEvents(result)
}, [])
if (events === null) {
return Laster arrangement...
}
if (events.length <= 0) {
return Det er ingen fremtidige arrangement.
}
return (
{events.map((event, index) => (
<>
>
))}
)
}