Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions assets/javascripts/discourse/components/modal/diff-modal.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@ export default class ModalDiffModal extends Component {

@tracked loading = false;
@tracked finalResult = "";
@tracked showcasedDiff = "";
@tracked diffStreamer = new DiffStreamer(this.args.model.selectedText);
@tracked suggestion = "";
@tracked
smoothStreamer = new SmoothStreamer(
() => this.suggestion,
(newValue) => (this.suggestion = newValue)
);
@tracked isStreaming = false;

constructor() {
super(...arguments);
this.suggestChanges();
}

get isStreaming() {
return this.diffStreamer.isStreaming || this.smoothStreamer.isStreaming;
}

get primaryBtnLabel() {
return this.loading
? i18n("discourse_ai.ai_helper.context_menu.loading")
Expand All @@ -62,23 +64,14 @@ export default class ModalDiffModal extends Component {

@action
async updateResult(result) {
// TODO(@keegan)
// Temporarily we are removing the animation using the diff streamer
// and simply showing the diff streamed without a proper animation
// while we figure things out
// so that things are not too janky in the meantime.
this.loading = false;
this.isStreaming = true;

if (result.done) {
this.finalResult = result.result;
}

this.showcasedDiff = result.diff;

if (result.done) {
this.loading = false;
this.isStreaming = false;
}

if (this.args.model.showResultAsDiff) {
Expand Down Expand Up @@ -143,7 +136,7 @@ export default class ModalDiffModal extends Component {
<div {{didInsert this.subscribe}} {{willDestroy this.unsubscribe}}>
{{#if this.loading}}
<div class="composer-ai-helper-modal__loading">
<CookText @rawText={{@model.selectedText}} />
{{~@model.selectedText~}}
</div>
{{else}}
<div
Expand All @@ -152,10 +145,13 @@ export default class ModalDiffModal extends Component {
"streamable-content"
(if this.isStreaming "streaming")
(if @model.showResultAsDiff "inline-diff")
(if this.diffStreamer.isThinking "thinking")
}}
>
{{#if @model.showResultAsDiff}}
{{htmlSafe this.showcasedDiff}}
{{~#if @model.showResultAsDiff~}}
<span class="diff-inner">{{htmlSafe
this.diffStreamer.diff
}}</span>
{{else}}
{{#if this.smoothStreamer.isStreaming}}
<CookText
Expand Down
Loading
Loading