add: post titles

This commit is contained in:
trisua 2025-06-08 15:34:29 -04:00
parent 1279536609
commit 5b1db42c51
14 changed files with 230 additions and 13 deletions

View file

@ -87,7 +87,7 @@
(text "{{ components::avatar(username=user.id, size=\"32px\", selector_type=\"id\") }}")
(select
("id" "community_to_post_to")
("onchange" "update_community_avatar(event)")
("onchange" "update_community_avatar(event); check_community_supports_title(event)")
(option
("value" "{{ config.town_square }}")
("selected" "{% if not selected_community -%}true{% else %}false{%- endif %}")
@ -102,6 +102,19 @@
("class" "card flex flex-col gap-2")
("id" "create_form")
("onsubmit" "create_post_from_form(event)")
(div
("class" "flex flex-col gap-1 hidden")
("id" "title_field")
(label
("for" "content")
(text "{{ text \"communities:label.title\" }}"))
(input
("type" "text")
("name" "title")
("id" "title")
("placeholder" "title")
("minlength" "2")
("maxlength" "128")))
(div
("class" "flex flex-col gap-1")
(label
@ -179,6 +192,7 @@
\"community_to_post_to\",
).selectedOptions[0].value,
poll: poll_data[1],
title: e.target.title.value,
}),
);
@ -397,10 +411,29 @@
}
}
function check_community_supports_title(e) {
const element = document.getElementById(\"title_field\");
const id = e.target.selectedOptions[0].value;
fetch(`/api/v1/communities/${id}/supports_titles`)
.then((res) => res.json())
.then((res) => {
if (res.message === \"yes\") {
element.classList.remove(\"hidden\");
} else {
element.classList.add(\"hidden\");
}
});
}
setTimeout(() => {
update_community_avatar({
target: document.getElementById(\"community_to_post_to\"),
});
check_community_supports_title({
target: document.getElementById(\"community_to_post_to\"),
});
}, 150);
async function cancel_create_post() {

View file

@ -922,6 +922,22 @@
\"{{ community.context.enable_questions }}\",
\"checkbox\",
],
[
[
\"enable_titles\",
\"Allow users to attach a title to their posts\",
],
\"{{ community.context.enable_titles }}\",
\"checkbox\",
],
[
[
\"require_titles\",
\"Require users to attach a title to their posts\",
],
\"{{ community.context.require_titles }}\",
\"checkbox\",
],
],
settings,
);