Skip to content

Commit

Permalink
Events: Add indicator that filter is applied.
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenDufresne committed Dec 7, 2023
1 parent d6079d2 commit f9a9d7d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
54 changes: 38 additions & 16 deletions public_html/wp-content/themes/wporg-events-2023/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,24 @@ function add_site_navigation_menus( $menus ) {
function get_country_options( array $options ): array {
global $wp_query;
$selected = isset( $wp_query->query['country'] ) ? (array) $wp_query->query['country'] : array();
$count = count( $selected );

$countries = wcorg_get_countries();

// Re-index to match the format expected by the query-filters block.
$countries = array_combine( array_keys( $countries ), array_column( $countries, 'name' ) );

$label = __( 'Country', 'wporg' );
if ( $count > 0 ) {
$label = sprintf(
/* translators: The dropdown label for filtering, %s is the selected term count. */
_n( 'Country <span>%s</span>', 'Country <span>%s</span>', $count, 'wporg' ),
$count
);
}

return array(
'label' => __( 'Country', 'wporg' ),
'label' => $label,
'title' => __( 'Country', 'wporg' ),
'key' => 'country',
'action' => home_url( '/upcoming-events/' ),
Expand All @@ -89,11 +99,15 @@ function get_event_type_options( array $options ): array {
global $wp_query;
$selected = isset( $wp_query->query['event_type'] ) ? (array) $wp_query->query['event_type'] : array();
$count = count( $selected );
$label = sprintf(
/* translators: The dropdown label for filtering, %s is the selected term count. */
_n( 'Type <span>%s</span>', 'Type <span>%s</span>', $count, 'wporg' ),
$count
);

$label = __( 'Type', 'wporg' );
if ( $count > 0 ) {
$label = sprintf(
/* translators: The dropdown label for filtering, %s is the selected term count. */
_n( 'Type <span>%s</span>', 'Type <span>%s</span>', $count, 'wporg' ),
$count
);
}

return array(
'label' => $label,
Expand All @@ -117,11 +131,15 @@ function get_format_type_options( array $options ): array {
global $wp_query;
$selected = isset( $wp_query->query['format_type'] ) ? (array) $wp_query->query['format_type'] : array();
$count = count( $selected );
$label = sprintf(
/* translators: The dropdown label for filtering, %s is the selected term count. */
_n( 'Format <span>%s</span>', 'Format <span>%s</span>', $count, 'wporg' ),
$count
);

$label = __( 'Format', 'wporg' );
if ( $count > 0 ) {
$label = sprintf(
/* translators: The dropdown label for filtering, %s is the selected term count. */
_n( 'Format <span>%s</span>', 'Format <span>%s</span>', $count, 'wporg' ),
$count
);
}

return array(
'label' => $label,
Expand All @@ -145,11 +163,15 @@ function get_month_options( array $options ): array {
global $wp_query;
$selected = isset( $wp_query->query['month'] ) ? (array) $wp_query->query['month'] : array();
$count = count( $selected );
$label = sprintf(
/* translators: The dropdown label for filtering, %s is the selected term count. */
_n( 'Month <span>%s</span>', 'Month <span>%s</span>', $count, 'wporg' ),
$count
);

$label = __( 'Month', 'wporg' );
if ( $count > 0 ) {
$label = sprintf(
/* translators: The dropdown label for filtering, %s is the selected term count. */
_n( 'Month <span>%s</span>', 'Month <span>%s</span>', $count, 'wporg' ),
$count
);
}

$months = array();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

/* Until we move to multi-select we should show the count so users know there is a filter applied. */
.wporg-query-filter__toggle.has-no-filter-applied span,
.wporg-query-filter__toggle.is-single-select span {
display: inline-block;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@

/* Blocks */
@import "blocks/wporg-google-map.pcss";
@import "blocks/wporg-query-filter.pcss";

0 comments on commit f9a9d7d

Please sign in to comment.