2021-06-18 01:25:13 +02:00
|
|
|
import Combine from "../Base/Combine";
|
|
|
|
import Attribution from "./Attribution";
|
|
|
|
import Img from "../Base/Img";
|
2021-06-22 14:21:32 +02:00
|
|
|
import ImageAttributionSource from "../../Logic/ImageProviders/ImageAttributionSource";
|
2021-09-15 01:33:52 +02:00
|
|
|
import BaseUIElement from "../BaseUIElement";
|
|
|
|
import {VariableUiElement} from "../Base/VariableUIElement";
|
2021-09-21 02:10:42 +02:00
|
|
|
import Loading from "../Base/Loading";
|
2021-06-18 01:25:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
export class AttributedImage extends Combine {
|
|
|
|
|
|
|
|
constructor(urlSource: string, imgSource: ImageAttributionSource) {
|
2021-09-15 01:33:52 +02:00
|
|
|
const preparedUrl = imgSource.PrepareUrl(urlSource)
|
|
|
|
let img: BaseUIElement;
|
|
|
|
let attr: BaseUIElement
|
|
|
|
if (typeof preparedUrl === "string") {
|
|
|
|
img = new Img(urlSource);
|
|
|
|
attr = new Attribution(imgSource.GetAttributionFor(urlSource), imgSource.SourceIcon())
|
|
|
|
} else {
|
2021-09-21 02:10:42 +02:00
|
|
|
img = new VariableUiElement(preparedUrl.map(url => {
|
|
|
|
if(url === undefined){
|
|
|
|
return new Loading()
|
|
|
|
}
|
|
|
|
return new Img(url, false, {fallbackImage: './assets/svg/blocked.svg'});
|
|
|
|
}))
|
|
|
|
attr = new VariableUiElement(preparedUrl.map(_ => new Attribution(imgSource.GetAttributionFor(urlSource), imgSource.SourceIcon())))
|
2021-09-15 01:33:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
super([img, attr]);
|
2021-06-18 01:25:13 +02:00
|
|
|
this.SetClass('block relative h-full');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|