Skip to content

Commit

Permalink
add notice for no local events found
Browse files Browse the repository at this point in the history
  • Loading branch information
iandunn committed Dec 14, 2023
1 parent dd8fb97 commit 15162cf
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ body {
.wporg-events__hidden {
display: none;
}

.wporg-marker-list__loading {
/* The final height could be anywhere between 50px and 750px, so split the difference in order to avoid a big
* jump when it loads. */
height: 350px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function enqueue_assets() {
*/
function render( $attributes, $content, $block ) {
if ( 'nearby' === $attributes['events'] ) {
$content = get_nearby_loading();
$content = get_nearby_events_markup();
} else {
$content = get_all_upcoming( $attributes['events'], $attributes['limit'], $attributes['groupByMonth'] );
}
Expand Down Expand Up @@ -121,17 +121,35 @@ function( $a, $b ) {
}

//
function get_nearby_loading() {
return sprintf(
'<p class="wporg-marker-list__loading">
Loading nearby events...
<img src="%s" width="20" height="20" alt="" />
</p>
%s',
esc_url( includes_url( 'images/spinner-2x.gif' ) ),
get_list_markup( array() )
);
function get_nearby_events_markup() {
ob_start();

?>

<p class="wporg-marker-list__loading">
Loading nearby events...
<img
src="<?php echo esc_url( includes_url( 'images/spinner-2x.gif' ) ); ?>>"
width="20"
height="20"
alt=""
/>
</p>

<?php echo get_list_markup( array() ); ?>

<!-- wp:wporg/notice {"type":"warning","className":"wporg-marker-list__no-results wporg-events__hidden"} -->
<div class="wp-block-wporg-notice is-warning-notice wporg-marker-list__no-results wporg-events__hidden">
<p>
There are no events scheduled near you at the moment. You can <a href="<?php echo esc_url( home_url( 'upcoming-events/' ) ); ?>">browse global events</a>, or
<a href="https://make.wordpress.org/community/handbook/meetup-organizer/welcome/" class="external-link">learn how to organize an event in your area</a>.
</p>
</div>
<!-- /wp:wporg/notice -->

<?php

return ob_get_clean();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ document.addEventListener( 'DOMContentLoaded', function() {
const nearbyEventList = document.getElementById( 'front-event-list-nearby' );
const globalEventList = document.getElementById( 'front-event-list-global' );
const chipsContainer = document.querySelector( '.wporg-events__nearby-chips' );
const noEventsMessage = document.querySelector( '.wporg-marker-list__no-results' );

//
function init() {
Expand Down Expand Up @@ -59,7 +60,7 @@ document.addEventListener( 'DOMContentLoaded', function() {
const blockContainer = document.getElementById( 'front-event-list-nearby' );
const loadingElement = blockContainer.querySelector( '.wporg-marker-list__loading' );
const listContainer = blockContainer.querySelector( '.wporg-marker-list__container' );
//return;

try {
/*
* This uses `fetch()` directly instead of `apifetch()`, because the latter is only intended for interacting
Expand All @@ -70,13 +71,18 @@ document.addEventListener( 'DOMContentLoaded', function() {
const response = await fetch( url, requestParams );
results = await response.json();

for ( let i = 0; i < results.events.length; i++ ) {
const eventDiv = document.createElement( 'li' );
eventDiv.classList.add( 'wporg-marker-list-item' );
eventDiv.innerHTML = renderEvent( results.events[ i ] );
listContainer.appendChild( eventDiv );
if ( results.events.length > 0 ) {
for ( let i = 0; i < results.events.length; i++ ) {
const eventDiv = document.createElement( 'li' );
eventDiv.classList.add( 'wporg-marker-list-item' );
eventDiv.innerHTML = renderEvent( results.events[ i ] );
listContainer.appendChild( eventDiv );
// review for security
}

} else {
noEventsMessage.classList.remove( 'wporg-events__hidden' );
}
// review for security

} catch ( error ) {
// This matches the format returned by the API for application-layer errors (e.g., invalid API key).
Expand Down

0 comments on commit 15162cf

Please sign in to comment.