Skip to content

A platform for community discussion. Free, open, simple.

DEV: Convert 10 components to glimmer (#44660)

Jarek Radosz0c2b15ad4a98
diff --git a/frontend/discourse/admin/components/report-filters/bool.gjs b/frontend/discourse/admin/components/report-filters/bool.gjs
index db8581a15bd..d3fd41ca6e7 100644
--- a/frontend/discourse/admin/components/report-filters/bool.gjs
+++ b/frontend/discourse/admin/components/report-filters/bool.gjs
@@ -3,31 +3,27 @@ import { concat } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
import FilterComponent from "discourse/admin/components/report-filters/filter";
+import { resettableTracked } from "discourse/lib/tracked-tools";
import { i18n } from "discourse-i18n";
export default class Bool extends FilterComponent {
- checked = false;
-
- didReceiveAttrs() {
- super.didReceiveAttrs(...arguments);
- this.set("checked", !!this.filter.default);
- }
+ @resettableTracked checked = !!this.args.filter.default;
@action
onChange() {
- this.applyFilter(this.filter.id, !this.checked || undefined);
+ this.args.applyFilter(this.args.filter.id, !this.checked || undefined);
}
<template>
- <label class="chart__filter-label checkbox-label">
- <Input
- @checked={{this.checked}}
- @type="checkbox"
- {{on "click" this.onChange}}
- />
- {{i18n
- (concat "admin.dashboard.reports.filters." this.filter.id ".label")
- }}
- </label>
+ <div ...attributes>
+ <label class="chart__filter-label checkbox-label">
+ <Input
+ @checked={{this.checked}}
+ @type="checkbox"
+ {{on "click" this.onChange}}
+ />
+ {{i18n (concat "admin.dashboard.reports.filters." @filter.id ".label")}}
+ </label>
+ </div>
</template>
}
diff --git a/frontend/discourse/admin/components/report-filters/category-list.gjs b/frontend/discourse/admin/components/report-filters/category-list.gjs
index 129c771e868..c9aa1b3437c 100644
--- a/frontend/discourse/admin/components/report-filters/category-list.gjs
+++ b/frontend/discourse/admin/components/report-filters/category-list.gjs
@@ -8,9 +8,9 @@ import MultipleCategoriesSelector from "discourse/select-kit/components/multiple
export default class CategoryList extends FilterComponent {
@tracked selectedCategories;
- init() {
- super.init(...arguments);
- this.selectedCategories = (this.filter?.default || [])
+ constructor() {
+ super(...arguments);
+ this.selectedCategories = (this.args.filter?.default || [])
.map((id) => Category.findById(id))
.filter(Boolean);
}
@@ -23,7 +23,7 @@ export default class CategoryList extends FilterComponent {
@action
onClose() {
const ids = this.selectedCategories.map((category) => category.id);
- const current = this.filter.default || [];
+ const current = this.args.filter.default || [];
// apply (and re-run the report) only once the picker closes, and only when
// the selection actually changed, so each individual pick doesn't refetch
@@ -34,15 +34,17 @@ export default class CategoryList extends FilterComponent {
return;
}
- this.applyFilter(this.filter.id, ids.length ? ids : undefined);
+ this.args.applyFilter(this.args.filter.id, ids.length ? ids : undefined);
}
<template>
- <MultipleCategoriesSelector
- @categories={{this.selectedCategories}}
- @onChange={{this.onChange}}
- @onClose={{this.onClose}}
- @options={{hash disabled=this.filter.disabled none="category.all"}}
- />
+ <div ...attributes>
+ <MultipleCategoriesSelector
+ @categories={{this.selectedCategories}}
+ @onChange={{this.onChange}}
+ @onClose={{this.onClose}}
+ @options={{hash [email protected] none="category.all"}}
+ />
+ </div>
</template>
}
diff --git a/frontend/discourse/admin/components/report-filters/category.gjs b/frontend/discourse/admin/components/report-filters/category.gjs
index 9ba0523cd8b..b5eef827c94 100644
--- a/frontend/discourse/admin/components/report-filters/category.gjs
+++ b/frontend/discourse/admin/components/report-filters/category.gjs
@@ -1,24 +1,25 @@
import { hash } from "@ember/helper";
-import { action, computed } from "@ember/object";
+import { action } from "@ember/object";
import FilterComponent from "discourse/admin/components/report-filters/filter";
import SearchAdvancedCategoryChooser from "discourse/select-kit/components/search-advanced-category-chooser";
export default class Category extends FilterComponent {
- @computed("filter.default")
get category() {
- return this.filter?.default;
+ return this.args.filter?.default;
}
@action
onChange(categoryId) {
- this.applyFilter(this.filter.id, categoryId || undefined);
+ this.args.applyFilter(this.args.filter.id, categoryId || undefined);
}
<template>
- <SearchAdvancedCategoryChooser
- @onChange={{this.onChange}}
- @options={{hash filterable=true disabled=this.filter.disabled}}
- @value={{this.category}}
- />
+ <div ...attributes>
+ <SearchAdvancedCategoryChooser
+ @onChange={{this.onChange}}
+ @options={{hash filterable=true [email protected]}}
+ @value={{this.category}}
+ />
+ </div>
</template>
}
diff --git a/frontend/discourse/admin/components/report-filters/filter.js b/frontend/discourse/admin/components/report-filters/filter.js
index cdc7798e2c4..3fd69da3a4c 100644
--- a/frontend/discourse/admin/components/report-filters/filter.js
+++ b/frontend/discourse/admin/components/report-filters/filter.js
@@ -1,10 +1,9 @@
-/* eslint-disable ember/no-classic-components, ember/require-tagless-components */
-import Component from "@ember/component";
+import Component from "@glimmer/component";
import { action } from "@ember/object";
export default class Filter extends Component {
@action
onChange(value) {
- this.applyFilter(this.filter.id, value);
+ this.args.applyFilter(this.args.filter.id, value);
}
}
diff --git a/frontend/discourse/admin/components/report-filters/group.gjs b/frontend/discourse/admin/components/report-filters/group.gjs
index c0264d516a7..db2f8d6a0f4 100644
--- a/frontend/discourse/admin/components/report-filters/group.gjs
+++ b/frontend/discourse/admin/components/report-filters/group.gjs
@@ -1,21 +1,21 @@
import { hash } from "@ember/helper";
-import { computed } from "@ember/object";
-import { tagName } from "@ember-decorators/component";
+import { service } from "@ember/service";
import FilterComponent from "discourse/admin/components/report-filters/filter";
import ComboBox from "discourse/select-kit/components/combo-box";
-@tagName("")
export default class Group extends FilterComponent {
- @computed
+ @service site;
+
get groupOptions() {
return (this.site.groups || []).map((group) => {
return { name: group["name"], value: group["id"] };
});
}
- @computed("filter.default")
get groupId() {
- return this.filter.default ? parseInt(this.filter.default, 10) : null;
+ return this.args.filter.default
+ ? parseInt(this.args.filter.default, 10)
+ : null;
}
<template>
@@ -24,8 +24,8 @@ export default class Group extends FilterComponent {
@content={{this.groupOptions}}
@onChange={{this.onChange}}
@options={{hash
- allowAny=this.filter.allow_any
- autoInsertNoneItem=this.filter.auto_insert_none_item
+ [email protected]_insert_none_item
filterable=true
none="admin.dashboard.reports.groups"
}}
diff --git a/frontend/discourse/admin/components/report-filters/groups.gjs b/frontend/discourse/admin/components/report-filters/groups.gjs
index e8a2999d1be..30cf39b2230 100644
--- a/frontend/discourse/admin/components/report-filters/groups.gjs
+++ b/frontend/discourse/admin/components/report-filters/groups.gjs
@@ -19,18 +19,21 @@ export default class Groups extends FilterComponent {
this.modal.show(Modal, {
model: {
- currentTokens: this.filter?.default ?? [],
- onApply: (tokens) => this.applyFilter(this.filter.id, tokens.join(",")),
+ currentTokens: this.args.filter?.default ?? [],
+ onApply: (tokens) =>
+ this.args.applyFilter(this.args.filter.id, tokens.join(",")),
},
});
}
<template>
- <DButton
- class="btn-default report-filter-groups__button"
- @action={{this.openCompareGroups}}
- @icon="plus"
- @label="admin.dashboard.sections.engagement.whos_posting.add_group"
- />
+ <div ...attributes>
+ <DButton
+ class="btn-default report-filter-groups__button"
+ @action={{this.openCompareGroups}}
+ @icon="plus"
+ @label="admin.dashboard.sections.engagement.whos_posting.add_group"
+ />
+ </div>
</template>
}
diff --git a/frontend/discourse/admin/components/report-filters/list.gjs b/frontend/discourse/admin/components/report-filters/list.gjs
index daf28b1d103..24a969e5110 100644
--- a/frontend/discourse/admin/components/report-filters/list.gjs
+++ b/frontend/discourse/admin/components/report-filters/list.gjs
@@ -4,17 +4,19 @@ import ComboBox from "discourse/select-kit/components/combo-box";
export default class List extends FilterComponent {
<template>
- <ComboBox
- @content={{this.filter.choices}}
- @onChange={{this.onChange}}
- @options={{hash
- allowAny=this.filter.allow_any
- autoInsertNoneItem=this.filter.auto_insert_none_item
- filterable=true
- none="admin.dashboard.report_filter_any"
- disabled=this.filter.disabled
- }}
- @value={{this.filter.default}}
- />
+ <div ...attributes>
+ <ComboBox
+ @content={{@filter.choices}}
+ @onChange={{this.onChange}}
+ @options={{hash
+ [email protected]_insert_none_item
+ filterable=true
+ none="admin.dashboard.report_filter_any"
+ }}
+ @value={{@filter.default}}
+ />
+ </div>
</template>
}
diff --git a/frontend/discourse/app/components/categories-only.gjs b/frontend/discourse/app/components/categories-only.gjs
index 336f8593daf..005f4bf8f1d 100644
--- a/frontend/discourse/app/components/categories-only.gjs
+++ b/frontend/discourse/app/components/categories-only.gjs
@@ -1,19 +1,19 @@
-/* eslint-disable ember/no-classic-components */
-import Component from "@ember/component";
+import Component from "@glimmer/component";
+import { cached, tracked } from "@glimmer/tracking";
import { on } from "@ember/modifier";
-import { action, computed } from "@ember/object";
-import { tagName } from "@ember-decorators/component";
+import { action } from "@ember/object";
+import { service } from "@ember/service";
import ParentCategoryRow from "discourse/components/parent-category-row";
import PluginOutlet from "discourse/components/plugin-outlet";
import lazyHash from "discourse/helpers/lazy-hash";
import dIcon from "discourse/ui-kit/helpers/d-icon";
import { i18n } from "discourse-i18n";
-@tagName("")
export default class CategoriesOnly extends Component {
- showMuted = false;
+ @service site;
+
+ @tracked showMuted = false;
- @computed("showMutedCategories", "filteredCategories.length")
get mutedToggleIcon() {
if (this.filteredCategories?.length === 0) {
return;
@@ -26,49 +26,50 @@ export default class CategoriesOnly extends Component {
return "plus";
}
- @computed("showMuted", "filteredCategories.length")
get showMutedCategories() {
return this.showMuted || this.filteredCategories?.length === 0;
}
- @computed("categories", "categories.length")
+ @cached
get filteredCategories() {
- if (!this.categories || this.categories?.length === 0) {
+ const categories = this.args.categories;
+ if (!categories || categories?.length === 0) {
return [];
}
- return this.categories.filter((cat) => !cat.isHidden);
+ return categories.filter((cat) => !cat.isHidden);
}
- @computed("categories", "categories.length")
+ @cached
get mutedCategories() {
- if (!this.categories || this.categories?.length === 0) {
+ const categories = this.args.categories;
+ if (!categories || categories?.length === 0) {
return [];
}
// hide in single category pages
- if (this.categories[0].parent_category_id) {
+ if (categories[0].parent_category_id) {
return [];
}
- return this.categories.filter((category) => category.hasMuted);
+ return categories.filter((category) => category.hasMuted);
}
@action
toggleShowMuted(event) {
event?.preventDefault();
- this.toggleProperty("showMuted");
+ this.showMuted = !this.showMuted;
}
<template>
<PluginOutlet
@name="categories-only-wrapper"
- @outletArgs={{lazyHash categories=this.categories}}
+ @outletArgs={{lazyHash categories=@categories}}
>
- {{#if this.categories}}
+ {{#if @categories}}
{{#if this.filteredCategories}}
{{#if this.site.mobileView}}
- <div class="category-list {{if this.showTopics 'with-topics'}}">
+ <div class="category-list {{if @showTopics 'with-topics'}}">
<PluginOutlet
@name="mobile-categories"
@outletArgs={{lazyHash categories=this.filteredCategories}}
@@ -76,13 +77,13 @@ export default class CategoriesOnly extends Component {
{{#each this.filteredCategories as |c|}}
<ParentCategoryRow
@category={{c}}
- @showTopics={{this.showTopics}}
+ @showTopics={{@showTopics}}
/>
{{/each}}
</PluginOutlet>
</div>
{{else}}
- <table class="category-list {{if this.showTopics 'with-topics'}}">
+ <table class="category-list {{if @showTopics 'with-topics'}}">
<thead class="category-list-header">
<tr>
<th class="category topic-list-data default"><span
@@ -93,16 +94,16 @@ export default class CategoriesOnly extends Component {
<th class="topics topic-list-data num">{{i18n
"categories.topics"
}}</th>
- {{#if this.showTopics}}
+ {{#if @showTopics}}
<th class="latest">{{i18n "categories.latest"}}</th>
{{/if}}
</tr>
</thead>
<tbody aria-labelledby="categories-only-category">
- {{#each this.categories as |category|}}
+ {{#each @categories as |category|}}
<ParentCategoryRow
@category={{category}}
- @showTopics={{this.showTopics}}
+ @showTopics={{@showTopics}}
/>
{{/each}}
</tbody>
@@ -127,21 +128,21 @@ export default class CategoriesOnly extends Component {
{{#if this.site.mobileView}}
<div
class="category-list
- {{if this.showTopics 'with-topics'}}
+ {{if @showTopics 'with-topics'}}
{{unless this.showMutedCategories 'hidden'}}"
>
{{#each this.mutedCategories as |c|}}
<ParentCategoryRow
@category={{c}}
@listType="muted"
- @showTopics={{this.showTopics}}
+ @showTopics={{@showTopics}}
/>
{{/each}}
</div>
{{else}}
<table
class="category-list
- {{if this.showTopics 'with-topics'}}
+ {{if @showTopics 'with-topics'}}
{{unless this.showMutedCategories 'hidden'}}"
>
<thead>
@@ -152,17 +153,17 @@ export default class CategoriesOnly extends Component {
role="heading"
>{{i18n "categories.category"}}</span></th>
<th class="topics">{{i18n "categories.topics"}}</th>
- {{#if this.showTopics}}
+ {{#if @showTopics}}
<th class="latest">{{i18n "categories.latest"}}</th>
{{/if}}
</tr>
</thead>
<tbody aria-labelledby="categories-only-category-muted">
- {{#each this.categories as |category|}}
+ {{#each @categories as |category|}}
<ParentCategoryRow
@category={{category}}
@listType="muted"
- @showTopics={{this.showTopics}}
+ @showTopics={{@showTopics}}
/>
{{/each}}
</tbody>
@@ -176,10 +177,7 @@ export default class CategoriesOnly extends Component {
<PluginOutlet
@connectorTagName="div"
@name="below-categories-only"
- @outletArgs={{lazyHash
- categories=this.categories
- showTopics=this.showTopics
- }}
+ @outletArgs={{lazyHash categories=@categories showTopics=@showTopics}}
/>
</template>
}
diff --git a/frontend/discourse/app/components/navigation-item.gjs b/frontend/discourse/app/components/navigation-item.gjs
index c8ed972ddc6..dd7f8147e0a 100644
--- a/frontend/discourse/app/components/navigation-item.gjs
+++ b/frontend/discourse/app/components/navigation-item.gjs
@@ -1,48 +1,37 @@
-/* eslint-disable ember/no-classic-components */
-import Component from "@ember/component";
-import { computed } from "@ember/object";
-import { dependentKeyCompat } from "@ember/object/compat";
-import { tagName } from "@ember-decorators/component";
+import Component from "@glimmer/component";
+import { service } from "@ember/service";
import { filterTypeForMode } from "discourse/lib/filter-mode";
import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";
-@tagName("")
export default class NavigationItem extends Component {
- filterMode;
- hidden = false;
- activeClass = "";
+ @service currentUser;
+ @service siteSettings;
- /** @type {string | null | undefined} */
- hrefLink = null;
-
- @dependentKeyCompat
get filterType() {
- return filterTypeForMode(this.filterMode);
+ return filterTypeForMode(this.args.filterMode);
}
- @computed("content.filterType", "filterType", "content.active")
get active() {
- if (this.content?.active !== undefined) {
- return this.content?.active;
+ if (this.args.content?.active !== undefined) {
+ return this.args.content?.active;
}
- return this.content?.filterType === this.filterType;
+ return this.args.content?.filterType === this.filterType;
}
- @computed("content.count", "content.name")
get isHidden() {
return (
!this.active &&
this.currentUser &&
!this.currentUser.unified_new_enabled &&
this.currentUser.trust_level > 0 &&
- (this.content?.name === "new" || this.content?.name === "unread") &&
- this.content?.count < 1
+ (this.args.content?.name === "new" ||
+ this.args.content?.name === "unread") &&
+ this.args.content?.count < 1
);
}
- didReceiveAttrs() {
- super.didReceiveAttrs(...arguments);
- const content = this.content;
+ get hrefLink() {
+ const content = this.args.content;
let [href, searchParams] = content.get("href")?.split("?") || [];
@@ -51,7 +40,7 @@ export default class NavigationItem extends Component {
// Include the category id if the option is present
if (content.get("includeCategoryId")) {
- let categoryId = this.get("content.category.id");
+ let categoryId = content.get("category.id");
if (categoryId) {
urlSearchParams.set("category_id", categoryId);
}
@@ -82,32 +71,30 @@ export default class NavigationItem extends Component {
if (addParamsEvenIfEmpty || (queryString && href)) {
href = (href || "") + `?${queryString}`;
}
- this.set("hrefLink", href);
-
- this.set("activeClass", this.active ? "active" : "");
+ return href;
}
<template>
<li
class={{dConcatClass
(if this.active "active")
- (if this.content.hasIcon "has-icon")
- this.content.classNames
+ (if @content.hasIcon "has-icon")
+ @content.classNames
(if this.isHidden "hidden")
- this.content.name
+ @content.name
}}
- title={{this.content.title}}
+ title={{@content.title}}
...attributes
>
<a
- aria-current={{if this.activeClass "page"}}
- class={{this.activeClass}}
+ aria-current={{if this.active "page"}}
+ class={{if this.active "active"}}
href={{this.hrefLink}}
>
{{#if this.hasIcon}}
- <span class={{this.content.name}}></span>
+ <span class={{@content.name}}></span>
{{/if}}
- {{this.content.displayName}}
+ {{@content.displayName}}
</a>
</li>
</template>
diff --git a/frontend/discourse/tests/integration/components/categories-only-test.gjs b/frontend/discourse/tests/integration/components/categories-only-test.gjs
new file mode 100644
index 00000000000..36647564d88
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/categories-only-test.gjs
@@ -0,0 +1,36 @@
+import { click, render } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import CategoriesOnly from "discourse/components/categories-only";
+import { NotificationLevels } from "discourse/lib/notification-levels";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+
+module("Integration | Component | CategoriesOnly", function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("toggles the muted categories", async function (assert) {
+ const store = this.owner.lookup("service:store");
+ const categories = [
+ store.createRecord("category", { id: 1, name: "Visible", slug: "v" }),
+ store.createRecord("category", {
+ id: 2,
+ name: "Muted",
+ slug: "m",
+ notification_level: NotificationLevels.MUTED,
+ }),
+ ];
+
+ await render(
+ <template><CategoriesOnly @categories={{categories}} /></template>
+ );
+
+ assert
+ .dom(".muted-categories .category-list")
+ .hasClass("hidden", "starts with muted categories collapsed");
+
+ await click(".muted-categories-link");
+
+ assert
+ .dom(".muted-categories .category-list")
+ .doesNotHaveClass("hidden", "expands the muted categories");
+ });
+});
diff --git a/frontend/discourse/tests/integration/components/report-filters/report-filters-test.gjs b/frontend/discourse/tests/integration/components/report-filters/report-filters-test.gjs
new file mode 100644
index 00000000000..d4ff02d1170
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/report-filters/report-filters-test.gjs
@@ -0,0 +1,71 @@
+import { tracked } from "@glimmer/tracking";
+import { click, render, settled } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import Bool from "discourse/admin/components/report-filters/bool";
+import List from "discourse/admin/components/report-filters/list";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import selectKit from "discourse/tests/helpers/select-kit-helper";
+
+module("Integration | Component | ReportFilters", function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("a bool filter applies the toggled value and follows the report", async function (assert) {
+ const filter = tracked({ id: "include_subcategories", default: false });
+ const applied = [];
+ const applyFilter = (id, value) => applied.push([id, value]);
+
+ await render(
+ <template>
+ <Bool @applyFilter={{applyFilter}} @filter={{filter.value}} />
+ </template>
+ );
+
+ assert.dom("input[type='checkbox']").isNotChecked();
+
+ await click("input[type='checkbox']");
+
+ assert.deepEqual(
+ applied,
+ [["include_subcategories", true]],
+ "applies the checked value"
+ );
+
+ filter.value = { id: "include_subcategories", default: true };
+ await settled();
+
+ assert
+ .dom("input[type='checkbox']")
+ .isChecked("shows the value the report applied");
+
+ filter.value = { id: "include_subcategories", default: false };
+ await settled();
+
+ assert
+ .dom("input[type='checkbox']")
+ .isNotChecked("follows the report when it changes the value");
+ });
+
+ test("a list filter applies the picked choice", async function (assert) {
+ const applied = [];
+ const applyFilter = (id, value) => applied.push([id, value]);
+ const filter = {
+ id: "flag_type",
+ default: null,
+ choices: [
+ { id: "spam", name: "Spam" },
+ { id: "off_topic", name: "Off topic" },
+ ],
+ };
+
+ await render(
+ <template>
+ <List @applyFilter={{applyFilter}} @filter={{filter}} />
+ </template>
+ );
+
+ await selectKit().expand();
+ await selectKit().selectRowByValue("spam");
+
+ assert.deepEqual(applied, [["flag_type", "spam"]]);
+ });
+});
diff --git a/plugins/discourse-patreon/assets/javascripts/discourse/connectors/topic-above-footer-buttons/patreon.gjs b/plugins/discourse-patreon/assets/javascripts/discourse/connectors/topic-above-footer-buttons/patreon.gjs
index c1109d7ea90..587426bc3a0 100644
--- a/plugins/discourse-patreon/assets/javascripts/discourse/connectors/topic-above-footer-buttons/patreon.gjs
+++ b/plugins/discourse-patreon/assets/javascripts/discourse/connectors/topic-above-footer-buttons/patreon.gjs
@@ -1,9 +1,9 @@
-/* eslint-disable ember/no-classic-components, ember/require-tagless-components */
-import Component from "@ember/component";
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
+import { service } from "@ember/service";
import { trustHTML } from "@ember/template";
-import { classNames, tagName } from "@ember-decorators/component";
import cookie from "discourse/lib/cookie";
import dIcon from "discourse/ui-kit/helpers/d-icon";
import { i18n } from "discourse-i18n";
@@ -14,27 +14,23 @@ export function incrementTopicsOpened() {
numTopicsOpened++;
}
-@tagName("div")
-@classNames("topic-above-footer-buttons-outlet", "patreon")
export default class Patreon extends Component {
static shouldRender(_args, context) {
return context.currentUser;
}
- init() {
- super.init(...arguments);
- this.didInsertElement = function () {
- const showDonationPrompt =
- this.siteSettings.patreon_enabled &&
- this.siteSettings.patreon_donation_prompt_enabled &&
- this.siteSettings.patreon_donation_prompt_campaign_url !== "" &&
- this.currentUser.show_donation_prompt &&
- cookie(cookieName) !== "t" &&
- numTopicsOpened >
- this.siteSettings.patreon_donation_prompt_show_after_topics;
- this.set("showDonationPrompt", showDonationPrompt);
- };
- }
+ @service currentUser;
+ @service siteSettings;
+
+ @tracked
+ showDonationPrompt =
+ this.siteSettings.patreon_enabled &&
+ this.siteSettings.patreon_donation_prompt_enabled &&
+ this.siteSettings.patreon_donation_prompt_campaign_url !== "" &&
+ this.currentUser.show_donation_prompt &&
+ cookie(cookieName) !== "t" &&
+ numTopicsOpened >
+ this.siteSettings.patreon_donation_prompt_show_after_topics;
@action
close() {
@@ -43,23 +39,25 @@ export default class Patreon extends Component {
cookie(cookieName, "t", {
expires,
});
- this.set("showDonationPrompt", false);
+ this.showDonationPrompt = false;
}
<template>
- {{#if this.showDonationPrompt}}
- <div class="patreon-donation-prompt">
- <span class="close" role="button" {{on "click" this.close}}>
- {{dIcon "xmark"}}
- </span>
+ <div class="topic-above-footer-buttons-outlet patreon" ...attributes>
+ {{#if this.showDonationPrompt}}
+ <div class="patreon-donation-prompt">
+ <span class="close" role="button" {{on "click" this.close}}>
+ {{dIcon "xmark"}}
+ </span>
- {{trustHTML
- (i18n
- "patreon.donation_prompt.body"
- campaignUrl=this.siteSettings.patreon_donation_prompt_campaign_url
- )
- }}
- </div>
- {{/if}}
+ {{trustHTML
+ (i18n
+ "patreon.donation_prompt.body"
+ campaignUrl=this.siteSettings.patreon_donation_prompt_campaign_url
+ )
+ }}
+ </div>
+ {{/if}}
+ </div>
</template>
}
diff --git a/plugins/discourse-patreon/test/javascripts/integration/components/patreon-donation-prompt-test.gjs b/plugins/discourse-patreon/test/javascripts/integration/components/patreon-donation-prompt-test.gjs
new file mode 100644
index 00000000000..64aa4cb6422
--- /dev/null
+++ b/plugins/discourse-patreon/test/javascripts/integration/components/patreon-donation-prompt-test.gjs
@@ -0,0 +1,47 @@
+import { getOwner } from "@ember/owner";
+import { click, render } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import { removeCookie } from "discourse/lib/cookie";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import {
+ logIn,
+ updateCurrentUser,
+} from "discourse/tests/helpers/qunit-helpers";
+import Patreon, {
+ incrementTopicsOpened,
+} from "discourse/plugins/discourse-patreon/discourse/connectors/topic-above-footer-buttons/patreon";
+
+module("Integration | Component | Patreon donation prompt", function (hooks) {
+ setupRenderingTest(hooks);
+
+ hooks.beforeEach(function () {
+ removeCookie("PatreonDonationPromptClosed");
+ });
+
+ hooks.afterEach(function () {
+ removeCookie("PatreonDonationPromptClosed");
+ });
+
+ test("shows the prompt until it is closed", async function (assert) {
+ logIn(getOwner(this));
+ updateCurrentUser({ show_donation_prompt: true });
+ this.siteSettings.patreon_enabled = true;
+ this.siteSettings.patreon_donation_prompt_enabled = true;
+ this.siteSettings.patreon_donation_prompt_campaign_url =
+ "https://patreon.com/example";
+ this.siteSettings.patreon_donation_prompt_show_after_topics = 0;
+ incrementTopicsOpened();
+
+ await render(<template><Patreon /></template>);
+
+ assert
+ .dom(
+ ".topic-above-footer-buttons-outlet.patreon .patreon-donation-prompt"
+ )
+ .exists("shows the prompt");
+
+ await click(".patreon-donation-prompt .close");
+
+ assert.dom(".patreon-donation-prompt").doesNotExist("hides it on close");
+ });
+});