From 1fc4e1ebc697339af8a34180bd3bfba46d7a3a96 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Wed, 25 Oct 2023 14:49:18 +0200 Subject: [PATCH] refining taxonomy js to handle load more button and connect to custom api endpoint --- resources/js/taxonomy-thematique-(faq).js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/resources/js/taxonomy-thematique-(faq).js b/resources/js/taxonomy-thematique-(faq).js index 767da32..f8900cd 100644 --- a/resources/js/taxonomy-thematique-(faq).js +++ b/resources/js/taxonomy-thematique-(faq).js @@ -1,20 +1,20 @@ -async function fetchMoreThematiquePostDatas() { - // const response = await fetch('/wp-json/wp/v2/questions?per_page=100'); - const response = await fetch('/wp-json/wp/v2/questions?thematiques=41'); +async function fetchMoreThematiquePostDatas(id) { + const response = await fetch(`/wp-json/homegrade-datas/v1/questions-thematiques/${id}`); const data = await response.json(); - console.log(data); return data; } async function handleLoadMoreClick() { - const posts = await fetchMoreThematiquePostDatas(); + const currentTermId = mainAppJsDynamicDatas.current_thematique.term_id; + const posts = await fetchMoreThematiquePostDatas(currentTermId); + console.log(posts); const postsContainer = document.querySelector('.post-question-page__accordeons-container'); - console.log(mainAppJsDynamicDatas.current_thematique); - posts.forEach((post) => { - let newContent = createDetailsElement(post); - postsContainer.appendChild(newContent); - }); + // console.log(posts); + // posts.forEach((post) => { + // let newContent = createDetailsElement(post); + // postsContainer.appendChild(newContent); + // }); } function createDetailsElement(post) { @@ -44,7 +44,7 @@ function createDetailsElement(post) { } export default async function taxonomyThematiqueFaqInit() { - console.log(mainAppJsDynamicDatas); + // console.log(mainAppJsDynamicDatas); const currentQuestionPage = document.querySelector('.post-question-page'); const filters = document.querySelectorAll('.thematiques-subtaxonomy-links li'); if (!currentQuestionPage) return;