DEV: converts insert-hyperlink to gjs (#29841)

This commit is contained in:
Joffrey JAFFEUX 2024-11-20 10:49:44 +01:00 committed by GitHub
parent 8271010387
commit 704a5f4cab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 86 additions and 74 deletions

View File

@ -1,11 +1,20 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
import { cancel } from "@ember/runloop";
import { isEmpty } from "@ember/utils";
import DButton from "discourse/components/d-button";
import DModal from "discourse/components/d-modal";
import TopicStatus from "discourse/components/topic-status";
import categoryLink from "discourse/helpers/category-link";
import discourseTags from "discourse/helpers/discourse-tags";
import loadingSpinner from "discourse/helpers/loading-spinner";
import replaceEmoji from "discourse/helpers/replace-emoji";
import { searchForTerm } from "discourse/lib/search";
import { prefixProtocol } from "discourse/lib/url";
import discourseDebounce from "discourse-common/lib/debounce";
import { i18n } from "discourse-i18n";
export default class InsertHyperlink extends Component {
@tracked linkText = this.args.model.linkText;
@ -161,4 +170,81 @@ export default class InsertHyperlink extends Component {
this.linkUrl = event.target.value;
this._debounced = discourseDebounce(this, this.triggerSearch, 400);
}
<template>
{{! template-lint-disable no-pointer-down-event-binding }}
<DModal
{{on "keydown" this.keyDown}}
{{on "mousedown" this.mouseDown}}
@closeModal={{@closeModal}}
@title={{i18n "composer.link_dialog_title"}}
@bodyClass="insert-link"
class="insert-hyperlink-modal"
>
<:body>
<div class="inputs">
<input
{{on "input" this.search}}
value={{this.linkUrl}}
placeholder={{i18n "composer.link_url_placeholder"}}
type="text"
autofocus="autofocus"
class="link-url"
/>
{{#if this.searchLoading}}
{{loadingSpinner}}
{{/if}}
{{#if this.searchResults}}
<div class="internal-link-results">
{{#each this.searchResults as |result|}}
<a
{{on "click" this.linkClick}}
href={{result.url}}
data-title={{result.fancy_title}}
class="search-link"
>
<TopicStatus @topic={{result}} @disableActions={{true}} />
{{replaceEmoji result.title}}
<div class="search-category">
{{#if result.category.parentCategory}}
{{categoryLink result.category.parentCategory}}
{{/if}}
{{categoryLink result.category hideParent=true}}
{{discourseTags result}}
</div>
</a>
{{/each}}
</div>
{{/if}}
</div>
<div class="inputs">
<input
{{on "input" this.updateLinkText}}
value={{this.linkText}}
placeholder={{i18n "composer.link_optional_text"}}
type="text"
class="link-text"
/>
</div>
</:body>
<:footer>
<DButton
@action={{this.ok}}
@label="composer.modal_ok"
type="submit"
class="btn-primary"
/>
<DButton
@action={{@closeModal}}
@label="composer.cancel"
class="btn-danger"
/>
</:footer>
</DModal>
</template>
}

View File

@ -1,74 +0,0 @@
{{! template-lint-disable no-pointer-down-event-binding }}
<DModal
{{on "keydown" this.keyDown}}
{{on "mousedown" this.mouseDown}}
@closeModal={{@closeModal}}
@title={{i18n "composer.link_dialog_title"}}
@bodyClass="insert-link"
class="insert-hyperlink-modal"
>
<:body>
<div class="inputs">
<input
{{on "input" this.search}}
value={{this.linkUrl}}
placeholder={{i18n "composer.link_url_placeholder"}}
type="text"
autofocus="autofocus"
class="link-url"
/>
{{#if this.searchLoading}}
{{loading-spinner}}
{{/if}}
{{#if this.searchResults}}
<div class="internal-link-results">
{{#each this.searchResults as |result|}}
<a
{{on "click" this.linkClick}}
href={{result.url}}
data-title={{result.fancy_title}}
class="search-link"
>
<TopicStatus @topic={{result}} @disableActions={{true}} />
{{replace-emoji result.title}}
<div class="search-category">
{{#if result.category.parentCategory}}
{{category-link result.category.parentCategory}}
{{/if}}
{{category-link result.category hideParent=true}}
{{discourse-tags result}}
</div>
</a>
{{/each}}
</div>
{{/if}}
</div>
<div class="inputs">
<input
{{on "input" this.updateLinkText}}
value={{this.linkText}}
placeholder={{i18n "composer.link_optional_text"}}
type="text"
class="link-text"
/>
</div>
</:body>
<:footer>
<DButton
@action={{this.ok}}
@label="composer.modal_ok"
type="submit"
class="btn-primary"
/>
<DButton
@action={{@closeModal}}
@label="composer.cancel"
class="btn-danger"
/>
</:footer>
</DModal>