No JS replybox

FossilOrigin-Name: 47e174164920f713bc3f7409dbc1e0b9195677fcf4b064679dffd76a2ab399fd
This commit is contained in:
nekobit 2022-07-18 23:15:29 +00:00
parent 1083ed03ff
commit 5e9701dfa3
9 changed files with 55 additions and 112 deletions

105
dist/js/main.js vendored
View File

@ -1,12 +1,4 @@
(function(){
// Global state variable
// let state = {
// file: {
// files: {},
// file_counter: 0,
// }
// };
Element.prototype.insertAfter = function(element) {
element.parentNode.insertBefore(this, element.nextSibling);
};
@ -44,77 +36,7 @@
document.querySelectorAll("input[type=text], input[type=url], input[type=email], input[type=password], textarea").forEach((i) => {
i.addEventListener("keydown", e => form_enter_submit(e, i));
});
function construct_quick_reply_form(status)
{
let src = document.createElement("form");
src.action = "/status/create";
src.method = "post";
src.enctype = "multipart/form-data";
src.className = "statusbox-quickreply";
let hiddeninput = document.createElement("input");
hiddeninput.type = "hidden";
hiddeninput.name = "replyid"
hiddeninput.value = status.id;
let statusbox = document.createElement("div");
statusbox.className = "statusbox statusbox-ani";
let textarea = document.createElement("textarea");
textarea.placeholder = "Just landed in N.Y.";
textarea.rows = 5;
textarea.tabindex = 1;
textarea.name = "content";
// Load placeholder text
let instance_info = status.querySelector(".instance-info");
textarea.innerText = reply_get_mentions(
instance_info ? instance_info.innerText : null,
status.querySelector(".status-content").innerHTML
);
let statusfooter = document.createElement("div");
statusfooter.className = "statusfooter";
let statusfooter_sides = {
left: document.createElement("div"),
right: document.createElement("div"),
}
let select = document.createElement("select");
let files_input = document.createElement("input");
statusfooter_sides.left.className = "statusfooter-left";
select.innerHTML = `
<option value="public">Public</option>
<option value="unlisted">Unlisted</option>
<option value="private">Private</option>
<option value="direct">Direct</option>
<option value="local">Local</option>
`.trim();
files_input.type = "file";
files_input.name = "file";
files_input.tabindex = 4;
files_input.multiple = "";
statusfooter_sides.right.className = "statusfooter-right";
let submitbtn = document.createElement("input");
submitbtn.className = "btn post-btn";
submitbtn.type = "submit";
submitbtn.value = "Post";
submitbtn.tabindex = 2;
statusfooter_sides.left.appendChild(select);
statusfooter_sides.left.appendChild(files_input);
statusfooter_sides.right.appendChild(submitbtn);
statusfooter.appendChild(statusfooter_sides.left);
statusfooter.appendChild(statusfooter_sides.right);
statusbox.appendChild(textarea);
textarea.addEventListener("keydown", e => form_enter_submit(e, textarea));
statusbox.appendChild(statusfooter);
src.appendChild(hiddeninput);
src.appendChild(statusbox);
return src;
}
function construct_query(query)
{
query_string = "";
@ -239,24 +161,6 @@
return false;
}
function create_reply_form(e)
{
e.preventDefault();
let status = e.target.closest(".status");
if (status.nextSibling.className === "statusbox-quickreply")
{
status.nextSibling.remove();
}
else {
let form = construct_quick_reply_form(status);
form.insertAfter(status);
}
return false;
}
function frame_resize()
{
let rightbar_frame = document.querySelector("#rightbar .sidebar-frame");
@ -379,10 +283,6 @@
let interact_btn = document.getElementsByClassName("statbtn");
// Add event listener to add specificied buttons
for (let i = 0; i < reply_btn.length; ++i)
{
reply_btn[i].addEventListener('click', create_reply_form);
}
for (let i = 0; i < interact_btn.length; ++i)
{
interact_btn[i].addEventListener('click', status_interact_props);
@ -401,8 +301,5 @@
{
file_input.addEventListener('change', evt_file_upload);
}
// let submit = document.querySelector("form");
// submit.onsubmit
});
})();

5
dist/treebird.css vendored
View File

