1
0
mirror of https://github.com/dwaxweiler/connector-mobilizon synced 2025-06-05 21:59:25 +02:00

Add show more events button below the events list #22 (#24)

This commit is contained in:
Daniel Waxweiler
2025-05-23 16:48:19 +02:00
committed by GitHub
parent 778c4e3b92
commit 3430b98f94
7 changed files with 26 additions and 2 deletions

View File

@ -1,3 +1,4 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
/* eslint-disable @wordpress/i18n-ellipsis */
import {
clearEventsList,
@ -30,9 +31,12 @@ export default ({ attributes, setAttributes }) => {
clearEventsList(container)
showLoadingIndicator(container)
let url = `/wp-json/connector-mobilizon/v1/events?eventsCount=${eventsCount}`
let showMoreUrl = window.MOBILIZON_CONNECTOR.url
if (groupName) {
showMoreUrl += '/@' + groupName + '/events'
url += `&groupName=${groupName}`
}
container.querySelector('a').href = showMoreUrl
await fetch(url)
.then((response) => response.text())
.then((data) => {
@ -55,7 +59,9 @@ export default ({ attributes, setAttributes }) => {
}, [])
function updateEventsCount(event) {
let newValue = Number(event.target.value)
if (newValue < 1) newValue = 1
if (newValue < 1) {
newValue = 1
}
setAttributes({ eventsCount: newValue })
reloadEventList(newValue, attributes.groupName)
}
@ -108,6 +114,13 @@ export default ({ attributes, setAttributes }) => {
{__('Loading...', '<wordpress-name>')}
</div>
<ul style={{ 'list-style-type': 'none', 'padding-left': 0 }}></ul>
<a
href=""
target="_blank"
style={{ display: 'inline-block', 'margin-top': '20px;' }}
>
{__('Show more events', '<wordpress-name>')}
</a>
</div>,
]
}