FIX: clear uploads after successfully posting new PM

This commit is contained in:
Sam Saffron 2025-05-02 09:24:01 +10:00
parent 9196546f6f
commit a3e76c0b2a
No known key found for this signature in database
GPG Key ID: B9606168D2FFD9F5
4 changed files with 13 additions and 6 deletions

View File

@ -3,6 +3,7 @@ import Controller from "@ember/controller";
import { action } from "@ember/object";
import { getOwner } from "@ember/owner";
import { service } from "@ember/service";
import { popupAjaxError } from "discourse/lib/ajax-error";
import UppyUpload from "discourse/lib/uppy/uppy-upload";
import UppyMediaOptimization from "discourse/lib/uppy-media-optimization-plugin";
import { clipboardHelpers } from "discourse/lib/utilities";
@ -172,10 +173,15 @@ export default class DiscourseAiBotConversations extends Controller {
}
@action
prepareAndSubmitToBot() {
async prepareAndSubmitToBot() {
// Pass uploads to the service before submitting
this.aiBotConversationsHiddenSubmit.uploads = this.uploads;
this.aiBotConversationsHiddenSubmit.submitToBot();
try {
await this.aiBotConversationsHiddenSubmit.prepareAndSubmitToBot();
this.uploads.clear();
} catch (error) {
popupAjaxError(error);
}
}
_autoExpandTextarea() {

View File

@ -3,7 +3,6 @@ import { next } from "@ember/runloop";
import Service, { service } from "@ember/service";
import { tracked } from "@ember-compat/tracked-built-ins";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { getUploadMarkdown } from "discourse/lib/uploads";
import { i18n } from "discourse-i18n";
@ -89,8 +88,6 @@ export default class AiBotConversationsHiddenSubmit extends Service {
});
this.router.transitionTo(response.post_url);
} catch (e) {
popupAjaxError(e);
} finally {
this.loading = false;
}

View File

@ -319,7 +319,7 @@ export default {
// force Glimmer to re-render that one link
this.links = this.links.map((link) =>
link.topic.id === topic.id
link?.topic?.id === topic.id
? new AiConversationLink(topic)
: link
);

View File

@ -131,6 +131,10 @@ RSpec.describe "AI Bot - Homepage", type: :system do
expect(topic_page).to have_content("Here are two image attachments")
expect(page).to have_css(".cooked img", count: 2)
end
find(".ai-new-question-button").click
expect(ai_pm_homepage).to have_homepage
expect(page).to have_no_css(".ai-bot-upload")
end
it "allows removing an upload before submission" do