akf-forum/views/thread.ejs

161 lines
4.9 KiB
Text
Raw Normal View History

2022-03-13 16:16:46 +03:00
<!DOCTYPE html>
<html lang="en">
<%- include("extra/meta", {title: thread.title }) %>
2022-03-26 23:28:10 +03:00
2022-08-11 17:55:48 +03:00
2022-08-28 20:36:39 +03:00
<body>
<%- include("extra/navbar") %>
<link href='https://unpkg.com/boxicons@2.1.2/css/boxicons.min.css' rel='stylesheet'>
<link rel="stylesheet" href="/css/thread.css" />
<link rel="stylesheet" href="/css/pages.css" />
2022-08-27 14:08:28 +03:00
<% if (user){ %>
<script type="module" src="/js/thread.js"></script>
<% }; %>
2022-08-29 16:16:44 +03:00
<div style="text-align:center;padding:8px">
2022-08-29 19:31:59 +03:00
<div class="title" id="title"><%= thread.title %></div>
<div class="date">
<%= new Date(thread.time).toLocaleString() %> • Views: <%= thread.views %>%>
</div>
<div class="date">
<a style="color: var(--reaction-hover);" href="/users/<%= thread.author.id %>"><%= thread.author.name %></a> <%= "• "+(thread.edited ? "Edited" : "Not edited")%>
</div>
2022-08-29 16:16:44 +03:00
</div>
<div style="text-align:center;padding:8px">
<% if (user && !thread.deleted){ %>
<a onclick="delete_thread('<%= thread.id %>')" class="btn-outline-primary">DELETE</a>
<a onclick="edit_thread('<%= thread.id %>')" class="btn-outline-primary">EDIT</a>
2022-08-29 16:16:44 +03:00
<% } else if (thread.deleted) { %>
<h3 style="display:inline;">This thread has been deleted</h3>
<a onclick="undelete_thread('<%= thread.id %>')" class="btn-primary">UNDELETE</a>
2022-08-29 16:16:44 +03:00
<% }; %>
</div>
2022-08-29 16:16:44 +03:00
<div id="messages">
2022-03-13 16:16:46 +03:00
2022-08-29 16:16:44 +03:00
<% messages.filter(Boolean).forEach(message=>{ %>
2022-08-29 16:16:44 +03:00
<div class="message" id="message-<%= message.id %>">
<div class="left">
2022-09-09 16:29:36 +03:00
<img src="<%= message.author.avatar %>" />
2022-08-31 16:25:35 +03:00
<div class="username"><a href="/users/<%=message.authorID %>"><%=message.author.name %></a></div>
2022-08-29 16:16:44 +03:00
<div class="date">
<%= new Date(message.time).toLocaleDateString() %>
2022-08-29 16:16:44 +03:00
</div>
<div class="date">
<%= new Date(message.time).toLocaleTimeString() %>
2022-08-29 16:16:44 +03:00
</div>
</div>
2022-08-28 20:36:39 +03:00
2022-08-29 16:16:44 +03:00
<div class="content"><%- message.content %></div>
<% if(user){ %>
2022-08-31 16:25:35 +03:00
<% if(user.id === message.authorID || user.admin){ %>
<div class="dots" onclick="dots('<%=message.id %>')">
2022-08-29 16:16:44 +03:00
<% if (message.deleted){ %>
<i class='bx bx-trash bx-sm' id="deleted" style="color: var(--important);"></i>
2022-08-29 16:16:44 +03:00
<% } %>
2022-08-29 19:31:59 +03:00
<% if (message.edited){ %>
<i class='bx bx-pencil bx-sm' id="edited" style="color: GREEN;"></i>
2022-08-29 19:31:59 +03:00
<% } %>
<i class='bx bx-dots-horizontal-rounded'></i>
2022-08-29 16:16:44 +03:00
</div>
2022-08-28 21:09:15 +03:00
<div class="dots-menu">
<% if (!message.deleted){ %>
<a onclick="delete_message('<%=message.id %>');">Delete</a>
<a onclick="edit_message('<%=message.id %>');">Edit</a>
<% }else { %>
2022-08-29 16:16:44 +03:00
<a onclick="undelete_message('<%=message.id %>');">Undelete</a>
<% } %>
2022-08-29 16:16:44 +03:00
</div>
<% } %>
2022-08-29 16:16:44 +03:00
<div class="reactions">
<div>
<i onclick='react("<%= message.id %>","like");' class='bx bx-like'></i>
<div id="like"><%=message.react.like.length %></div>
2022-08-29 16:16:44 +03:00
</div>
<div>
<i onclick='react("<%= message.id %>","dislike");' class='bx bx-dislike'></i>
<div id="dislike"><%=message.react.dislike.length %></div>
2022-08-29 16:16:44 +03:00
</div>
</div>
<% }; %>
2022-08-28 20:36:39 +03:00
</div>
2022-08-29 16:16:44 +03:00
<% }); %>
2022-08-28 20:36:39 +03:00
</div>
2022-08-29 19:31:59 +03:00
<% if (user){ %>
<div class="message" id="send-div">
2022-08-31 15:28:52 +03:00
<form id="send" style="width:100%">
<textarea rows="4" name="content"></textarea>
2022-08-29 16:16:44 +03:00
<input name="threadID" type="hidden" value="<%= thread.id %>"></input>
2022-08-29 19:31:59 +03:00
<input name="page" type="hidden" value="<%= page %>"></input>
<button class="btn-primary">Send!</button>
2022-08-29 19:31:59 +03:00
</form>
2022-08-29 19:31:59 +03:00
</div>
<script type="module">
import request from "../../js/request.js";
2022-08-29 19:31:59 +03:00
document.getElementById("send").addEventListener("submit", async e => {
2022-08-29 19:31:59 +03:00
e.preventDefault();
2022-08-29 19:31:59 +03:00
const data = new FormData(e.target);
const res = await request("/api/messages", "POST", {
threadID: "<%= thread.id %>",
content: data.get("content")
})
let tp = Number("<%= thread.pages %>")
let tm = Number("<%= thread.count %>")
if (tp * 10 === tm) tp++;
if (res) location.href = `/threads/${data.get("threadID")}?page=${tp-1}`;
});
</script>
2022-08-29 19:31:59 +03:00
<% }%>
<div class="pagination">
<div class="back">
2022-08-29 19:31:59 +03:00
<% if (page > 0){ %>
<a href="<%= thread.getLink() %>?page=<%= page-1 %>" class='bx bxs-chevron-left'></a>
<% } %>
</div>
<div class="numbers">
2022-08-29 19:31:59 +03:00
<% for(let i=0; i < thread.pages; i++){ %>
<a class="number <%= i==page?'active':'' %>" href="<%= thread.getLink() %>?page=<%= i %>"><%= i+1 %></a>
<% } %>
</div>
<div class="after">
2022-08-29 19:31:59 +03:00
<% if (thread.pages-1 > page) { %>
<a href="<%= thread.getLink() %>?page=<%= page +1 %>" class='bx bxs-chevron-right'></a>
2022-08-29 16:16:44 +03:00
<% } %>
</div>
</div>
<script>
document.getElementById("message-<%= scroll %>").scrollIntoView();
function dots(id) {
document.getElementById('message-' + id).querySelector(".dots-menu").classList.toggle('active')
}
</script>
</body>
2022-03-13 16:16:46 +03:00
</html>