2022-08-11 01:36:53 +03:00
|
|
|
import request from "./request.js";
|
2022-08-11 17:55:48 +03:00
|
|
|
|
2022-08-31 16:05:23 +03:00
|
|
|
window.edit_thread = async function (id) {
|
2022-08-29 19:31:59 +03:00
|
|
|
const title = prompt("Enter new title!");
|
2022-08-31 16:05:23 +03:00
|
|
|
const res = await request(`/api/threads/${id}/`, "PATCH", { title });
|
2022-08-29 19:31:59 +03:00
|
|
|
if (res.error) return;
|
|
|
|
alert(`Thread updated`);
|
|
|
|
document.getElementById("title").innerHTML = title;
|
|
|
|
|
|
|
|
}
|
2022-08-29 21:32:57 +03:00
|
|
|
window.delete_thread = async function (id) {
|
|
|
|
const res = await request(`/api/threads/${id}/`, "DELETE");
|
|
|
|
if (res.error) return;
|
2022-08-29 19:31:59 +03:00
|
|
|
|
2022-08-29 21:32:57 +03:00
|
|
|
alert(`Thread deleted`);
|
|
|
|
location.reload();
|
|
|
|
}
|
2022-08-29 19:31:59 +03:00
|
|
|
|
2022-08-29 21:32:57 +03:00
|
|
|
window.undelete_thread = async function (id) {
|
|
|
|
const res = await request(`/api/threads/${id}/undelete`);
|
2022-08-29 19:31:59 +03:00
|
|
|
if (res.error) return;
|
|
|
|
|
2022-08-29 21:32:57 +03:00
|
|
|
alert(`Thread undeleted`);
|
2022-08-29 16:26:34 +03:00
|
|
|
location.reload();
|
2022-08-27 14:08:28 +03:00
|
|
|
}
|
2022-08-29 19:31:59 +03:00
|
|
|
window.edit_message = async function (id) {
|
|
|
|
const content = prompt("Enter new content!");
|
2022-08-29 21:32:57 +03:00
|
|
|
const res = await request(`/api/messages/${id}/`, "PATCH", { content });
|
2022-08-31 16:05:23 +03:00
|
|
|
if (res && res.error) return;
|
2022-08-29 19:31:59 +03:00
|
|
|
|
|
|
|
alert(`Message updated`);
|
|
|
|
document.getElementById("message-" + id).querySelector(".content").innerHTML = content;
|
|
|
|
|
|
|
|
}
|
2022-08-29 16:16:44 +03:00
|
|
|
window.undelete_message = async function (id) {
|
2022-08-27 14:08:28 +03:00
|
|
|
const response = await request(`/api/messages/${id}/undelete`);
|
2022-08-29 16:16:44 +03:00
|
|
|
if (response.deleted) return;
|
|
|
|
document.getElementById("deleted-" + id).remove();
|
|
|
|
document.getElementById("dot-" + id).innerHTML = `
|
|
|
|
<a onclick="delete_message('${id}');">DELETE</a>
|
2022-08-29 19:31:59 +03:00
|
|
|
<a onclick="edit_message('${id}');">EDIT</a>`
|
2022-08-27 14:08:28 +03:00
|
|
|
}
|
2022-08-29 19:31:59 +03:00
|
|
|
|
2022-08-29 16:16:44 +03:00
|
|
|
window.delete_message = async function (id) {
|
2022-08-31 16:05:23 +03:00
|
|
|
const response = await request(`/api/messages/${id}/`, "DELETE");
|
2022-08-27 14:08:28 +03:00
|
|
|
if (response.deleted) {
|
|
|
|
alert("Message deleted");
|
2022-08-29 16:16:44 +03:00
|
|
|
document.getElementById("dots-" + id).innerHTML = `
|
2022-08-31 18:14:21 +03:00
|
|
|
<i class='bx bx-trash bx-sm' id="deleted-${id}" style="color: var(--important)"></i>
|
2022-08-29 16:16:44 +03:00
|
|
|
`+ document.getElementById("dots-" + id).innerHTML;
|
2022-08-29 16:26:34 +03:00
|
|
|
document.getElementById("dot-" + id).innerHTML = `<a onclick="undelete_message('${id}');">UNDELETE</a>`;
|
2022-08-27 14:08:28 +03:00
|
|
|
}
|
|
|
|
}
|
2022-08-29 19:31:59 +03:00
|
|
|
|
2022-08-29 16:16:44 +03:00
|
|
|
window.react = async function (id, type) {
|
2022-08-27 14:08:28 +03:00
|
|
|
const res = await request(`/api/messages/${id}/react/${type}`)
|
2022-08-29 16:16:44 +03:00
|
|
|
document.getElementById(`like-${id}`).innerHTML = res.react.like.length;
|
|
|
|
document.getElementById(`dislike-${id}`).innerHTML = res.react.dislike.length;
|
2022-08-27 14:08:28 +03:00
|
|
|
}
|