diff --git a/source/front/blocks/events-list/edit.js b/source/front/blocks/events-list/edit.js index 0294cd2..f8de8a3 100644 --- a/source/front/blocks/events-list/edit.js +++ b/source/front/blocks/events-list/edit.js @@ -8,7 +8,7 @@ import { } from '../../events-displayer.js' const { InspectorControls, useBlockProps } = wp.blockEditor -const { PanelBody } = wp.components +const { Panel, PanelBody } = wp.components const { useEffect } = wp.element const { __ } = wp.i18n @@ -16,11 +16,10 @@ const NAME = '' export default ({ attributes, setAttributes }) => { let timer - const { eventsCount, groupName } = attributes const blockProps = useBlockProps({ className: NAME + '_events-list', }) - function reloadEventList() { + function reloadEventList(eventsCount, groupName) { if (timer) { clearTimeout(timer) } @@ -35,12 +34,7 @@ export default ({ attributes, setAttributes }) => { url += `&groupName=${groupName}` } await fetch(url) - .then((response) => { - if (!response.ok) { - return Promise.reject('Network response was not OK.') - } - return response.text() - }) + .then((response) => response.text()) .then((data) => { const events = JSON.parse(data) displayEvents({ @@ -57,51 +51,51 @@ export default ({ attributes, setAttributes }) => { }, 500) } useEffect(() => { - reloadEventList() + reloadEventList(attributes.eventsCount, attributes.groupName) }, []) function updateEventsCount(event) { - // console.log('new value: ', event.target.value) // TODO let newValue = Number(event.target.value) if (newValue < 1) newValue = 1 setAttributes({ eventsCount: newValue }) - reloadEventList() + reloadEventList(newValue, attributes.groupName) } function updateGroupName(event) { - // console.log('new value: ', event.target.value) // TODO - // TODO not triggered on pasting only - setAttributes({ groupName: event.target.value }) - reloadEventList() + const newValue = event.target.value + setAttributes({ groupName: newValue }) + reloadEventList(attributes.eventsCount, newValue) } return [ - ')}> - - - - - + + ')}> + + + + + + ,