2018-10-23 00:10:28 -04:00
|
|
|
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChange, SimpleChanges } from "@angular/core";
|
2017-12-15 23:22:34 -05:00
|
|
|
import { DomSanitizer, SafeResourceUrl } from "@angular/platform-browser";
|
2017-12-24 04:02:57 -05:00
|
|
|
import { FE_Integration } from "../shared/models/integration";
|
2018-10-23 00:10:28 -04:00
|
|
|
import { MediaService } from "../shared/services/media.service";
|
2017-12-15 23:22:34 -05:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "my-integration-bag",
|
|
|
|
templateUrl: "./integration-bag.component.html",
|
|
|
|
styleUrls: ["./integration-bag.component.scss"],
|
|
|
|
})
|
2018-10-23 00:10:28 -04:00
|
|
|
export class IntegrationBagComponent implements OnChanges {
|
2017-12-15 23:22:34 -05:00
|
|
|
|
2017-12-24 04:02:57 -05:00
|
|
|
@Input() integrations: FE_Integration[];
|
|
|
|
@Output() integrationClicked: EventEmitter<FE_Integration> = new EventEmitter<FE_Integration>();
|
2017-12-15 23:22:34 -05:00
|
|
|
|
2018-10-23 00:10:28 -04:00
|
|
|
constructor(private sanitizer: DomSanitizer, private media: MediaService) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnChanges(changes: SimpleChanges) {
|
|
|
|
const change: SimpleChange = changes.integrations;
|
|
|
|
|
|
|
|
(<FE_Integration[]>change.currentValue).map(async (i) => {
|
|
|
|
if (i.avatarUrl.startsWith("mxc://")) {
|
|
|
|
i.avatarUrl = await this.media.getThumbnailUrl(i.avatarUrl, 128, 128, "scale", true);
|
|
|
|
}
|
|
|
|
});
|
2017-12-15 23:22:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public getSafeUrl(url: string): SafeResourceUrl {
|
|
|
|
return this.sanitizer.bypassSecurityTrustResourceUrl(url);
|
|
|
|
}
|
|
|
|
|
2017-12-24 04:02:57 -05:00
|
|
|
public onClick(integration: FE_Integration) {
|
2017-12-15 23:22:34 -05:00
|
|
|
this.integrationClicked.emit(integration);
|
|
|
|
}
|
|
|
|
}
|