discourse-ai/assets/javascripts/discourse/lib/ai-helper-suggestions.js
Keegan George 442530a154
UX: Show error and ability to try again when no suggestions (#1426)
## 🔍  Overview
When the title suggestions return no suggestions, there is no indication in the UI. In the tag suggester we show a toast when there aren't any suggestions but the request was a success. In this update we make a similar UI indication with a toast for both category and title suggestions. Additionally, for all suggestions we add a "Try again" button to the toast so that suggestions can be generated again if the results yield nothing the first time.
2025-06-11 12:05:10 -07:00

34 lines
916 B
JavaScript

import { getOwner } from "@ember/application";
import { later } from "@ember/runloop";
import { i18n } from "discourse-i18n";
export const MIN_CHARACTER_COUNT = 40;
export function showSuggestionsError(context, reloadFn) {
const toasts = getOwner(context).lookup("service:toasts");
toasts.error({
class: "ai-suggestion-error",
duration: "long",
showProgressBar: true,
data: {
message: i18n("discourse_ai.ai_helper.suggest_errors.no_suggestions"),
actions: [
{
label: i18n("discourse_ai.ai_helper.context_menu.regen"),
icon: "rotate",
class: "btn btn-small",
action: async (toast) => {
toast.close();
await reloadFn();
if (context.dMenu?.show && context.suggestions?.length > 0) {
later(() => context.dMenu.show(), 50);
}
},
},
],
},
});
}