@ -715,6 +715,11 @@ svg.in-reply-to-icon
line-height: 23px;
}
input[type=checkbox].hidden:not(:checked) + .reply-form
{
display: none;
}
.notification-compact .notification-content
{
color: #808080;

View File

@ -49,6 +49,8 @@
#include "../static/likeboost.ctmpl"
#include "../static/reactions_btn.ctmpl"
#include "../static/interaction_buttons.ctmpl"
#include "../static/reply_link.ctmpl"
#include "../static/reply_checkbox.ctmpl"
#include "../static/menu_item.ctmpl"
#include "../static/like_btn.ctmpl"
#include "../static/repeat_btn.ctmpl"
@ -270,6 +272,7 @@ char* construct_interaction_buttons(struct session* ssn,
char* likeboost_html = NULL;
char* reply_count = NULL;
char* repeat_count = NULL;
char* reply_btn;
char* favourites_count = NULL;
char* emoji_picker_html = NULL;
char* reactions_btn_html = NULL;
@ -323,17 +326,36 @@ char* construct_interaction_buttons(struct session* ssn,
struct like_btn_template ldata = { .favourite_active = status->favourited ? "active" : "" };
like_btn = tmpl_gen_like_btn(&ldata, NULL);
}
// Weather it should be a link or a <label> button
if ((flags & STATUS_NO_QUICKREPLY) != STATUS_NO_QUICKREPLY)
{
struct reply_checkbox_template tmpl = {
.reply_btn = use_img ? data_reply_btn_img : data_reply_btn,
.reply_count = reply_count,
.status_id = status->id,
};
reply_btn = tmpl_gen_reply_checkbox(&tmpl, NULL);
}
else {
struct reply_link_template tmpl = {
.prefix = config_url_prefix,
.reply_btn = use_img ? data_reply_btn_img : data_reply_btn,
.reply_count = reply_count,
.status_id = status->id,
};
reply_btn = tmpl_gen_reply_link(&tmpl, NULL);
}
struct interaction_buttons_template data = {
// Icons
.reply_btn = use_img ? data_reply_btn_img : data_reply_btn,
.reply_btn = reply_btn,
.expand_btn = use_img ? data_expand_btn_img : data_expand_btn,
.repeat_btn = repeat_btn,
.like_btn = like_btn,
// Interactions data
.prefix = config_url_prefix,
.status_id = status->id,
.reply_count = reply_count,
.unrepeat = status->reblogged ? "un" : "",
.repeats_count = repeat_count,
.repeat_text = "Repeat",
@ -357,6 +379,7 @@ char* construct_interaction_buttons(struct session* ssn,
free(reactions_btn_html);
free(likeboost_html);
free(time_str);
free(reply_btn);
free(like_btn);
free(repeat_btn);
return interaction_html;
@ -680,6 +703,7 @@ char* construct_status(struct session* ssn,
char* serialized_display_name = NULL;
char* interaction_btns = NULL;
char* notif_info = NULL;
char* post_response = NULL;
char* in_reply_to_str = NULL;
char* delete_status = NULL;
char* pin_status = NULL;
@ -770,6 +794,9 @@ char* construct_status(struct session* ssn,
free(repl_str);
}
if (ssn->logged_in)
post_response = reply_status(ssn, status->in_reply_to_account_id , status);
// Delete status menu item and pinned, logged in only
if (ssn->logged_in && strcmp(status->account.acct, ssn->acct.acct) == 0)
{
@ -836,7 +863,8 @@ char* construct_status(struct session* ssn,
.attachments = attachments,
.interactions = interactions_html,
.emoji_reactions = emoji_reactions,
.interaction_btns = interaction_btns
.interaction_btns = interaction_btns,
.reply = post_response,
};
stat_html = tmpl_gen_status(&tmpl, size);
@ -850,6 +878,7 @@ char* construct_status(struct session* ssn,
free(interaction_btns);
free(in_reply_to_str);
free(attachments);
free(post_response);
free(emoji_reactions);
if (notif) free(notif_info);
free(delete_status);

View File

@ -30,6 +30,7 @@
#define STATUS_EMOJI_PICKER (1<<2)
#define STATUS_NO_LIKEBOOST (1<<3)
#define STATUS_NO_DOPAMEME (1<<4)
#define STATUS_NO_QUICKREPLY (1<<5)
struct construct_statuses_args
{

View File

@ -2,10 +2,7 @@
<table class="ui-table">
<tr>
<td>
<a target="_parent" href="{{%s:prefix}}/status/{{%s:status_id}}/reply#{{%s:status_id}}" class="pointer statbtn reply-btn">
{{ %s : reply_btn }}
<span class="count">{{%s:reply_count}}</span>
</a>
{{ %s : reply_btn }}
</td>
<td>
<form action="{{%s:prefix}}/status/{{%s:status_id}}/interact" method="post">

View File

@ -1,4 +1,4 @@
<form action="{{%s:prefix}}/status/create" method="post" enctype="multipart/form-data">
<form class="reply-form" action="{{%s:prefix}}/status/create" method="post" enctype="multipart/form-data">
{{%s:reply_input}}
<div class="statusbox">
<textarea name="content" placeholder="Just landed in N.Y." rows="5">{{%s:content}}</textarea>
@ -61,3 +61,4 @@
<div class="file-uploads-container hidden"></div>
</div>
</form>

View File

@ -0,0 +1,5 @@
<label for="status-quickreply-{{%s:status_id}}" class="pointer statbtn reply-btn">
{{ %s : reply_btn }}
<span class="count">{{%s:reply_count}}</span>
</label>

5
static/reply_link.tmpl Normal file
View File

@ -0,0 +1,5 @@
<a target="_parent" href="{{%s:prefix}}/status/{{%s:status_id}}/reply#{{%s:status_id}}" class="pointer statbtn reply-btn">
{{ %s : reply_btn }}
<span class="count">{{%s:reply_count}}</span>
</a>

View File

@ -49,3 +49,6 @@
</tr>
</table>
</div>
<input type="checkbox" class="quickreply-hide hidden" id="status-quickreply-{{%s:status_id}}">
{{ %s : reply }}