add: ability to upload images while creating a reply or answer

This commit is contained in:
trisua 2025-05-11 15:34:09 -04:00
parent eb95be0f38
commit 68c3a5d84e
2 changed files with 38 additions and 7 deletions

View file

@ -108,7 +108,14 @@
></textarea>
</div>
<div id="files_list" class="flex gap-2 flex-wrap"></div>
<div class="flex gap-2">
{{ components::emoji_picker(element_id="content",
render_dialog=true) }} {% if is_supporter %} {{
components::file_picker(files_list_id="files_list") }}
{% endif %}
<button class="primary">{{ text "requests:label.answer" }}</button>
<button type="button" class="red quaternary" onclick="trigger('me::remove_question', ['{{ question[0].id }}'])">{{ text "general:action.delete" }}</button>
<button type="button" class="red quaternary" onclick="trigger('me::ip_block_question', ['{{ question[0].id }}'])">{{ text "auth:action.ip_block" }}</button>
@ -166,16 +173,30 @@
window.answer_question_from_form = async (e, answering) => {
e.preventDefault();
await trigger("atto::debounce", ["posts::create"]);
fetch("/api/v1/posts", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
// create body
const body = new FormData();
if (e.target.file_picker) {
for (const file of e.target.file_picker.files) {
body.append(file.name, file);
}
}
body.append(
"body",
JSON.stringify({
content: e.target.content.value,
community: "{{ config.town_square }}",
answering,
}),
);
// ...
fetch("/api/v1/posts", {
method: "POST",
body,
})
.then((res) => res.json())
.then((res) => {

View file

@ -43,9 +43,13 @@
></textarea>
</div>
<div id="files_list" class="flex gap-2 flex-wrap"></div>
<div class="flex gap-2">
{{ components::emoji_picker(element_id="content",
render_dialog=true) }}
render_dialog=true) }} {% if is_supporter %} {{
components::file_picker(files_list_id="files_list") }} {% endif
%}
<button class="primary">
{{ text "communities:action.create" }}
@ -294,6 +298,12 @@
// create body
const body = new FormData();
if (e.target.file_picker) {
for (const file of e.target.file_picker.files) {
body.append(file.name, file);
}
}
body.append(
"body",
JSON.stringify({