2024-02-19 12:56:28 -05:00
|
|
|
import Component from "@glimmer/component";
|
|
|
|
import { on } from "@ember/modifier";
|
|
|
|
import { action } from "@ember/object";
|
2024-02-22 12:31:25 -05:00
|
|
|
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
|
|
|
|
import didUpdate from "@ember/render-modifiers/modifiers/did-update";
|
|
|
|
import willDestroy from "@ember/render-modifiers/modifiers/will-destroy";
|
2024-02-19 12:56:28 -05:00
|
|
|
import { inject as service } from "@ember/service";
|
|
|
|
import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";
|
|
|
|
import DButton from "discourse/components/d-button";
|
2024-02-20 10:44:15 -05:00
|
|
|
import DTextarea from "discourse/components/d-textarea";
|
2024-02-19 12:56:28 -05:00
|
|
|
import autoFocus from "discourse/modifiers/auto-focus";
|
|
|
|
import icon from "discourse-common/helpers/d-icon";
|
|
|
|
import i18n from "discourse-common/helpers/i18n";
|
|
|
|
|
|
|
|
export default class AiImageCaptionContainer extends Component {
|
|
|
|
@service imageCaptionPopup;
|
|
|
|
|
|
|
|
@action
|
|
|
|
updateCaption(event) {
|
|
|
|
event.preventDefault();
|
2024-02-20 10:44:15 -05:00
|
|
|
this.imageCaptionPopup.newCaption = event.target.value;
|
2024-02-19 12:56:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
saveCaption() {
|
2024-02-28 16:32:45 -05:00
|
|
|
this.imageCaptionPopup.updateCaption();
|
2024-02-22 12:31:25 -05:00
|
|
|
this.hidePopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
resizeTextarea(target) {
|
|
|
|
const style = window.getComputedStyle(target);
|
|
|
|
|
|
|
|
// scrollbars will show based on scrollHeight alone
|
|
|
|
// so we need to consider borders too
|
|
|
|
const borderTopWidth = parseInt(style.borderTopWidth, 10);
|
|
|
|
const borderBottomWidth = parseInt(style.borderBottomWidth, 10);
|
|
|
|
|
|
|
|
target.scrollTop = 0;
|
|
|
|
target.style.height = `${
|
|
|
|
target.scrollHeight + borderTopWidth + borderBottomWidth
|
|
|
|
}px`;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
hidePopup() {
|
2024-02-19 12:56:28 -05:00
|
|
|
this.imageCaptionPopup.showPopup = false;
|
2024-02-28 16:32:45 -05:00
|
|
|
if (this.imageCaptionPopup._request) {
|
|
|
|
this.imageCaptionPopup._request.abort();
|
|
|
|
this.imageCaptionPopup._request = null;
|
|
|
|
this.imageCaptionPopup.toggleLoadingState(false);
|
|
|
|
}
|
2024-02-19 12:56:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
<template>
|
|
|
|
{{#if this.imageCaptionPopup.showPopup}}
|
2024-02-22 12:31:25 -05:00
|
|
|
<div
|
|
|
|
class="composer-popup education-message ai-caption-popup"
|
|
|
|
{{willDestroy this.hidePopup}}
|
|
|
|
>
|
2024-02-19 12:56:28 -05:00
|
|
|
<ConditionalLoadingSpinner
|
|
|
|
@condition={{this.imageCaptionPopup.loading}}
|
|
|
|
>
|
2024-02-20 10:44:15 -05:00
|
|
|
<DTextarea
|
2024-02-22 12:31:25 -05:00
|
|
|
{{didInsert this.resizeTextarea}}
|
|
|
|
{{didUpdate this.resizeTextarea this.imageCaptionPopup.newCaption}}
|
2024-02-20 10:44:15 -05:00
|
|
|
@value={{this.imageCaptionPopup.newCaption}}
|
|
|
|
{{on "change" this.updateCaption}}
|
2024-02-19 12:56:28 -05:00
|
|
|
{{autoFocus}}
|
2024-02-20 10:44:15 -05:00
|
|
|
/>
|
2024-02-19 12:56:28 -05:00
|
|
|
</ConditionalLoadingSpinner>
|
|
|
|
|
|
|
|
<div class="actions">
|
|
|
|
<DButton
|
|
|
|
class="btn-primary"
|
|
|
|
@label="discourse_ai.ai_helper.image_caption.save_caption"
|
|
|
|
@icon="check"
|
|
|
|
@action={{this.saveCaption}}
|
|
|
|
/>
|
|
|
|
<DButton
|
2024-02-28 16:32:45 -05:00
|
|
|
class="btn-flat cancel-request"
|
2024-02-19 12:56:28 -05:00
|
|
|
@label="cancel"
|
2024-02-22 12:31:25 -05:00
|
|
|
@action={{this.hidePopup}}
|
2024-02-19 12:56:28 -05:00
|
|
|
/>
|
|
|
|
|
|
|
|
<span class="credits">
|
|
|
|
{{icon "discourse-sparkles"}}
|
2024-02-20 17:59:59 -05:00
|
|
|
<span>{{i18n "discourse_ai.ai_helper.image_caption.credits"}}</span>
|
2024-02-19 12:56:28 -05:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{{/if}}
|
|
|
|
</template>
|
|
|
|
}
|