tildefriends/apps/ssb/tf-user.js

48 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

import {LitElement, html} from './lit-all.min.js';
import * as tfrpc from '/static/tfrpc.js';
import {styles} from './tf-styles.js';
class TfUserElement extends LitElement {
static get properties() {
return {
id: {type: String},
users: {type: Object},
};
}
static styles = styles;
constructor() {
super();
this.id = null;
this.users = {};
}
render() {
let name = this.users?.[this.id]?.name;
2024-02-24 11:09:34 -05:00
name =
name !== undefined
? html`<a target="_top" href=${'#' + this.id}>${name}</a>`
: html`<a target="_top" href=${'#' + this.id}>${this.id}</a>`;
if (this.users[this.id]) {
let image = this.users[this.id].image;
2024-02-24 11:09:34 -05:00
image = typeof image == 'string' ? image : image?.link;
return html` <div style="display: inline-block; font-weight: bold">
<img
style="width: 2em; height: 2em; vertical-align: middle; border-radius: 50%"
?hidden=${image === undefined}
src="${image ? '/' + image + '/view' : undefined}"
/>
${name}
</div>`;
} else {
2024-02-24 11:09:34 -05:00
return html` <div style="display: inline-block; font-weight: bold">
${name}
</div>`;
}
}
}
2024-02-24 11:09:34 -05:00
customElements.define('tf-user', TfUserElement);