mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-12 16:14:25 +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
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import {htmlSafe} from '@ember/template';
|
|
|
|
const stringToHslColor = function (str, saturation, lightness) {
|
|
var hash = 0;
|
|
for (var i = 0; i < str.length; i++) {
|
|
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
}
|
|
|
|
var h = hash % 360;
|
|
return 'hsl(' + h + ', ' + saturation + '%, ' + lightness + '%)';
|
|
};
|
|
|
|
export default class GhMemberAvatarComponent extends Component {
|
|
get memberName() {
|
|
let {member} = this.args;
|
|
|
|
return member?.name || member?.email || 'NM';
|
|
}
|
|
|
|
get avatarImage() {
|
|
let {member} = this.args;
|
|
|
|
// to cover both ways avatar image is returned depending on where member data comes from
|
|
return member?.avatar_image || member?.avatarImage || null;
|
|
}
|
|
|
|
get backgroundStyle() {
|
|
let color = stringToHslColor(this.memberName, 75, 55);
|
|
return htmlSafe(`background-color: ${color}`);
|
|
}
|
|
|
|
get initials() {
|
|
if (this.memberName === 'NM') {
|
|
return 'NM';
|
|
}
|
|
|
|
let names = this.memberName.split(' ');
|
|
let intials = names.length > 1 ? [names[0][0], names[names.length - 1][0]] : [names[0][0]];
|
|
return intials.join('').toUpperCase();
|
|
}
|
|
}
|