2021-04-12 20:06:21 +02:00
|
|
|
class commentsDisplay extends HTMLElement {
|
|
|
|
constructor() {
|
|
|
|
super();
|
2022-03-08 12:23:05 +01:00
|
|
|
this.getComments()
|
|
|
|
}
|
2021-04-18 21:49:25 +02:00
|
|
|
|
2022-03-08 12:23:05 +01:00
|
|
|
async getComments() {
|
|
|
|
var graphql = JSON.stringify({
|
|
|
|
query: 'query($article: String!) { comments(article: $article) { name comment gravatarURL }}',
|
|
|
|
variables: {
|
|
|
|
"article": window.location.pathname
|
2021-04-12 20:06:21 +02:00
|
|
|
}
|
2022-03-08 12:23:05 +01:00
|
|
|
})
|
|
|
|
var requestOptions = {
|
|
|
|
method: 'POST',
|
|
|
|
body: graphql,
|
|
|
|
};
|
2022-03-15 08:49:36 +01:00
|
|
|
let comments = (await (await fetch("/API/graphql.php", requestOptions)).json()).data.comments;
|
2022-03-14 15:37:35 +01:00
|
|
|
this.innerHTML = "";
|
2022-03-08 12:23:05 +01:00
|
|
|
comments.forEach((element) => {
|
|
|
|
const h3 = document.createElement("h3");
|
|
|
|
h3.classList.add("commentTitle");
|
|
|
|
h3.innerText = element["name"];
|
|
|
|
this.appendChild(h3);
|
|
|
|
|
|
|
|
const commentDiv = document.createElement("div");
|
|
|
|
commentDiv.classList.add("comment");
|
|
|
|
this.appendChild(commentDiv);
|
|
|
|
|
|
|
|
const image = document.createElement("img");
|
|
|
|
image.src = element["gravatarURL"];
|
|
|
|
commentDiv.appendChild(image);
|
|
|
|
|
|
|
|
const article = document.createElement("article");
|
|
|
|
article.classList.add("commentArticle");
|
|
|
|
commentDiv.appendChild(article);
|
|
|
|
|
|
|
|
const commentText = document.createElement("p");
|
|
|
|
commentText.classList.add("commentText");
|
|
|
|
commentText.innerText = element["comment"];
|
|
|
|
article.appendChild(commentText);
|
|
|
|
|
|
|
|
});
|
2021-04-12 20:06:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-09 12:08:05 +01:00
|
|
|
customElements.define("jl-comments_display", commentsDisplay);
|