A platform for community discussion. Free, open, simple.
DEV: converts insert-hyperlink to gjs (#29841)
Joffrey JAFFEUX704a5f4cabfb
diff --git a/app/assets/javascripts/discourse/app/components/modal/insert-hyperlink.js b/app/assets/javascripts/discourse/app/components/modal/insert-hyperlink.gjssimilarity index 60%rename from app/assets/javascripts/discourse/app/components/modal/insert-hyperlink.jsrename to app/assets/javascripts/discourse/app/components/modal/insert-hyperlink.gjsindex 9711d963aba..b60e7cff7d9 100644--- a/app/assets/javascripts/discourse/app/components/modal/insert-hyperlink.js+++ b/app/assets/javascripts/discourse/app/components/modal/insert-hyperlink.gjs@@ -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>}diff --git a/app/assets/javascripts/discourse/app/components/modal/insert-hyperlink.hbs b/app/assets/javascripts/discourse/app/components/modal/insert-hyperlink.hbsdeleted file mode 100644index 93d2486cfd9..00000000000--- a/app/assets/javascripts/discourse/app/components/modal/insert-hyperlink.hbs+++ /dev/null@@ -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>\ No newline at end of file