summaryrefslogtreecommitdiff
path: root/static/js/controllers/comments_controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/js/controllers/comments_controller.js')
-rw-r--r--static/js/controllers/comments_controller.js39
1 files changed, 20 insertions, 19 deletions
diff --git a/static/js/controllers/comments_controller.js b/static/js/controllers/comments_controller.js
index 683f5ca..86abfe6 100644
--- a/static/js/controllers/comments_controller.js
+++ b/static/js/controllers/comments_controller.js
@@ -1,51 +1,52 @@
import { BaseController } from "./base_controller.js";
-import { Paginator } from "../paginator.js";
+import { PaginationController } from "./pagination_controller.js";
export class CommentsController extends BaseController {
- constructor(replies_controller) {
+ constructor(replies_controller) {
super();
this.replies_controller = replies_controller;
this.comments_node = document.getElementById("comments-thread");
- this.paginator = new Paginator(this.comments_server_host, "/api/comments", this.post);
+ this.paginator = new PaginationController(this.comments_server_host, "/api/comments", this.post,
+ this.replies_controller);
this.renderForm();
this.renderComments();
- }
+ }
- renderForm() {
+ renderForm() {
this.get("/api/comments/new").then((value) => {
- const form = value?.getElementById("comment-form");
+ const form = value?.getElementById("comment-form");
- if(form != null) {
+ if (form != null) {
this.comments_node.appendChild(form);
this.form_element = document.getElementById("comment-form");
this.form_element.addEventListener("submit", this.submit.bind(this));
- }
+ }
});
- }
+ }
- renderComments() {
+ renderComments() {
this.get(`/api/comments?path=${this.post}`).then((value) => {
- const comments = value?.getElementById("comment-section");
+ const comments = value?.getElementById("comment-section");
- if(comments != null) {
+ if (comments != null) {
this.comments_node.appendChild(comments);
this.replies_controller.init();
this.paginator.populatePageAnchors();
- }
+ }
});
- }
+ }
- renderSubmitResponse(response_document) {
+ renderSubmitResponse(response_document) {
const new_comments = this.htmlFromResponse(response_document).getElementById("comment-section");
const comments = document.getElementById("comment-section");
comments.replaceWith(new_comments);
- }
+ }
- async submit(event) {
+ async submit(event) {
var form = new FormData(event.target);
form.append("domain", `${window.location.protocol}//${window.location.host}`);
super.submit(event, `${this.comments_server_host}/api/comments?path=${this.post}`, form);
- }
- }
+ }
+}