2021-05-05 10:02:57 +02:00
|
|
|
import { displayEvents, displayErrorMessage } from './events-displayer'
|
2021-01-08 14:08:40 +01:00
|
|
|
import * as GraphqlWrapper from './graphql-wrapper'
|
|
|
|
|
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')
|
|
|
|
for (let list of eventLists) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|