This commit is contained in:
Akif9748 2022-08-24 23:10:29 +03:00
parent e5d4ea92ed
commit a857e68617
3 changed files with 30 additions and 15 deletions

View file

@ -76,7 +76,7 @@ And, you can learn about API in `util/APIDOCS.md`.
| auto-scroll | 🟢 | LOW | | auto-scroll | 🟢 | LOW |
| Multi-theme support | 🔴 | LOW | | Multi-theme support | 🔴 | LOW |
| Search | 🔴 | MEDIUM | | Search | 🔴 | MEDIUM |
| Better view, page support | 🔴 | MEDIUM | | Better view, page support, support message limit correct | 🔴 | MEDIUM |
| Sending message etc. will use fetch API | 🟢 | HIGH | | Sending message etc. will use fetch API | 🟢 | HIGH |
## Screenshot ## Screenshot

View file

@ -1,7 +1,7 @@
import request from "./request.js"; import request from "./request.js";
const messages = document.getElementById("messages"); const messages = document.getElementById("messages");
let messages_raw = [];
function renderMessage(message) { function renderMessage(message) {
const messageElement = document.createElement("div"); const messageElement = document.createElement("div");
messageElement.classList.add("message"); messageElement.classList.add("message");
@ -40,16 +40,15 @@ function renderMessage(message) {
*/ */
(async () => { (async () => {
const result = await fetch(`/api/threads/${messages.getAttribute("value")}/messages/`).then(res => res.json()); messages_raw = await fetch(`/api/threads/${messages.getAttribute("value")}/messages/`).then(res => res.json());
if (messages_raw?.error) {
if (result?.error) {
document.getElementById("messages").innerHTML document.getElementById("messages").innerHTML
+= '<div class="message"><h1>THIS THREAD HAS NOT GOT ANY MESSAGE</h1></div>'; += '<div class="message"><h1>THIS THREAD HAS NOT GOT ANY MESSAGE</h1></div>';
} else } else
for (const message of result) for (const message of messages_raw)
renderMessage(message); renderMessage(message);
window.scrollTo(0, document.body.scrollHeight); window.scrollTo(0, document.body.scrollHeight);
@ -80,6 +79,7 @@ document.getElementById("send").addEventListener("submit", async e => {
* Button Listener * Button Listener
*/ */
document.addEventListener("click", async e => { document.addEventListener("click", async e => {
let page = 1;
// e.preventDefault(); // e.preventDefault();
if (e.target.id === "delete_thread") { if (e.target.id === "delete_thread") {
const response = await request("/api/threads/" + e.target.value + "/delete"); const response = await request("/api/threads/" + e.target.value + "/delete");
@ -95,6 +95,16 @@ document.addEventListener("click", async e => {
alert("Message deleted"); alert("Message deleted");
document.getElementById("message-delete-" + e.target.value).innerHTML = "<h3 style=\"display:inline;\">This message has been deleted</h3>"; document.getElementById("message-delete-" + e.target.value).innerHTML = "<h3 style=\"display:inline;\">This message has been deleted</h3>";
} }
} else if (e.target.id === "left_page") {
e.preventDefault();
}else if (e.target.id === "right_page") {
e.preventDefault();
const response = await request(`/api/messages/${e.target.value}/delete`);
if (response.deleted) {
alert("Message deleted");
document.getElementById("message-delete-" + e.target.value).innerHTML = "<h3 style=\"display:inline;\">This message has been deleted</h3>";
}
}/*else if (e.target.id === "edit_thread") { }/*else if (e.target.id === "edit_thread") {
window.location.href = "/threads/<%= thread.id }/edit"; window.location.href = "/threads/<%= thread.id }/edit";
} */ } */

View file

@ -55,9 +55,14 @@
<script> <script>
document.getElementById("message-<%= scroll %>").scrollIntoView(); document.getElementById("message-<%= scroll %>").scrollIntoView();
</script> </script>
<!-- <button id="left_page" style=" float: right;" type="submit">PREV</button>
<button id="right_page" style="display:inline;float: right;" type="submit">NEXT</button>--> <!-- <div style="float: right;">
<h3 id="page_count" style="display:inline;">1</h3>
<button id="left_page" style=" display:inline;float: right;" type="submit">PREV</button>
<button id="right_page" style="display:inline;float: right;" type="submit">NEXT</button>
</div>-->
<%- include("extra/footer") %> <%- include("extra/footer") %>
</body> </body>