Compare commits

...

4 Commits

Author SHA1 Message Date
Nonimart
a50612cd58 REFACTOR Renaming and deleting unused lines
All checks were successful
continuous-integration/drone/push Build is passing
2025-06-13 16:04:32 +02:00
Nonimart
5e24ce4c88 FEATURE Handling Reset all artisans buttons 2025-06-13 16:03:43 +02:00
Nonimart
9e14ec6ee7 FEATURE Introducing cta variants component 2025-06-13 16:03:03 +02:00
Nonimart
f08f6d1aab FIX Passing missing taxonomy-tag--parent to metiers 2025-06-13 16:02:41 +02:00
6 changed files with 41 additions and 46 deletions

View File

@ -7,18 +7,13 @@ add_action('rest_api_init', function () {
-----------------*/
// ################ BUILD ARTISANS SEARCH RESULTS ################
// * BUILD MORE NEWS CARDS
register_rest_route('metiers-patrimoine-datas/v1/build', '/artisans', array(
'methods' => 'GET',
'callback' => 'build_search_artisan_posts_cards',
'permission_callback' => '__return_true',
));
});
// ################ ARTISANS ################
function build_search_artisan_posts_cards($request)
{
@ -66,10 +61,10 @@ function build_search_artisan_posts_cards($request)
"meta_query" => $metaQuery,
's' => $search_value,
);
$newsPostsDatas = new WP_Query($args);
$searchArtisans = new WP_Query($args);
ob_start();
foreach ($newsPostsDatas->posts as $key => $post) {
foreach ($searchArtisans->posts as $key => $post) {
// continue en fonction
$post_thumbnail = get_the_post_thumbnail($post->ID, 'full', array('class' => 'card-artisans__thumbnail')) ?? null;
@ -94,7 +89,7 @@ function build_search_artisan_posts_cards($request)
$html_template = ob_get_clean();
if ($newsPostsDatas->found_posts === 0) {
if ($searchArtisans->found_posts === 0) {
ob_start();
get_template_part(
'template-components/artisans/artisan-search-no-results',
@ -105,49 +100,15 @@ function build_search_artisan_posts_cards($request)
}
$response_data = array(
'html_template' => $html_template,
'total_posts_found' => $newsPostsDatas->found_posts,
'total_posts_found' => $searchArtisans->found_posts,
'active_page' => $activePage,
'max_num_pages' => $newsPostsDatas->max_num_pages,
'max_num_pages' => $searchArtisans->max_num_pages,
);
$response = new WP_REST_Response($response_data);
$response->set_status(200);
// debugQueryTest( );
return $response;
}
function debugQueryTest()
{
$args = array(
"post_status" => "publish",
"post_type" => "artisans",
"posts_per_page" => -1,
// "tax_query" => $taxQuery,
// "meta_query" => $metaQuery,
's' => "Atelier Schrauwen",
);
$newsPostsDatas = new WP_Query($args);
$filteredPosts = [];
do_action('wpml_switch_language', 'nl');
ob_start();
get_template_part(
'template-components/artisans/artisan-search-no-results',
null,
[]
);
$html_template = ob_get_clean();
$test = __("Aucun résultat trouvé", "metiers-patrimoine-theme");
return ($html_template);
}
// debugQueryTest();
// add_action('wp_footer', 'debugQueryTest');

View File

@ -3,3 +3,13 @@
@apply text-patrimoine-sante-securite;
}
}
.cta {
@apply px-4 py-2;
&--rounded {
@apply rounded-full;
}
&--primary {
@apply bg-patrimoine-sante-securite text-white;
}
}

View File

@ -20,6 +20,9 @@
p {
@apply text-neutral-900 tracking-wide;
}
#reset-all-artisans-button {
@apply mt-4 mx-auto;
}
}
}
.card-artisans {

View File

@ -36,6 +36,24 @@ function observeSearchResetButton() {
}
});
}
function observeResetAllArtisansButton() {
const resetAllArtisansButton = document.querySelector('#reset-all-artisans-button');
resetAllArtisansButton.addEventListener('click', () => {
resetSearchfield();
hydrateWithAllArtisans({});
});
}
function observeNoResultsApparition() {
const grid = document.querySelector('.artisans-posts__grid');
const observer = new MutationObserver(() => {
const noResults = grid.querySelector('.no-results');
if (!noResults) return;
observeResetAllArtisansButton();
});
observer.observe(grid, { childList: true, subtree: true });
}
function clearAllCheckboxes() {
const filtersCheckboxes = document.querySelectorAll('.taxonomy-checkbox');
@ -219,7 +237,7 @@ export default function dynamicSearch() {
});
const searchForm = document.querySelector('.artisan-search-bar');
searchForm.addEventListener('submit', handleSearchSubmit);
observeSearchResetButton();
observeNoResultsApparition(); // Si la div no-results apparait, on observe le bouton reset all artisans pour gérer son comortement
}

View File

@ -5,4 +5,7 @@
<img class='no-results__cover' src="<?php echo get_stylesheet_directory_uri() . "/resources/img/illustrations/Homegrade_resultats-filtres-cactus.svg" ?>" alt='' />
<h3><?php echo __("Aucun artisan correspondant actuellement", "metiers-patrimoine-theme") ?> </h3>
<p> <?php echo __("Sélectionnez un ou plusieurs <span class='highlighted-purple'>métiers</span> ou <span class='highlighted-purple'>critères</span> pour lancer votre recherche", "metiers-patrimoine-theme") ?></p>
<button class="cta cta--primary cta--rounded" id="reset-all-artisans-button">
<?php echo __("Voir tous les artisans", "metiers-patrimoine-theme") ?>
</button>
</div>

View File

@ -22,7 +22,7 @@ $hasEmptyTaxos = (empty($elementsBatimentsTerms) && empty($metiersTerms)) ? 'car
</div>
<div class="taxonomy-tags card-taxonomies__taxonomy-tags">
<?php foreach ($elementsBatimentsTerms as $key => $term) : ?>
<span class="taxonomy-tag"><?php echo $term->name; ?></span>
<span class="taxonomy-tag taxonomy-tag--<?php echo $term->parent === 0 ? 'parent' : 'child'; ?>"><?php echo $term->name; ?></span>
<?php endforeach; ?>
</div>
</div>