From 52339e6b9895acb1e39892aac0883091ec7601b0 Mon Sep 17 00:00:00 2001
From: trisua <me@trisua.com>
Date: Sun, 11 May 2025 15:40:03 -0400
Subject: [PATCH] fix: global question answering

---
 .../src/public/html/communities/question.html | 40 ++++++++++++++-----
 1 file changed, 31 insertions(+), 9 deletions(-)

diff --git a/crates/app/src/public/html/communities/question.html b/crates/app/src/public/html/communities/question.html
index 46e5e38..8644251 100644
--- a/crates/app/src/public/html/communities/question.html
+++ b/crates/app/src/public/html/communities/question.html
@@ -33,9 +33,18 @@
                 ></textarea>
             </div>
 
-            <button class="primary">
-                {{ text "communities:action.create" }}
-            </button>
+            <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>
+            </div>
         </form>
     </div>
     {% endif %}
@@ -62,16 +71,29 @@
     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: community ? community : "{{ config.town_square }}",
                 answering,
             }),
+        );
+
+        // ...
+        fetch("/api/v1/posts", {
+            method: "POST",
+            body,
         })
             .then((res) => res.json())
             .then((res) => {