Skip to content

Commit

Permalink
DEV: Convert to native class syntax (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaylorhq authored Nov 29, 2024
1 parent e506658 commit 96003a7
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
Expand All @@ -20,5 +20,5 @@ export default CategoryChooser.extend({
return !actor;
}
});
},
});
}
}
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -23,11 +25,5 @@ export default ComboBoxComponent.extend({
),
},
];
}),

actions: {
onChange(value) {
this.onChange?.(value);
},
},
});
}
}
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -33,11 +35,5 @@ export default ComboBoxComponent.extend({
),
},
];
}),

actions: {
onChange(value) {
this.onChange?.(value);
},
},
});
}
}
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -26,22 +29,16 @@ export default ComboBoxComponent.extend({
}),
},
];
}),
}

didReceiveAttrs() {
this._super(...arguments);
super.didReceiveAttrs(...arguments);

if (this.fullTopicPublication) {
this.set("value", "public");
}
schedule("afterRender", () => {
this.set("selectKit.options.disabled", this.fullTopicPublication);
});
},

actions: {
onChange(value) {
this.onChange?.(value);
},
},
});
}
}
12 changes: 6 additions & 6 deletions assets/javascripts/discourse/models/activity-pub-actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -23,7 +23,7 @@ const ActivityPubActor = EmberObject.extend({
return ajax(`${actorAdminPath}/${this.id}/disable`, {
type: "POST",
}).catch(popupAjaxError);
},
}

enable() {
if (this.isNew) {
Expand All @@ -32,7 +32,7 @@ const ActivityPubActor = EmberObject.extend({
return ajax(`${actorAdminPath}/${this.id}/enable`, {
type: "POST",
}).catch(popupAjaxError);
},
}

save() {
let data = {
Expand All @@ -56,8 +56,8 @@ const ActivityPubActor = EmberObject.extend({
}

return ajax(path, { type, data }).catch(popupAjaxError);
},
});
}
}

ActivityPubActor.reopenClass({
find(actorId) {
Expand Down
8 changes: 4 additions & 4 deletions assets/javascripts/discourse/models/activity-pub-followers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -24,8 +24,8 @@ const ActivityPubFollowers = EmberObject.extend({
}
})
.catch(popupAjaxError);
},
});
}
}

ActivityPubFollowers.reopenClass({
load(category, params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -24,7 +24,7 @@ export default DiscourseRoute.extend({
transition.to.queryParams,
"followers"
).then((response) => this.setProperties(response));
},
}

setupController(controller) {
controller.setProperties({
Expand All @@ -33,5 +33,5 @@ export default DiscourseRoute.extend({
loadMoreUrl: this.meta?.load_more_url,
total: this.meta?.total,
});
},
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -22,7 +22,7 @@ export default DiscourseRoute.extend({
transition.to.queryParams,
"follows"
).then((response) => this.setProperties(response));
},
}

setupController(controller) {
controller.setProperties({
Expand All @@ -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) {
Expand All @@ -48,5 +48,5 @@ export default DiscourseRoute.extend({
if (model && model.type === "category" && model.id === actor.id) {
this.refresh();
}
},
});
}
}

0 comments on commit 96003a7

Please sign in to comment.