Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 071f635

Browse files
committed
UI basically functioning now
1 parent 496b4c0 commit 071f635

File tree

3 files changed

+38
-77
lines changed

3 files changed

+38
-77
lines changed

assets/javascripts/discourse/components/ai-spam.gjs

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import { service } from "@ember/service";
77
import DButton from "discourse/components/d-button";
88
import DToggleSwitch from "discourse/components/d-toggle-switch";
99
import DTooltip from "discourse/components/d-tooltip";
10+
import withEventValue from "discourse/helpers/with-event-value";
1011
import { ajax } from "discourse/lib/ajax";
1112
import { popupAjaxError } from "discourse/lib/ajax-error";
1213
import i18n from "discourse-common/helpers/i18n";
1314
import ComboBox from "select-kit/components/combo-box";
1415

1516
export default class AiSpam extends Component {
1617
@service siteSettings;
18+
@service toasts;
19+
1720
@tracked
1821
stats = {
1922
scanned_count: 0,
@@ -35,7 +38,7 @@ export default class AiSpam extends Component {
3538
initializeFromModel() {
3639
const model = this.args.model;
3740
this.isEnabled = model.is_enabled;
38-
this.selectedLLM = model.selected_llm;
41+
this.selectedLLM = "custom:" + model.llm_id;
3942
this.customInstructions = model.custom_instructions;
4043
this.stats = model.stats;
4144
}
@@ -50,13 +53,12 @@ export default class AiSpam extends Component {
5053
@action
5154
async toggleEnabled() {
5255
try {
53-
const response = await ajax(
54-
"/admin/plugins/discourse-ai/ai-spam/toggle",
55-
{
56-
type: "PUT",
57-
data: { enabled: !this.isEnabled },
58-
}
59-
);
56+
// so UI responds immediately
57+
this.isEnabled = !this.isEnabled;
58+
const response = await ajax("/admin/plugins/discourse-ai/ai-spam.json", {
59+
type: "PUT",
60+
data: { is_enabled: this.isEnabled },
61+
});
6062
this.isEnabled = response.is_enabled;
6163
} catch (error) {
6264
popupAjaxError(error);
@@ -69,11 +71,19 @@ export default class AiSpam extends Component {
6971
}
7072

7173
@action
72-
async saveInstructions() {
74+
async save() {
75+
const llmId = this.selectedLLM.toString().split(":")[1];
7376
try {
74-
await ajax("/admin/plugins/discourse-ai/ai-spam/instructions", {
77+
await ajax("/admin/plugins/discourse-ai/ai-spam.json", {
7578
type: "PUT",
76-
data: { instructions: this.customInstructions },
79+
data: {
80+
llm_model_id: llmId,
81+
custom_instructions: this.customInstructions,
82+
},
83+
});
84+
this.toasts.success({
85+
data: { message: i18n("discourse_ai.spam.settings_saved") },
86+
duration: 2000,
7787
});
7888
} catch (error) {
7989
popupAjaxError(error);
@@ -87,10 +97,10 @@ export default class AiSpam extends Component {
8797
"discourse_ai.spam.title"
8898
}}</h3>
8999

90-
<div class="control-group ai-persona-editor__priority">
100+
<div class="control-group ai-spam__enabled">
91101
<DToggleSwitch
92102
class="ai-spam__toggle"
93-
@state={{this.enabled}}
103+
@state={{this.isEnabled}}
94104
@label="discourse_ai.spam.enable"
95105
{{on "click" this.toggleEnabled}}
96106
/>
@@ -125,13 +135,10 @@ export default class AiSpam extends Component {
125135
placeholder={{i18n
126136
"discourse_ai.spam.custom_instructions_placeholder"
127137
}}
128-
{{on
129-
"input"
130-
(fn (mut this.customInstructions) value="target.value")
131-
}}
138+
{{on "input" (withEventValue (fn (mut this.customInstructions)))}}
132139
>{{this.customInstructions}}</textarea>
133140
<DButton
134-
@action={{this.saveInstructions}}
141+
@action={{this.save}}
135142
@label="save"
136143
class="ai-spam__instructions-save btn-primary"
137144
/>
@@ -180,26 +187,6 @@ export default class AiSpam extends Component {
180187
>{{this.stats.false_negatives}}</span>
181188
</div>
182189
</div>
183-
184-
<div class="ai-spam__reports">
185-
<h3 class="ai-spam__reports-title">{{i18n
186-
"discourse_ai.spam.reports"
187-
}}</h3>
188-
<div class="ai-spam__reports-links">
189-
<a
190-
href="/review?status=false_positive"
191-
class="ai-spam__reports-link"
192-
>
193-
{{i18n "discourse_ai.spam.view_false_positives"}}
194-
</a>
195-
<a
196-
href="/review?status=missed_spam"
197-
class="ai-spam__reports-link"
198-
>
199-
{{i18n "discourse_ai.spam.view_missed_spam"}}
200-
</a>
201-
</div>
202-
</div>
203190
{{/if}}
204191
</section>
205192
</div>

assets/stylesheets/modules/llms/common/spam.scss

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
margin-bottom: 2em;
99
}
1010

11+
&__enabled {
12+
display: flex;
13+
align-items: center;
14+
gap: 0.4em;
15+
margin-bottom: 1em;
16+
17+
.fk-d-tooltip__trigger {
18+
color: var(--primary-high);
19+
20+
}
21+
}
22+
1123
&__settings-title {
1224
margin-bottom: 1em;
1325
}
@@ -40,16 +52,6 @@
4052
margin-bottom: 1em;
4153
}
4254

43-
&__loading {
44-
width: 32px;
45-
height: 32px;
46-
margin: 2em auto;
47-
border: 3px solid var(--primary-low);
48-
border-top-color: var(--tertiary);
49-
border-radius: 50%;
50-
animation: ai-spam-loading 1s infinite linear;
51-
}
52-
5355
&__metrics {
5456
display: grid;
5557
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
@@ -73,30 +75,4 @@
7375
&__metrics-value {
7476
font-size: var(--font-up-2);
7577
}
76-
77-
&__reports {
78-
margin-top: 2em;
79-
}
80-
81-
&__reports-title {
82-
margin-bottom: 1em;
83-
}
84-
85-
&__reports-links {
86-
display: flex;
87-
gap: 1em;
88-
}
89-
90-
&__reports-link {
91-
@extend .btn;
92-
}
93-
}
94-
95-
@keyframes ai-spam-loading {
96-
from {
97-
transform: rotate(0deg);
98-
}
99-
to {
100-
transform: rotate(360deg);
101-
}
10278
}

config/locales/client.en.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,10 @@ en:
137137
false_positives: "Incorrectly flagged"
138138
false_negatives: "Missed spam"
139139
spam_detected: "Spam detected"
140-
reports: "Reports"
141-
view_false_positives: "View false positives"
142-
view_missed_spam: "View missed spam"
143140
custom_instructions_placeholder: "Site-specific instructions for the AI to help identify spam more accurately."
144141
enable: "Enable"
145142
spam_tip: "AI spam detection will scan the first 3 posts by all new users on public topics. It will flag them for review and block users if they are likely spam."
143+
settings_saved: "Settings saved"
146144

147145
usage:
148146
short_title: "Usage"

0 commit comments

Comments
 (0)