2022-01-09 12:11:24 +01:00
|
|
|
import { displayEvents, displayErrorMessage } from './events-displayer.js'
|
|
|
|
import * as GraphqlWrapper from './graphql-wrapper.js'
|
2021-01-08 14:08:40 +01:00
|
|
|
|
2021-04-04 18:03:05 +02:00
|
|
|
const NAME = '<wordpress-name>'
|
2021-01-08 14:08:40 +01:00
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2021-01-15 20:30:05 +01:00
|
|
|
const eventLists = document.getElementsByClassName(NAME + '_events-list')
|
2021-11-01 20:57:34 +01:00
|
|
|
for (const list of eventLists) {
|
2021-01-15 20:30:05 +01:00
|
|
|
const url = list.getAttribute('data-url') + '/api'
|
2021-04-04 18:03:05 +02:00
|
|
|
const limit = parseInt(list.getAttribute('data-maximum'))
|
2021-01-15 20:30:05 +01:00
|
|
|
const groupName = list.getAttribute('data-group-name')
|
|
|
|
if (groupName) {
|
|
|
|
GraphqlWrapper.getUpcomingEventsByGroupName({ url, limit, groupName })
|
2021-05-05 10:02:57 +02:00
|
|
|
.then((data) => displayEvents({ data, document, list }))
|
|
|
|
.catch((data) => displayErrorMessage({ data, list }))
|
2021-01-15 20:30:05 +01:00
|
|
|
} else {
|
|
|
|
GraphqlWrapper.getUpcomingEvents({ url, limit })
|
2021-05-05 10:02:57 +02:00
|
|
|
.then((data) => displayEvents({ data, document, list }))
|
|
|
|
.catch((data) => displayErrorMessage({ data, list }))
|
2021-01-08 14:08:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|