diff --git a/resources/js/single-revue.js b/resources/js/single-revue.js index e9c645b..2d8c6fd 100644 --- a/resources/js/single-revue.js +++ b/resources/js/single-revue.js @@ -5,7 +5,8 @@ export default function singleRevue() { if (!isSingleRevue) return; handleButtons(); - getRevueAuthors(); + hydrateRevueAuthors(); + handleAuthorsButton(); } function getRevueID() { const revueID = document @@ -14,6 +15,14 @@ function getRevueID() { return revueID ?? null; } +function handleAuthorsButton() { + const authorsButton = document.querySelector( + '.authors-button' + ); + authorsButton.addEventListener('click', () => { + hydrateRevueAuthors(); + }); +} function handleButtons() { const socialsButtons = document.querySelectorAll( '.socials-buttons__button' @@ -23,25 +32,27 @@ function handleButtons() { '.socials-buttons__button--share' ); shareButton.addEventListener('click', () => { - const url = window.location.href; - const title = document.title; - const text = 'Check out this article: ' + url; - const shareUrl = - 'https://www.facebook.com/sharer/sharer.php?u=' + - encodeURIComponent(url); + // const url = window.location.href; + // const title = document.title; + // const text = 'Check out this article: ' + url; + // const shareUrl = + // 'https://www.facebook.com/sharer/sharer.php?u=' + + // encodeURIComponent(url); // window.open(shareUrl, '_blank'); - - console.log(url, title, text, shareUrl); }); } -async function getRevueAuthors() { +async function hydrateRevueAuthors() { const revueID = getRevueID(); if (!revueID) return; - console.log(revueID); const response = await fetch( `/wp-json/dynamiques-datas/v1/build/revue/authors?revue-id=${revueID}` ); const revueAuthors = await response.json(); + // console.log(revueAuthors); + + const authorsList = + document.querySelector('.authors-list'); + authorsList.innerHTML = revueAuthors.html_template; }