Compare commits
4 Commits
183c7bdd35
...
f1c4232493
Author | SHA1 | Date |
---|---|---|
Daniel Waxweiler | f1c4232493 | |
Daniel Waxweiler | 55c1ead17d | |
Daniel Waxweiler | d546157c93 | |
Daniel Waxweiler | 4f0752b0ac |
|
@ -2,10 +2,11 @@
|
|||
#### Added
|
||||
- Display name of group when it cannot be found
|
||||
#### Changed
|
||||
- Let backend do requests to API for viewing all forms, except for in-editor block preview
|
||||
- Let backend do requests to API of Mobilizon instance for increased privacy
|
||||
#### Deprecated
|
||||
#### Removed
|
||||
#### Fixed
|
||||
- Fix displaying more than one block in the editor
|
||||
#### Security
|
||||
|
||||
### [0.11.5]
|
||||
|
|
|
@ -8,24 +8,22 @@ 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
|
||||
|
||||
const NAME = '<wordpress-name>'
|
||||
|
||||
let timer
|
||||
|
||||
export default ({ attributes, setAttributes }) => {
|
||||
const { eventsCount, groupName } = attributes
|
||||
let timer
|
||||
const blockProps = useBlockProps({
|
||||
className: NAME + '_events-list',
|
||||
})
|
||||
function reloadEventList() {
|
||||
function reloadEventList(eventsCount, groupName) {
|
||||
if (timer) {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
timer = setTimeout(() => {
|
||||
timer = setTimeout(async () => {
|
||||
const container = document.getElementById(blockProps.id)
|
||||
if (container) {
|
||||
hideErrorMessages(container)
|
||||
|
@ -35,13 +33,8 @@ export default ({ attributes, setAttributes }) => {
|
|||
if (groupName) {
|
||||
url += `&groupName=${groupName}`
|
||||
}
|
||||
fetch(url)
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
return Promise.reject('Network response was not OK.')
|
||||
}
|
||||
return response.text()
|
||||
})
|
||||
await fetch(url)
|
||||
.then((response) => response.text())
|
||||
.then((data) => {
|
||||
const events = JSON.parse(data)
|
||||
displayEvents({
|
||||
|
@ -58,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 [
|
||||
<InspectorControls>
|
||||
<PanelBody title={__('Events List Settings', '<wordpress-name>')}>
|
||||
<label
|
||||
className="components-base-control__label"
|
||||
htmlFor={NAME + '_events-count'}
|
||||
>
|
||||
{__('Number of events to show', '<wordpress-name>')}
|
||||
</label>
|
||||
<input
|
||||
className="components-text-control__input"
|
||||
type="number"
|
||||
value={eventsCount}
|
||||
onChange={updateEventsCount}
|
||||
id={NAME + '_events-count'}
|
||||
/>
|
||||
<label
|
||||
className="components-base-control__label"
|
||||
htmlFor={NAME + '_group-name'}
|
||||
>
|
||||
{__('Group name (optional)', '<wordpress-name>')}
|
||||
</label>
|
||||
<input
|
||||
className="components-text-control__input"
|
||||
type="text"
|
||||
value={groupName}
|
||||
onChange={updateGroupName}
|
||||
id={NAME + '_group-name'}
|
||||
/>
|
||||
</PanelBody>
|
||||
<Panel>
|
||||
<PanelBody title={__('Events List Settings', '<wordpress-name>')}>
|
||||
<label
|
||||
className="components-base-control__label"
|
||||
htmlFor={NAME + '_events-count'}
|
||||
>
|
||||
{__('Number of events to show', '<wordpress-name>')}
|
||||
</label>
|
||||
<input
|
||||
className="components-text-control__input"
|
||||
type="number"
|
||||
value={attributes.eventsCount}
|
||||
onChange={updateEventsCount}
|
||||
id={NAME + '_events-count'}
|
||||
/>
|
||||
<label
|
||||
className="components-base-control__label"
|
||||
htmlFor={NAME + '_group-name'}
|
||||
>
|
||||
{__('Group name (optional)', '<wordpress-name>')}
|
||||
</label>
|
||||
<input
|
||||
className="components-text-control__input"
|
||||
type="text"
|
||||
value={attributes.groupName}
|
||||
onChange={updateGroupName}
|
||||
id={NAME + '_group-name'}
|
||||
/>
|
||||
</PanelBody>
|
||||
</Panel>
|
||||
</InspectorControls>,
|
||||
<div {...blockProps}>
|
||||
<div className="general-error" style={{ display: 'none' }}>
|
||||
|
|
|
@ -80,7 +80,7 @@ export function showLoadingIndicator(container) {
|
|||
indicator.style.display = 'block'
|
||||
}
|
||||
|
||||
export function hideLoadingIndicator(container) {
|
||||
function hideLoadingIndicator(container) {
|
||||
const indicator = container.querySelector('.loading-indicator')
|
||||
indicator.style.display = 'none'
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue