Compare commits

..

3 Commits

5 changed files with 25 additions and 12 deletions

View File

@ -94,11 +94,15 @@ app:get("topic", "/:slug", function(self)
topic_id = topic.id topic_id = topic.id
})) }))
self.topic = topic self.topic = topic
local sort_by = self.session.sort_by or "activity"
self.pages = math.max(math.ceil(threads_count / THREADS_PER_PAGE), 1) local order_clause = ""
self.page = math.max(1, math.min(tonumber(self.params.page) or 1, self.pages)) if sort_by == "thread" then
-- self.threads_list = db.query("SELECT * FROM threads WHERE topic_id = ? ORDER BY is_stickied DESC, created_at DESC", topic.id) order_clause = "ORDER BY threads.is_stickied DESC, threads.created_at DESC"
self.threads_list = db.query([[ else
order_clause = "ORDER BY threads.is_stickied DESC, latest_post_created_at DESC"
end
local query = [[
SELECT SELECT
threads.title, threads.slug, threads.created_at, threads.is_locked, threads.is_stickied, threads.title, threads.slug, threads.created_at, threads.is_locked, threads.is_stickied,
users.username AS started_by, users.username AS started_by,
@ -126,11 +130,11 @@ app:get("topic", "/:slug", function(self)
users u ON u.id = posts.user_id users u ON u.id = posts.user_id
WHERE WHERE
threads.topic_id = ? threads.topic_id = ?
ORDER BY ]] .. order_clause .. " LIMIT ? OFFSET ?"
threads.is_stickied DESC,
threads.created_at DESC self.pages = math.max(math.ceil(threads_count / THREADS_PER_PAGE), 1)
LIMIT ? OFFSET ? self.page = math.max(1, math.min(tonumber(self.params.page) or 1, self.pages))
]], topic.id, THREADS_PER_PAGE, (self.page - 1) * THREADS_PER_PAGE) self.threads_list = db.query(query, topic.id, THREADS_PER_PAGE, (self.page - 1) * THREADS_PER_PAGE)
local user = util.get_logged_in_user_or_transient(self) local user = util.get_logged_in_user_or_transient(self)
self.me = user self.me = user

View File

@ -261,7 +261,9 @@ app:post("user_settings", "/:username/settings", function(self)
if me.id ~= target_user.id then if me.id ~= target_user.id then
return {redirect_to = self:url_for("user", {username = self.params.username})} return {redirect_to = self:url_for("user", {username = self.params.username})}
end end
if self.params.topic_sort_by == "activity" or self.params.topic_sort_by == "thread" then
self.session.sort_by = self.params.topic_sort_by
end
local status = self.params.status:sub(1, 100) local status = self.params.status:sub(1, 100)
local original_sig = self.params.signature or "" local original_sig = self.params.signature or ""
local rendered_sig = babycode.to_html(original_sig, html_escape) local rendered_sig = babycode.to_html(original_sig, html_escape)

View File

@ -111,7 +111,7 @@
<section class="babycode-guide-section"> <section class="babycode-guide-section">
<h2 id="paragraph-rules">Paragraph rules</h2> <h2 id="paragraph-rules">Paragraph rules</h2>
<% table.insert(tocs, {"Paragraph rules", "paragraph-rules"}) %> <% table.insert(tocs, {"Paragraph rules", "paragraph-rules"}) %>
<p>Line breaks in babycode work more like Markdown: to start a new paragraph, use two line breaks:</p> <p>Line breaks in babycode work like Markdown: to start a new paragraph, use two line breaks:</p>
<pre><span class="copy-code-container"><button type=button class="copy-code" value="paragraph 1 <pre><span class="copy-code-container"><button type=button class="copy-code" value="paragraph 1
paragraph 2">Copy</button></span><code>paragraph 1 paragraph 2">Copy</button></span><code>paragraph 1

View File

@ -7,6 +7,8 @@
<span> <span>
<% if me and me:is_logged_in() then -%> <% if me and me:is_logged_in() then -%>
Welcome, <a href="<%= url_for("user", {username = me.username}) %>"><%= me.username %></a> Welcome, <a href="<%= url_for("user", {username = me.username}) %>"><%= me.username %></a>
&bullet;
<a href="<%= url_for("user_settings", {username = me.username}) %>">Settings</a>
<% if me:is_mod() then %> <% if me:is_mod() then %>
&bullet; &bullet;
<a href="<%= url_for("user_list") %>">User list</a> <a href="<%= url_for("user_list") %>">User list</a>

View File

@ -15,6 +15,11 @@
</div> </div>
</form> </form>
<form method="post" action=""> <form method="post" action="">
<label for="topic_sort_by">Sort threads by:</label>
<select id="topic_sort_by" name="topic_sort_by">
<option value="activity" <%= session.sort_by == "activity" and "selected" %>>Latest activity</option>
<option value="thread" <%= session.sort_by == "thread" and "selected" %>>Thread creation date</option>
</select>
<label for="status">Status</label> <label for="status">Status</label>
<input type="text" id="status" name="status" value="<%= me.status %>" maxlength="70" placeholder="Will be shown under your username. Max 70 characters"> <input type="text" id="status" name="status" value="<%= me.status %>" maxlength="70" placeholder="Will be shown under your username. Max 70 characters">
<label for="babycode-content">Signature</label><br> <label for="babycode-content">Signature</label><br>