fix: fix message submission

This commit is contained in:
Andy Burke 2025-09-12 12:06:12 -07:00
parent e52a9e997c
commit 6df0673c8e
3 changed files with 20 additions and 14 deletions

View file

@ -54,7 +54,7 @@
topic_changed: {
detail: {
previous,
topic: topic_id
topic_id
}
}
});
@ -62,7 +62,7 @@
document.dispatchEvent(new CustomEvent( "topic_changed", {
detail: {
previous,
topic: topic_id
topic_id
}
}));
}
@ -89,14 +89,14 @@
}
}
window.addEventListener("locationchange", extract_url_hash_info);
document.addEventListener( 'topic_changed', ( {detail: { topic }}) => {
if ( !topic ) {
document.addEventListener( 'topic_changed', ( {detail: { topic_id }}) => {
if ( !topic_id ) {
const first_topic_id = TOPICS?.[0]?.id;
if ( first_topic_id ) {
window.location.hash = `/topic/${ first_topic_id }/chat`;
}
}
})
});
let TOPICS = [];
let last_topic_update = undefined;

View file

@ -43,9 +43,10 @@
<script>
{
const form = document.currentScript.closest("form");
const file_input = document.querySelector('input[type="file"]');
const chat_input = document.getElementById("topic-chat-input");
const parent_id_input = document.getElementById("parent-id");
const file_input = form.querySelector('input[type="file"]');
const chat_input = form.querySelector('textarea[name="data.content"]');
const parent_id_input = form.querySelector('input[name="parent_id"]');
const topic_chat_container =
document.getElementById("topic-chat-container");
const topic_chat_content =
@ -53,6 +54,13 @@
let messages_in_flight = {};
document.addEventListener(
"topic_changed",
({ detail: { topic_id } }) => {
form.action = topic_id ? `/api/topics/${topic_id}/events` : "";
},
);
chat_input.addEventListener("keypress", (event) => {
if (event.key === "Enter" && !event.shiftKey) {
form.requestSubmit();
@ -100,8 +108,6 @@
if (form.uploaded_urls.length === 0 && message.length === 0) {
return false;
}
form.action = `/api/topics/${topic_id}/events`;
};
form.on_parsed = (json) => {

View file

@ -349,7 +349,7 @@ async function append_topic_events(events) {
let topic_polling_request_abort_controller = null;
async function poll_for_new_events() {
const topic_chat_content = document.getElementById("topic-chat-content");
const topic_id = topic_chat_content.dataset.topic_id;
const topic_id = document.body.dataset.topic;
const last_message_id = topic_chat_content.dataset.last_message_id;
if (!topic_id) {
@ -418,8 +418,8 @@ async function load_topic(topic_id) {
const events = (await events_response.json()).reverse();
await append_topic_events(events);
poll_for_new_events(topic_id);
poll_for_new_events();
}
document.addEventListener("topic_changed", ({ detail: { topic } }) => {
load_topic(topic);
document.addEventListener("topic_changed", ({ detail: { topic_id } }) => {
load_topic(topic_id);
});