refining taxonomy js to handle load more button and connect to custom api endpoint

This commit is contained in:
Antoine M 2023-10-25 14:49:18 +02:00
parent c702ea0e54
commit 1fc4e1ebc6

View File

@ -1,20 +1,20 @@
async function fetchMoreThematiquePostDatas() { async function fetchMoreThematiquePostDatas(id) {
// const response = await fetch('/wp-json/wp/v2/questions?per_page=100'); const response = await fetch(`/wp-json/homegrade-datas/v1/questions-thematiques/${id}`);
const response = await fetch('/wp-json/wp/v2/questions?thematiques=41');
const data = await response.json(); const data = await response.json();
console.log(data);
return data; return data;
} }
async function handleLoadMoreClick() { 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'); const postsContainer = document.querySelector('.post-question-page__accordeons-container');
console.log(mainAppJsDynamicDatas.current_thematique); // console.log(posts);
posts.forEach((post) => { // posts.forEach((post) => {
let newContent = createDetailsElement(post); // let newContent = createDetailsElement(post);
postsContainer.appendChild(newContent); // postsContainer.appendChild(newContent);
}); // });
} }
function createDetailsElement(post) { function createDetailsElement(post) {
@ -44,7 +44,7 @@ function createDetailsElement(post) {
} }
export default async function taxonomyThematiqueFaqInit() { export default async function taxonomyThematiqueFaqInit() {
console.log(mainAppJsDynamicDatas); // console.log(mainAppJsDynamicDatas);
const currentQuestionPage = document.querySelector('.post-question-page'); const currentQuestionPage = document.querySelector('.post-question-page');
const filters = document.querySelectorAll('.thematiques-subtaxonomy-links li'); const filters = document.querySelectorAll('.thematiques-subtaxonomy-links li');
if (!currentQuestionPage) return; if (!currentQuestionPage) return;