mapcomplete/UI/Image/ImageCarousel.ts
Pieter Vander Vennet a721d3137a Optimize rendering
2020-10-14 12:15:09 +02:00

58 lines
No EOL
1.5 KiB
TypeScript

import {UIElement} from "../UIElement";
import {ImageSearcher} from "../../Logic/ImageSearcher";
import {SlideShow} from "./SlideShow";
import {UIEventSource} from "../../Logic/UIEventSource";
import {TagDependantUIElement} from "../../Customizations/UIElementConstructor";
import Combine from "../Base/Combine";
import DeleteImage from "./DeleteImage";
export class ImageCarousel extends TagDependantUIElement {
public readonly slideshow: SlideShow;
constructor(tags: UIEventSource<any>) {
super(tags);
const searcher : UIEventSource<{url:string}[]> = new ImageSearcher(tags);
const uiElements = searcher.map((imageURLS: {key: string, url:string}[]) => {
const uiElements: UIElement[] = [];
for (const url of imageURLS) {
let image = ImageSearcher.CreateImageElement(url.url);
if(url.key !== undefined){
image = new Combine([
image,
new DeleteImage(url.key, tags)
]);
}
uiElements.push(image);
}
return uiElements;
});
this.slideshow = new SlideShow(uiElements).HideOnEmpty(true);
}
InnerRender(): string {
return this.slideshow.Render();
}
IsKnown(): boolean {
return true;
}
IsQuestioning(): boolean {
return false;
}
IsSkipped(): boolean {
return false;
}
Priority(): number {
return 0;
}
}