From 96003a7f3f4d0c02d34ee7a405fc5ec114dfc9a9 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 29 Nov 2024 15:41:04 +0000 Subject: [PATCH] DEV: Convert to native class syntax (#140) --- .../activity-pub-category-chooser.js | 20 +++++++------- .../activity-pub-post-object-type-dropdown.js | 20 ++++++-------- .../activity-pub-publication-type-dropdown.js | 20 ++++++-------- .../activity-pub-visibility-dropdown.js | 27 +++++++++---------- .../discourse/models/activity-pub-actor.js | 12 ++++----- .../models/activity-pub-followers.js | 8 +++--- .../models/activity-pub-webfinger.js | 2 +- .../routes/activity-pub-actor-followers.js | 14 +++++----- .../routes/activity-pub-actor-follows.js | 18 ++++++------- 9 files changed, 65 insertions(+), 76 deletions(-) diff --git a/assets/javascripts/discourse/components/activity-pub-category-chooser.js b/assets/javascripts/discourse/components/activity-pub-category-chooser.js index d72ba32a..54f36fab 100644 --- a/assets/javascripts/discourse/components/activity-pub-category-chooser.js +++ b/assets/javascripts/discourse/components/activity-pub-category-chooser.js @@ -1,15 +1,15 @@ +import { classNames } from "@ember-decorators/component"; import CategoryChooser from "select-kit/components/category-chooser"; +import { selectKitOptions } from "select-kit/components/select-kit"; import ActivityPubActor from "../models/activity-pub-actor"; -export default CategoryChooser.extend({ - classNames: ["activity-pub-category-chooser"], - - selectKitOptions: { - allowUncategorized: false, - }, - +@selectKitOptions({ + allowUncategorized: false, +}) +@classNames("activity-pub-category-chooser") +export default class ActivityPubCategoryChooser extends CategoryChooser { categoriesByScope() { - return this._super().filter((category) => { + return super.categoriesByScope().filter((category) => { if (category.read_restricted) { return false; } @@ -20,5 +20,5 @@ export default CategoryChooser.extend({ return !actor; } }); - }, -}); + } +} diff --git a/assets/javascripts/discourse/components/activity-pub-post-object-type-dropdown.js b/assets/javascripts/discourse/components/activity-pub-post-object-type-dropdown.js index d3de89c7..0cb4d139 100644 --- a/assets/javascripts/discourse/components/activity-pub-post-object-type-dropdown.js +++ b/assets/javascripts/discourse/components/activity-pub-post-object-type-dropdown.js @@ -1,12 +1,14 @@ import { computed } from "@ember/object"; +import { classNames } from "@ember-decorators/component"; import I18n from "I18n"; import ComboBoxComponent from "select-kit/components/combo-box"; -export default ComboBoxComponent.extend({ - classNames: ["activity-pub-post-object-type-dropdown"], - nameProperty: "label", +@classNames("activity-pub-post-object-type-dropdown") +export default class ActivityPubPostObjectTypeDropdown extends ComboBoxComponent { + nameProperty = "label"; - content: computed(function () { + @computed + get content() { return [ { id: "Note", @@ -23,11 +25,5 @@ export default ComboBoxComponent.extend({ ), }, ]; - }), - - actions: { - onChange(value) { - this.onChange?.(value); - }, - }, -}); + } +} diff --git a/assets/javascripts/discourse/components/activity-pub-publication-type-dropdown.js b/assets/javascripts/discourse/components/activity-pub-publication-type-dropdown.js index 4cb7f4e5..897f690d 100644 --- a/assets/javascripts/discourse/components/activity-pub-publication-type-dropdown.js +++ b/assets/javascripts/discourse/components/activity-pub-publication-type-dropdown.js @@ -1,12 +1,14 @@ import { computed } from "@ember/object"; +import { classNames } from "@ember-decorators/component"; import I18n from "I18n"; import ComboBoxComponent from "select-kit/components/combo-box"; -export default ComboBoxComponent.extend({ - classNames: ["activity-pub-publication-type-dropdown"], - nameProperty: "label", +@classNames("activity-pub-publication-type-dropdown") +export default class ActivityPubPublicationTypeDropdown extends ComboBoxComponent { + nameProperty = "label"; - content: computed(function () { + @computed + get content() { return [ { id: "first_post", @@ -33,11 +35,5 @@ export default ComboBoxComponent.extend({ ), }, ]; - }), - - actions: { - onChange(value) { - this.onChange?.(value); - }, - }, -}); + } +} diff --git a/assets/javascripts/discourse/components/activity-pub-visibility-dropdown.js b/assets/javascripts/discourse/components/activity-pub-visibility-dropdown.js index f5db7107..959c7162 100644 --- a/assets/javascripts/discourse/components/activity-pub-visibility-dropdown.js +++ b/assets/javascripts/discourse/components/activity-pub-visibility-dropdown.js @@ -1,15 +1,18 @@ import { computed } from "@ember/object"; import { equal } from "@ember/object/computed"; import { schedule } from "@ember/runloop"; +import { classNames } from "@ember-decorators/component"; import I18n from "I18n"; import ComboBoxComponent from "select-kit/components/combo-box"; -export default ComboBoxComponent.extend({ - classNames: ["activity-pub-visibility-dropdown"], - fullTopicPublication: equal("publicationType", "full_topic"), - nameProperty: "label", +@classNames("activity-pub-visibility-dropdown") +export default class ActivityPubVisibilityDropdown extends ComboBoxComponent { + @equal("publicationType", "full_topic") fullTopicPublication; - content: computed(function () { + nameProperty = "label"; + + @computed + get content() { return [ { id: "private", @@ -26,10 +29,10 @@ export default ComboBoxComponent.extend({ }), }, ]; - }), + } didReceiveAttrs() { - this._super(...arguments); + super.didReceiveAttrs(...arguments); if (this.fullTopicPublication) { this.set("value", "public"); @@ -37,11 +40,5 @@ export default ComboBoxComponent.extend({ schedule("afterRender", () => { this.set("selectKit.options.disabled", this.fullTopicPublication); }); - }, - - actions: { - onChange(value) { - this.onChange?.(value); - }, - }, -}); + } +} diff --git a/assets/javascripts/discourse/models/activity-pub-actor.js b/assets/javascripts/discourse/models/activity-pub-actor.js index 501182d3..400402a1 100644 --- a/assets/javascripts/discourse/models/activity-pub-actor.js +++ b/assets/javascripts/discourse/models/activity-pub-actor.js @@ -13,8 +13,8 @@ export const actorModels = ["category"]; export const actorAdminPath = "/admin/plugins/ap/actor"; export const actorClientPath = "/ap/local/actor"; -const ActivityPubActor = EmberObject.extend({ - isNew: equal("id", newActor.id), +class ActivityPubActor extends EmberObject { + @equal("id", newActor.id) isNew; disable() { if (this.isNew) { @@ -23,7 +23,7 @@ const ActivityPubActor = EmberObject.extend({ return ajax(`${actorAdminPath}/${this.id}/disable`, { type: "POST", }).catch(popupAjaxError); - }, + } enable() { if (this.isNew) { @@ -32,7 +32,7 @@ const ActivityPubActor = EmberObject.extend({ return ajax(`${actorAdminPath}/${this.id}/enable`, { type: "POST", }).catch(popupAjaxError); - }, + } save() { let data = { @@ -56,8 +56,8 @@ const ActivityPubActor = EmberObject.extend({ } return ajax(path, { type, data }).catch(popupAjaxError); - }, -}); + } +} ActivityPubActor.reopenClass({ find(actorId) { diff --git a/assets/javascripts/discourse/models/activity-pub-followers.js b/assets/javascripts/discourse/models/activity-pub-followers.js index 5f519685..d985af24 100644 --- a/assets/javascripts/discourse/models/activity-pub-followers.js +++ b/assets/javascripts/discourse/models/activity-pub-followers.js @@ -3,8 +3,8 @@ import { notEmpty } from "@ember/object/computed"; import { ajax } from "discourse/lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; -const ActivityPubFollowers = EmberObject.extend({ - hasFollowers: notEmpty("followers"), +class ActivityPubFollowers extends EmberObject { + @notEmpty("followers") hasFollowers; loadMore() { if (!this.loadMoreUrl || this.total <= this.followers.length) { @@ -24,8 +24,8 @@ const ActivityPubFollowers = EmberObject.extend({ } }) .catch(popupAjaxError); - }, -}); + } +} ActivityPubFollowers.reopenClass({ load(category, params) { diff --git a/assets/javascripts/discourse/models/activity-pub-webfinger.js b/assets/javascripts/discourse/models/activity-pub-webfinger.js index cdbb3281..8e38d9f6 100644 --- a/assets/javascripts/discourse/models/activity-pub-webfinger.js +++ b/assets/javascripts/discourse/models/activity-pub-webfinger.js @@ -2,7 +2,7 @@ import EmberObject from "@ember/object"; import { ajax } from "discourse/lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; -const ActivityPubWebfinger = EmberObject.extend({}); +class ActivityPubWebfinger extends EmberObject {} ActivityPubWebfinger.reopenClass({ validateHandle(handle) { diff --git a/assets/javascripts/discourse/routes/activity-pub-actor-followers.js b/assets/javascripts/discourse/routes/activity-pub-actor-followers.js index 3ceac980..f1d15abd 100644 --- a/assets/javascripts/discourse/routes/activity-pub-actor-followers.js +++ b/assets/javascripts/discourse/routes/activity-pub-actor-followers.js @@ -3,13 +3,13 @@ import { service } from "@ember/service"; import DiscourseRoute from "discourse/routes/discourse"; import ActivityPubActor from "../models/activity-pub-actor"; -export default DiscourseRoute.extend({ - site: service(), +export default class ActivityPubActorFollowers extends DiscourseRoute { + @service site; - queryParams: { + queryParams = { order: { refreshModel: true }, asc: { refreshModel: true }, - }, + }; afterModel(_, transition) { const actor = this.modelFor("activityPub.actor"); @@ -24,7 +24,7 @@ export default DiscourseRoute.extend({ transition.to.queryParams, "followers" ).then((response) => this.setProperties(response)); - }, + } setupController(controller) { controller.setProperties({ @@ -33,5 +33,5 @@ export default DiscourseRoute.extend({ loadMoreUrl: this.meta?.load_more_url, total: this.meta?.total, }); - }, -}); + } +} diff --git a/assets/javascripts/discourse/routes/activity-pub-actor-follows.js b/assets/javascripts/discourse/routes/activity-pub-actor-follows.js index a26f0304..76986a8a 100644 --- a/assets/javascripts/discourse/routes/activity-pub-actor-follows.js +++ b/assets/javascripts/discourse/routes/activity-pub-actor-follows.js @@ -3,11 +3,11 @@ import DiscourseRoute from "discourse/routes/discourse"; import { bind } from "discourse-common/utils/decorators"; import ActivityPubActor from "../models/activity-pub-actor"; -export default DiscourseRoute.extend({ - queryParams: { +export default class ActivityPubActorFollows extends DiscourseRoute { + queryParams = { order: { refreshModel: true }, asc: { refreshModel: true }, - }, + }; afterModel(_, transition) { const actor = this.modelFor("activityPub.actor"); @@ -22,7 +22,7 @@ export default DiscourseRoute.extend({ transition.to.queryParams, "follows" ).then((response) => this.setProperties(response)); - }, + } setupController(controller) { controller.setProperties({ @@ -31,15 +31,15 @@ export default DiscourseRoute.extend({ loadMoreUrl: this.meta?.load_more_url, total: this.meta?.total, }); - }, + } activate() { this.messageBus.subscribe("/activity-pub", this.handleMessage); - }, + } deactivate() { this.messageBus.unsubscribe("/activity-pub", this.handleMessage); - }, + } @bind handleMessage(data) { @@ -48,5 +48,5 @@ export default DiscourseRoute.extend({ if (model && model.type === "category" && model.id === actor.id) { this.refresh(); } - }, -}); + } +}