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

Commit 36e900f

Browse files
committed
DEV: show old text in reduced opacity
1 parent 21e9a76 commit 36e900f

File tree

3 files changed

+47
-33
lines changed

3 files changed

+47
-33
lines changed

assets/javascripts/discourse/components/modal/diff-modal.gjs

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ export default class ModalDiffModal extends Component {
3939
return this.diffStreamer.isStreaming || this.smoothStreamer.isStreaming;
4040
}
4141

42+
get primaryBtnLabel() {
43+
return this.loading
44+
? i18n("discourse_ai.ai_helper.context_menu.loading")
45+
: i18n("discourse_ai.ai_helper.context_menu.confirm");
46+
}
47+
48+
get primaryBtnDisabled() {
49+
return this.loading || this.isStreaming;
50+
}
51+
4252
@bind
4353
subscribe() {
4454
const channel = "/discourse-ai/ai-helper/stream_composer_suggestion";
@@ -66,9 +76,9 @@ export default class ModalDiffModal extends Component {
6676
async suggestChanges() {
6777
this.smoothStreamer.resetStreaming();
6878
this.diffStreamer.reset();
69-
this.loading = true;
7079

7180
try {
81+
this.loading = true;
7282
return await ajax("/discourse-ai/ai-helper/stream_suggestion", {
7383
method: "POST",
7484
data: {
@@ -150,33 +160,27 @@ export default class ModalDiffModal extends Component {
150160
</:body>
151161

152162
<:footer>
153-
{{#if this.loading}}
154-
<DButton
155-
class="btn-primary"
156-
@label="discourse_ai.ai_helper.context_menu.loading"
157-
@disabled={{true}}
158-
>
163+
<DButton
164+
class="btn-primary confirm"
165+
@disabled={{this.primaryBtnDisabled}}
166+
@action={{this.triggerConfirmChanges}}
167+
@translatedLabel={{this.primaryBtnLabel}}
168+
>
169+
{{#if this.loading}}
159170
<AiIndicatorWave @loading={{this.loading}} />
160-
</DButton>
161-
{{else}}
162-
<DButton
163-
class="btn-primary confirm"
164-
@disabled={{this.isStreaming}}
165-
@action={{this.triggerConfirmChanges}}
166-
@label="discourse_ai.ai_helper.context_menu.confirm"
167-
/>
168-
<DButton
169-
class="btn-flat discard"
170-
@action={{@closeModal}}
171-
@label="discourse_ai.ai_helper.context_menu.discard"
172-
/>
173-
<DButton
174-
class="regenerate"
175-
@icon="arrows-rotate"
176-
@action={{this.suggestChanges}}
177-
@label="discourse_ai.ai_helper.context_menu.regen"
178-
/>
179-
{{/if}}
171+
{{/if}}
172+
</DButton>
173+
<DButton
174+
class="btn-flat discard"
175+
@action={{@closeModal}}
176+
@label="discourse_ai.ai_helper.context_menu.discard"
177+
/>
178+
<DButton
179+
class="regenerate"
180+
@icon="arrows-rotate"
181+
@action={{this.suggestChanges}}
182+
@label="discourse_ai.ai_helper.context_menu.regen"
183+
/>
180184
</:footer>
181185
</DModal>
182186
</template>

assets/javascripts/discourse/lib/diff-streamer.gjs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,19 @@ export default class DiffStreamer {
102102
const diff = [];
103103
let i = 0;
104104

105-
while (i < newWords.length) {
105+
while (i < oldWords.length) {
106106
const oldWord = oldWords[i];
107107
const newWord = newWords[i];
108108

109-
let wordHTML;
110-
if (oldWord === undefined) {
111-
wordHTML = `<ins>${newWord}</ins>`;
109+
let wordHTML = "";
110+
let originalWordHTML = `<span class="ghost">${oldWord}</span>`;
111+
112+
if (newWord === undefined) {
113+
wordHTML = originalWordHTML;
114+
} else if (oldWord === newWord) {
115+
wordHTML = `<span class="same-word">${newWord}</span>`;
112116
} else if (oldWord !== newWord) {
113117
wordHTML = `<del>${oldWord}</del> <ins>${newWord}</ins>`;
114-
} else {
115-
wordHTML = newWord;
116118
}
117119

118120
if (i === newWords.length - 1 && opts.markLastWord) {

assets/stylesheets/modules/ai-helper/common/ai-helper.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
}
2323
}
2424

25+
.same-word {
26+
color: var(--primary);
27+
}
28+
29+
.ghost {
30+
color: var(--primary-low-mid);
31+
}
32+
2533
.preview-area {
2634
height: 200px;
2735
}

0 commit comments

Comments
 (0)