diff --git a/static/css/index.css b/static/css/index.css index e69de29..26d981f 100644 --- a/static/css/index.css +++ b/static/css/index.css @@ -0,0 +1,29 @@ +div.new-topic-form { + padding: 0 0.5rem; +} + +form.new-topic-form input[type="text"] { + margin: 0.5rem 0 0; + padding: 0.5rem; + width: 100%; + border: 1px solid #000; +} + +form.new-topic-form .position { + padding: 0.5rem 0 0; + display: flex; + align-items: center; + justify-content: space-around; +} + +form.new-topic-form input[type="radio"].new-topic-form-position { + appearance: auto; +} + +form.new-topic-form button.new-topic-form-submit-button { + margin: 0.5rem 0 0; + padding: 0.5rem; + width: 100%; + border: 1px solid #0004; + cursor: pointer; +} diff --git a/static/js/index.js b/static/js/index.js index adaa8c1..45d1ac9 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -1,21 +1,32 @@ -const form = document.getElementById("form"); -const button = document.getElementById("button"); +const newTopicFormSubmitButton = document.querySelector("button.new-topic-form-submit-button"); -button.addEventListener("click", (event) => { - const data = new FormData(form); - let obj = {}; - obj.parent_comment_id = 0; - obj.title = data.get("title"); - obj.text = data.get("text"); - obj.attribute = Number(data.get("sanpi")); +newTopicFormSubmitButton.addEventListener("click", () => { + const newTopicForm = document.querySelector("form.new-topic-form"); + let formData = new FormData(newTopicForm); + let requestData = {}; + requestData.parent_comment_id = 0; + requestData.title = formData.get("title"); + requestData.text = formData.get("content"); + if (formData.get("position") === "agree") { + requestData.attribute = 1; + } + if (formData.get("position") === "neutral") { + requestData.attribute = 0; + } + if (formData.get("position") === "disagree") { + requestData.attribute = -1; + } fetch("/comment", { method: "POST", headers: { "Content-Type": "application/json; charset=UTF-8" }, - body: JSON.stringify(obj) - }) - .then((res) => { return res.text(); }) - .then((data) => { console.log(data) }) - .catch((err) => { console.log(err); }); -}, false); + body: JSON.stringify(requestData) + }).then((response) => { + return response.json(); + }).then((responseJSON) => { + location.pathname = `/comment/${responseJSON.comment_id}`; + }).catch((error) => { + console.error(error); + }); +}); diff --git a/templates/index.html b/templates/index.html index e78f199..f1ab5bf 100644 --- a/templates/index.html +++ b/templates/index.html @@ -4,19 +4,39 @@ Document + + -
- - - - - - - - - -
+
+ +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+
\ No newline at end of file