1
0
mirror of https://github.com/dwaxweiler/connector-mobilizon synced 2025-03-02 10:27:51 +01:00

88 lines
2.6 KiB
JavaScript
Raw Normal View History

2022-06-03 23:48:19 +02:00
/* eslint-disable @wordpress/i18n-ellipsis */
import { loadEventList } from '../../events-loader.js'
const { InspectorControls, useBlockProps } = wp.blockEditor
2021-11-01 20:55:37 +01:00
const { PanelBody } = wp.components
2022-06-03 23:48:19 +02:00
const { useEffect } = wp.element
2021-11-01 20:55:37 +01:00
const { __ } = wp.i18n
2022-06-03 23:48:19 +02:00
const NAME = '<wordpress-name>'
let timer
2021-11-01 20:55:37 +01:00
export default ({ attributes, setAttributes }) => {
2022-06-03 23:48:19 +02:00
const blockProps = useBlockProps({
className: NAME + '_events-list',
'data-maximum': attributes.eventsCount,
'data-group-name': attributes.groupName,
})
function reloadEventList() {
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(() => {
const container = document.getElementById(blockProps.id)
if (container) {
loadEventList(container)
}
}, 500)
}
useEffect(() => {
reloadEventList()
}, [])
2021-11-01 20:55:37 +01:00
function updateEventsCount(event) {
let newValue = Number(event.target.value)
if (newValue < 1) newValue = 1
setAttributes({ eventsCount: newValue })
2022-06-03 23:48:19 +02:00
reloadEventList()
2021-11-01 20:55:37 +01:00
}
function updateGroupName(event) {
setAttributes({ groupName: event.target.value })
2022-06-03 23:48:19 +02:00
reloadEventList()
2021-11-01 20:55:37 +01:00
}
2021-12-14 15:33:07 +01:00
return [
2021-11-01 20:55:37 +01:00
<InspectorControls>
2021-12-14 15:33:07 +01:00
<PanelBody title={__('Events List Settings', '<wordpress-name>')}>
<label
className="components-base-control__label"
2022-06-19 09:30:36 +02:00
htmlFor={NAME + '_events-count'}
2021-12-14 15:33:07 +01:00
>
{__('Number of events to show', '<wordpress-name>')}
</label>
<input
className="components-text-control__input"
type="number"
value={attributes.eventsCount}
onChange={updateEventsCount}
2022-06-19 09:30:36 +02:00
id={NAME + '_events-count'}
2021-12-14 15:33:07 +01:00
/>
<label
className="components-base-control__label"
2022-06-19 09:30:36 +02:00
htmlFor={NAME + '_group-name'}
2021-12-14 15:33:07 +01:00
>
{__('Group name (optional)', '<wordpress-name>')}
</label>
<input
className="components-text-control__input"
type="text"
value={attributes.groupName}
onChange={updateGroupName}
2022-06-19 09:30:36 +02:00
id={NAME + '_group-name'}
2021-12-14 15:33:07 +01:00
/>
2021-11-01 20:55:37 +01:00
</PanelBody>
</InspectorControls>,
2022-06-03 23:48:19 +02:00
<div {...blockProps}>
<div className="general-error" style={{ display: 'none' }}>
{__('The events could not be loaded!', '<wordpress-name>')}
</div>
<div className="group-not-found" style={{ display: 'none' }}>
{__('The group could not be found!', '<wordpress-name>')}
</div>
<div className="loading-indicator" style={{ display: 'none' }}>
{__('Loading...', '<wordpress-name>')}
</div>
<ul style={{ 'list-style-type': 'none', 'padding-left': 0 }}></ul>
</div>,
2021-12-14 15:33:07 +01:00
]
2021-11-01 20:55:37 +01:00
}