wip
This commit is contained in:
parent
a442da042f
commit
c27d0760ea
|
@ -59,7 +59,7 @@ final class Mobilizon_Connector {
|
||||||
'timeZone' => wp_timezone_string(),
|
'timeZone' => wp_timezone_string(),
|
||||||
'url' => MobilizonConnector\Settings::getUrl()
|
'url' => MobilizonConnector\Settings::getUrl()
|
||||||
);
|
);
|
||||||
wp_add_inline_script($scriptName, 'var MOBILIZON_CONNECTOR = ' . json_encode($settings), 'before');
|
wp_add_inline_script($scriptName, 'var MOBILIZON_CONNECTOR = ' . json_encode($settings), 'before'); // TODO remove url
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register_api() {
|
public function register_api() {
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
/* eslint-disable @wordpress/i18n-ellipsis */
|
/* eslint-disable @wordpress/i18n-ellipsis */
|
||||||
import { loadEventList } from '../../events-loader.js'
|
|
||||||
import {
|
import {
|
||||||
|
clearEventsList,
|
||||||
|
displayErrorMessage,
|
||||||
|
displayEvents,
|
||||||
|
hideErrorMessages,
|
||||||
showLoadingIndicator,
|
showLoadingIndicator,
|
||||||
hideLoadingIndicator
|
|
||||||
} from '../../events-displayer.js'
|
} from '../../events-displayer.js'
|
||||||
|
|
||||||
const { InspectorControls, useBlockProps } = wp.blockEditor
|
const { InspectorControls, useBlockProps } = wp.blockEditor
|
||||||
|
@ -18,7 +20,7 @@ export default ({ attributes, setAttributes }) => {
|
||||||
const blockProps = useBlockProps({
|
const blockProps = useBlockProps({
|
||||||
className: NAME + '_events-list',
|
className: NAME + '_events-list',
|
||||||
'data-maximum': attributes.eventsCount,
|
'data-maximum': attributes.eventsCount,
|
||||||
'data-group-name': attributes.groupName,
|
'data-group-name': attributes.groupName, // TODO still necessary?
|
||||||
})
|
})
|
||||||
function reloadEventList() {
|
function reloadEventList() {
|
||||||
if (timer) {
|
if (timer) {
|
||||||
|
@ -27,10 +29,9 @@ export default ({ attributes, setAttributes }) => {
|
||||||
timer = setTimeout(() => {
|
timer = setTimeout(() => {
|
||||||
const container = document.getElementById(blockProps.id)
|
const container = document.getElementById(blockProps.id)
|
||||||
if (container) {
|
if (container) {
|
||||||
// loadEventList(container)
|
// TODO not using newest values yet, can get out of sync
|
||||||
// TODO use API instead
|
hideErrorMessages(container)
|
||||||
|
clearEventsList(container)
|
||||||
// TODO not using newest values yet
|
|
||||||
showLoadingIndicator(container)
|
showLoadingIndicator(container)
|
||||||
const eventsCount = attributes.eventsCount
|
const eventsCount = attributes.eventsCount
|
||||||
const groupName = attributes.groupName
|
const groupName = attributes.groupName
|
||||||
|
@ -40,11 +41,11 @@ export default ({ attributes, setAttributes }) => {
|
||||||
}
|
}
|
||||||
fetch(url)
|
fetch(url)
|
||||||
.then((response) => response.text()) // TODO also handle response.ok being false
|
.then((response) => response.text()) // TODO also handle response.ok being false
|
||||||
.then((data) => {
|
.then((events) => {
|
||||||
console.log(data) // TODO handle
|
displayEvents({ events, document, container })
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.catch((data) => {
|
||||||
hideLoadingIndicator(container)
|
displayErrorMessage({ data, container })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}, 500)
|
}, 500)
|
||||||
|
|
|
@ -40,24 +40,20 @@ test.beforeEach((t) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('#displayEvents one event', (t) => {
|
test('#displayEvents one event', (t) => {
|
||||||
const data = {
|
const events = [
|
||||||
events: {
|
{
|
||||||
elements: [
|
title: 'a',
|
||||||
{
|
url: 'b',
|
||||||
title: 'a',
|
beginsOn: '2021-04-15T10:30:00Z',
|
||||||
url: 'b',
|
endsOn: '2021-04-15T15:30:00Z',
|
||||||
beginsOn: '2021-04-15T10:30:00Z',
|
physicalAddress: {
|
||||||
endsOn: '2021-04-15T15:30:00Z',
|
description: 'c',
|
||||||
physicalAddress: {
|
locality: 'd',
|
||||||
description: 'c',
|
},
|
||||||
locality: 'd',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
}
|
]
|
||||||
const container = t.context.container
|
const container = t.context.container
|
||||||
displayEvents({ data, document, container })
|
displayEvents({ events, document, container })
|
||||||
const list = container.querySelector('ul')
|
const list = container.querySelector('ul')
|
||||||
t.is(list.children[0].childNodes[0].tagName, 'A')
|
t.is(list.children[0].childNodes[0].tagName, 'A')
|
||||||
t.is(list.children[0].childNodes[0].getAttribute('href'), 'b')
|
t.is(list.children[0].childNodes[0].getAttribute('href'), 'b')
|
||||||
|
|
|
@ -6,7 +6,7 @@ export function clearEventsList(container) {
|
||||||
list.replaceChildren()
|
list.replaceChildren()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function displayEvents({ data, document, container }) {
|
export function displayEvents({ events, document, container }) {
|
||||||
hideLoadingIndicator(container)
|
hideLoadingIndicator(container)
|
||||||
|
|
||||||
const isShortOffsetNameShown =
|
const isShortOffsetNameShown =
|
||||||
|
@ -15,9 +15,6 @@ export function displayEvents({ data, document, container }) {
|
||||||
const maxEventsCount = container.getAttribute('data-maximum')
|
const maxEventsCount = container.getAttribute('data-maximum')
|
||||||
const timeZone = window.MOBILIZON_CONNECTOR.timeZone
|
const timeZone = window.MOBILIZON_CONNECTOR.timeZone
|
||||||
|
|
||||||
const events = data.events
|
|
||||||
? data.events.elements
|
|
||||||
: data.group.organizedEvents.elements
|
|
||||||
const eventsCount = Math.min(maxEventsCount, events.length)
|
const eventsCount = Math.min(maxEventsCount, events.length)
|
||||||
const list = container.querySelector('ul')
|
const list = container.querySelector('ul')
|
||||||
for (let i = 0; i < eventsCount; i++) {
|
for (let i = 0; i < eventsCount; i++) {
|
||||||
|
|
|
@ -36,3 +36,5 @@ export function loadEventList(container) {
|
||||||
.catch((data) => displayErrorMessage({ data, container }))
|
.catch((data) => displayErrorMessage({ data, container }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO delete file and generated file events-loader.js?
|
||||||
|
|
Loading…
Reference in New Issue