add reusable babycode editor

This commit is contained in:
2025-05-24 02:45:54 +03:00
parent ec3f144b4e
commit 66318698e5
10 changed files with 116 additions and 33 deletions

View File

@ -9,8 +9,8 @@
</select><br>
<label for="title">Thread title</label>
<input type="text" id="title" name="title" placeholder="Required" required>
<label for="initial_post">Post body</label>
<textarea id="initial_post" name="initial_post" placeholder="Required" rows=5 required></textarea>
<label for="initial_post">Post body</label><br>
<% render("views.common.babycode-editor-component", {ta_name = "initial_post"}) %>
<% render "views.common.bbcode_help" %>
<input type="submit" value="Create thread">
</form>

View File

@ -54,13 +54,11 @@
<% if not edit then %>
<%- post.content %>
<% else %>
<form class="post-edit-form" method="post">
<textarea name="new_content" required><%- post.original_markup %></textarea>
<span>
<input type=submit value="Save">
<a class="linkbutton warn" href="<%= url_for("thread", {slug = thread.slug}, {page = page}) .. "#post-" .. post.id %>">Cancel</a>
</span>
</form>
<% render("views.common.babycode-editor", {
cancel_url = url_for("thread", {slug = thread.slug}, {page = page}) .. "#post-" .. post.id,
prefill = post.original_markup,
ta_name = "new_content"
}) %>
<% end %>
</div>
</div>

View File

@ -1,10 +1,6 @@
<%
local is_locked = ntob(thread.is_locked)
local can_post = (not is_locked and not me:is_guest()) or me:is_mod()
-- not locked, not guest, not mod = not false and not false or false = true and true or false = true
-- locked, not guest, not mod = not true and not false or false = false and true or false = false
-- not locked, guest, not mod = not false and not true or false = true and false or false = false
-- not locked, not guest, mod = not false and not false or true = true and true and true
%>
<main>
<nav class="darkbg">
@ -24,10 +20,7 @@
<% render("views.common.infobox", {kind = constants.InfoboxKind.LOCK, msg = "This thread is locked."}) %>
<% end -%>
<% if can_post then %>
<h1>Respond to "<%= thread.title %>"</h1>
<form method="post">
<textarea id="post_content" name="post_content" placeholder="Response body" rows=7 required></textarea><br>
<input type="submit" value="Post reply">
</form>
<script src="/static/js/thread.js"></script>
<h1>Respond to "<%= thread.title %>"</h1>
<% render("views.common.babycode-editor", {ta_name="post_content"}) %>
<script src="/static/js/thread.js"></script>
<% end %>