DEV: Convert user `...Categories` computed props to getters/setters (#19018)

Some locations in the app were `.set`-ing these computed properties. This would trigger the `computed-property.override` Ember deprecation, and also lead to inconsistency between the `..._categories_ids` property and the `...Categories` property.

This commit updates these properties to have getters/setters, with all state being stored in the `..._ids` property. The `@dependentKeyCompat` decorator is used to ensure these 'autotracking' getters can still be used as dependent keys in other computed properties.
This commit is contained in:
David Taylor 2022-11-16 10:00:57 +00:00 committed by GitHub
parent 392bafcd7e
commit b9b2e6a2e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 46 additions and 15 deletions

View File

@ -49,6 +49,7 @@ import {
showNextUserTip, showNextUserTip,
showUserTip, showUserTip,
} from "discourse/lib/user-tips"; } from "discourse/lib/user-tips";
import { dependentKeyCompat } from "@ember/object/compat";
export const SECOND_FACTOR_METHODS = { export const SECOND_FACTOR_METHODS = {
TOTP: 1, TOTP: 1,
@ -803,29 +804,59 @@ const User = RestModel.extend({
}); });
}, },
@discourseComputed("muted_category_ids") @dependentKeyCompat
mutedCategories(mutedCategoryIds) { get mutedCategories() {
return Category.findByIds(mutedCategoryIds); return Category.findByIds(this.get("muted_category_ids"));
},
set mutedCategories(categories) {
this.set(
"muted_category_ids",
categories.map((c) => c.id)
);
}, },
@discourseComputed("regular_category_ids") @dependentKeyCompat
regularCategories(regularCategoryIds) { get regularCategories() {
return Category.findByIds(regularCategoryIds); return Category.findByIds(this.get("regular_category_ids"));
},
set regularCategories(categories) {
this.set(
"regular_category_ids",
categories.map((c) => c.id)
);
}, },
@discourseComputed("tracked_category_ids") @dependentKeyCompat
trackedCategories(trackedCategoryIds) { get trackedCategories() {
return Category.findByIds(trackedCategoryIds); return Category.findByIds(this.get("tracked_category_ids"));
},
set trackedCategories(categories) {
this.set(
"tracked_category_ids",
categories.map((c) => c.id)
);
}, },
@discourseComputed("watched_category_ids") @dependentKeyCompat
watchedCategories(watchedCategoryIds) { get watchedCategories() {
return Category.findByIds(watchedCategoryIds); return Category.findByIds(this.get("watched_category_ids"));
},
set watchedCategories(categories) {
this.set(
"watched_category_ids",
categories.map((c) => c.id)
);
}, },
@discourseComputed("watched_first_post_category_ids") @dependentKeyCompat
watchedFirstPostCategories(watchedFirstPostCategoryIds) { get watchedFirstPostCategories() {
return Category.findByIds(watchedFirstPostCategoryIds); return Category.findByIds(this.get("watched_first_post_category_ids"));
},
set watchedFirstPostCategories(categories) {
this.set(
"watched_first_post_category_ids",
categories.map((c) => c.id)
);
}, },
@discourseComputed("can_delete_account") @discourseComputed("can_delete_account")