Compare commits
2 Commits
ccb2819b01
...
ca0256268b
Author | SHA1 | Date | |
---|---|---|---|
ca0256268b | |||
8a9a5e5bd9 |
@ -8,7 +8,7 @@ local util = require("util")
|
|||||||
local models = require("models")
|
local models = require("models")
|
||||||
local Posts = models.Posts
|
local Posts = models.Posts
|
||||||
local Threads = models.Threads
|
local Threads = models.Threads
|
||||||
|
local PostHistory = models.PostHistory
|
||||||
|
|
||||||
app:get("single_post", "/:post_id", function(self)
|
app:get("single_post", "/:post_id", function(self)
|
||||||
local query = constants.FULL_POSTS_QUERY .. "WHERE posts.id = ?"
|
local query = constants.FULL_POSTS_QUERY .. "WHERE posts.id = ?"
|
||||||
@ -22,6 +22,33 @@ app:get("single_post", "/:post_id", function(self)
|
|||||||
return {render = "post.single-post"}
|
return {render = "post.single-post"}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
app:post("delete_post", "/:post_id/delete", function(self)
|
||||||
|
local user = util.get_logged_in_user(self)
|
||||||
|
if not user then
|
||||||
|
return {redirect_to = self:url_for"all_topics"}
|
||||||
|
end
|
||||||
|
print("id is " .. self.params.post_id)
|
||||||
|
local post = Posts:find({id = self.params.post_id})
|
||||||
|
if not post then
|
||||||
|
return {redirect_to = self:url_for"all_topics"}
|
||||||
|
end
|
||||||
|
|
||||||
|
local thread = Threads:find({id = post.thread_id})
|
||||||
|
if user:is_mod() then
|
||||||
|
post:delete()
|
||||||
|
util.inject_infobox(self, "Post deleted.")
|
||||||
|
return {redirect_to = self:url_for("thread", {slug = thread.slug})}
|
||||||
|
end
|
||||||
|
|
||||||
|
if post.user_id ~= user.id then
|
||||||
|
return {redirect_to = self:url_for"all_topics"}
|
||||||
|
end
|
||||||
|
|
||||||
|
post:delete()
|
||||||
|
util.inject_infobox(self, "Post deleted.")
|
||||||
|
return {redirect_to = self:url_for("thread", {slug = thread.slug})}
|
||||||
|
end)
|
||||||
|
|
||||||
app:get("edit_post", "/:post_id/edit", function(self)
|
app:get("edit_post", "/:post_id/edit", function(self)
|
||||||
local user = util.get_logged_in_user(self)
|
local user = util.get_logged_in_user(self)
|
||||||
if not user then
|
if not user then
|
||||||
@ -48,6 +75,8 @@ app:get("edit_post", "/:post_id/edit", function(self)
|
|||||||
self.prev_context = db.query(context_prev_query, self.thread.id, self.editing_post.created_at)
|
self.prev_context = db.query(context_prev_query, self.thread.id, self.editing_post.created_at)
|
||||||
self.next_context = db.query(context_next_query, self.thread.id, self.editing_post.created_at)
|
self.next_context = db.query(context_next_query, self.thread.id, self.editing_post.created_at)
|
||||||
|
|
||||||
|
self.page_title = "editing a post"
|
||||||
|
|
||||||
return {render = "post.edit-post"}
|
return {render = "post.edit-post"}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -72,4 +101,4 @@ app:post("edit_post", "/:post_id/edit", function(self)
|
|||||||
return {redirect_to = link}
|
return {redirect_to = link}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
@ -23,7 +23,7 @@ app:get("thread_create", "/create", function(self)
|
|||||||
return "how did you get here?"
|
return "how did you get here?"
|
||||||
end
|
end
|
||||||
self.all_topics = all_topics
|
self.all_topics = all_topics
|
||||||
self.page_title = "creating thread"
|
self.page_title = "drafting a thread"
|
||||||
self.me = user
|
self.me = user
|
||||||
return {render = "threads.create"}
|
return {render = "threads.create"}
|
||||||
end)
|
end)
|
||||||
|
@ -53,7 +53,7 @@ app:get("topic_create", "/create", function(self)
|
|||||||
return {status = 403}
|
return {status = 403}
|
||||||
end
|
end
|
||||||
|
|
||||||
self.page_title = "creating topic"
|
self.page_title = "creating a topic"
|
||||||
self.me = user
|
self.me = user
|
||||||
|
|
||||||
return {render = "topics.create"}
|
return {render = "topics.create"}
|
||||||
|
@ -136,6 +136,20 @@ pre code {
|
|||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#delete-dialog {
|
||||||
|
padding: 0;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 2px solid black;
|
||||||
|
box-shadow: 0 0 30px rgba(0, 0, 0, 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-dialog-inner {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
.copy-code-container {
|
.copy-code-container {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
width: calc(100% - 4px);
|
width: calc(100% - 4px);
|
||||||
|
30
js/thread.js
30
js/thread.js
@ -1,10 +1,38 @@
|
|||||||
{
|
{
|
||||||
const ta = document.getElementById("post_content");
|
const ta = document.getElementById("post_content");
|
||||||
|
|
||||||
for (let button of document.querySelectorAll(".reply-button")) {
|
for (let button of document.querySelectorAll(".reply-button")) {
|
||||||
button.addEventListener("click", (e) => {
|
button.addEventListener("click", (e) => {
|
||||||
ta.value += button.value;
|
ta.value += button.value;
|
||||||
ta.scrollIntoView()
|
ta.scrollIntoView()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deleteDialog = document.getElementById("delete-dialog");
|
||||||
|
const deleteDialogCloseButton = document.getElementById("post-delete-dialog-close");
|
||||||
|
let deletionTargetPostContainer;
|
||||||
|
|
||||||
|
function closeDeleteDialog() {
|
||||||
|
deletionTargetPostContainer.style.removeProperty("background-color");
|
||||||
|
deleteDialog.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteDialogCloseButton.addEventListener("click", (e) => {
|
||||||
|
closeDeleteDialog();
|
||||||
|
})
|
||||||
|
deleteDialog.addEventListener("click", (e) => {
|
||||||
|
if (e.target === deleteDialog) {
|
||||||
|
closeDeleteDialog();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
for (let button of document.querySelectorAll(".post-delete-button")) {
|
||||||
|
button.addEventListener("click", (e) => {
|
||||||
|
deleteDialog.showModal();
|
||||||
|
const postId = button.value;
|
||||||
|
deletionTargetPostContainer = document.getElementById("post-" + postId).querySelector(".post-content-container");
|
||||||
|
deletionTargetPostContainer.style.setProperty("background-color", "#fff");
|
||||||
|
const form = document.getElementById("post-delete-form");
|
||||||
|
form.action = `/post/${postId}/delete`
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,6 +172,20 @@ pre code {
|
|||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#delete-dialog {
|
||||||
|
padding: 0;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 2px solid black;
|
||||||
|
box-shadow: 0 0 30px rgba(0, 0, 0, 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-dialog-inner {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
.copy-code-container {
|
.copy-code-container {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
// width: 100%;
|
// width: 100%;
|
||||||
|
@ -53,7 +53,13 @@
|
|||||||
local reply_text = ("%s\n[quote]%s[/quote]\n---\n\n"):format(quote_src_text, post.original_markup)
|
local reply_text = ("%s\n[quote]%s[/quote]\n---\n\n"):format(quote_src_text, post.original_markup)
|
||||||
%>
|
%>
|
||||||
<button value="<%= reply_text %>" class="reply-button">Reply</button>
|
<button value="<%= reply_text %>" class="reply-button">Reply</button>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<%
|
||||||
|
local show_delete = (post.user_id == me.id and not ntob(thread.is_locked)) or me:is_mod()
|
||||||
|
if show_delete then
|
||||||
|
%>
|
||||||
|
<button class="critical post-delete-button" value="<%= post.id %>">Delete</button>
|
||||||
|
<% end %>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="post-content">
|
<div class="post-content">
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
local is_locked = ntob(thread.is_locked)
|
local is_locked = ntob(thread.is_locked)
|
||||||
local can_post = (not is_locked and not me:is_guest()) or me:is_mod()
|
local can_post = (not is_locked and not me:is_guest()) or me:is_mod()
|
||||||
%>
|
%>
|
||||||
|
<% if infobox then %>
|
||||||
|
<% render("views.common.infobox", infobox) %>
|
||||||
|
<% end %>
|
||||||
<main>
|
<main>
|
||||||
<nav class="darkbg">
|
<nav class="darkbg">
|
||||||
<h1 class="thread-title"><%= thread.title %></h1>
|
<h1 class="thread-title"><%= thread.title %></h1>
|
||||||
@ -22,5 +25,15 @@
|
|||||||
<% if can_post then %>
|
<% if can_post then %>
|
||||||
<h1>Respond to "<%= thread.title %>"</h1>
|
<h1>Respond to "<%= thread.title %>"</h1>
|
||||||
<% render("views.common.babycode-editor", {ta_name="post_content"}) %>
|
<% render("views.common.babycode-editor", {ta_name="post_content"}) %>
|
||||||
<script src="/static/js/thread.js"></script>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<dialog id="delete-dialog">
|
||||||
|
<div class=delete-dialog-inner>
|
||||||
|
Are you sure you want to delete the highlighted post?
|
||||||
|
<span>
|
||||||
|
<button id=post-delete-dialog-close>Cancel</button>
|
||||||
|
<button class="critical" form=post-delete-form>Delete</button>
|
||||||
|
<form id="post-delete-form" method="post"></form>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</dialog>
|
||||||
|
<script src="/static/js/thread.js"></script>
|
||||||
|
Loading…
Reference in New Issue
Block a user