From 41593a5d7d3e3bea2f770da341060f649c6efeca Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Tue, 13 Aug 2024 14:22:24 +0200 Subject: [PATCH] DEV: Convert expand-post to glimmer/gjs/dbutton (#28339) --- .../discourse/app/components/expand-post.gjs | 50 +++++++++++++++++++ .../discourse/app/components/expand-post.hbs | 14 ------ .../discourse/app/components/expand-post.js | 36 ------------- 3 files changed, 50 insertions(+), 50 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/components/expand-post.gjs delete mode 100644 app/assets/javascripts/discourse/app/components/expand-post.hbs delete mode 100644 app/assets/javascripts/discourse/app/components/expand-post.js diff --git a/app/assets/javascripts/discourse/app/components/expand-post.gjs b/app/assets/javascripts/discourse/app/components/expand-post.gjs new file mode 100644 index 00000000000..1dfbf7c5660 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/expand-post.gjs @@ -0,0 +1,50 @@ +import Component from "@glimmer/component"; +import { tracked } from "@glimmer/tracking"; +import { action } from "@ember/object"; +import DButton from "discourse/components/d-button"; +import concatClass from "discourse/helpers/concat-class"; +import { ajax } from "discourse/lib/ajax"; + +export default class ExpandPost extends Component { + @tracked expanded = false; + loading = false; + + @action + async toggleItem() { + if (this.loading) { + return; + } + + if (this.expanded) { + this.expanded = false; + this.args.item.set("expandedExcerpt", null); + return; + } + + this.loading = true; + try { + const result = await ajax( + `/posts/by_number/${this.args.item.topic_id}/${this.args.item.post_number}.json` + ); + + this.expanded = true; + this.args.item.set("expandedExcerpt", result.cooked); + } finally { + this.loading = false; + } + } + + +} diff --git a/app/assets/javascripts/discourse/app/components/expand-post.hbs b/app/assets/javascripts/discourse/app/components/expand-post.hbs deleted file mode 100644 index d183a9c3115..00000000000 --- a/app/assets/javascripts/discourse/app/components/expand-post.hbs +++ /dev/null @@ -1,14 +0,0 @@ -{{#if this.item.truncated}} - - {{#if this.expanded}} - {{d-icon "chevron-up"}} - {{else}} - {{d-icon "chevron-down"}} - {{/if}} - -{{/if}} \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/expand-post.js b/app/assets/javascripts/discourse/app/components/expand-post.js deleted file mode 100644 index c16efd16fe8..00000000000 --- a/app/assets/javascripts/discourse/app/components/expand-post.js +++ /dev/null @@ -1,36 +0,0 @@ -import Component from "@ember/component"; -import { ajax } from "discourse/lib/ajax"; - -export default Component.extend({ - tagName: "", - expanded: null, - _loading: false, - - actions: { - toggleItem() { - if (this._loading) { - return false; - } - const item = this.item; - - if (this.expanded) { - this.set("expanded", false); - item.set("expandedExcerpt", null); - return false; - } - - const topicId = item.get("topic_id"); - const postNumber = item.get("post_number"); - - this._loading = true; - ajax(`/posts/by_number/${topicId}/${postNumber}.json`) - .then((result) => { - this.set("expanded", true); - item.set("expandedExcerpt", result.cooked); - }) - .finally(() => (this._loading = false)); - - return false; - }, - }, -});