mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 01:42:29 +03:00
7eab83a6ec
no issue - the `ella-sparse-array` dependency used for the sparsely populated list on the members screen creates ProxyObjects that wrap the underlying member model instances meaning the forced use of `.get()` and `.set()` required by ProxyObject was leaking through to other areas of the app causing a mismatch in code patterns - moved the loading state for each member into a separate component and put the loading conditional directly inside the `{{#each members}}` block so that we can pass the real model instance through to components via `{{member.content}}` rather than passing the ProxyObject wrapper, avoiding unexpected errors when not using `.get()` and `.set()` on member arguments
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import {action} from '@ember/object';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
export default class MembersNewsletterPreference extends Component {
|
|
@tracked filterValue;
|
|
|
|
constructor(...args) {
|
|
super(...args);
|
|
}
|
|
|
|
get newsletters() {
|
|
if (this.args.newsletters?.length > 0) {
|
|
return this.args.newsletters.map((d) => {
|
|
return {
|
|
name: d.name,
|
|
description: d.description,
|
|
subscribed: !!this.args.member?.newsletters?.find((n) => {
|
|
return n.id === d.id;
|
|
}),
|
|
id: d.id,
|
|
forId: `${d.id}-checkbox`
|
|
};
|
|
});
|
|
}
|
|
return [];
|
|
}
|
|
|
|
@action
|
|
updateNewsletterPreference(newsletter, event) {
|
|
let updatedNewsletters = [];
|
|
|
|
const selectedNewsletter = this.args.newsletters.find((d) => {
|
|
return d.id === newsletter.id;
|
|
});
|
|
|
|
if (!event.target.checked) {
|
|
updatedNewsletters = this.args.member.newsletters.filter((d) => {
|
|
return d.id !== newsletter.id;
|
|
});
|
|
} else {
|
|
updatedNewsletters = this.args.member.newsletters.filter((d) => {
|
|
return d.id !== newsletter.id;
|
|
}).concat(selectedNewsletter);
|
|
}
|
|
this.args.setMemberNewsletters(updatedNewsletters);
|
|
}
|
|
}
|