mapcomplete/UI/Image/ImageCarousel.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
2.1 KiB
TypeScript
Raw Normal View History

2020-10-14 12:15:09 +02:00
import { SlideShow } from "./SlideShow"
import { Store } from "../../Logic/UIEventSource"
import Combine from "../Base/Combine"
import DeleteImage from "./DeleteImage"
import { AttributedImage } from "./AttributedImage"
2021-06-11 22:51:45 +02:00
import BaseUIElement from "../BaseUIElement"
2021-06-14 19:21:33 +02:00
import Toggle from "../Input/Toggle"
import ImageProvider from "../../Logic/ImageProviders/ImageProvider"
2021-12-21 18:35:31 +01:00
import { OsmConnection } from "../../Logic/Osm/OsmConnection"
import { Changes } from "../../Logic/Osm/Changes"
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"
2021-06-14 19:21:33 +02:00
export class ImageCarousel extends Toggle {
constructor(
images: Store<{ key: string; url: string; provider: ImageProvider }[]>,
tags: Store<any>,
2023-03-28 05:13:48 +02:00
state: { osmConnection?: OsmConnection; changes?: Changes; layout: LayoutConfig }
2022-09-08 21:40:48 +02:00
) {
const uiElements = images.map(
(imageURLS: { key: string; url: string; provider: ImageProvider }[]) => {
2021-06-11 22:51:45 +02:00
const uiElements: BaseUIElement[] = []
2020-06-24 00:35:19 +02:00
for (const url of imageURLS) {
2022-09-08 21:40:48 +02:00
try {
let image = new AttributedImage(url)
2020-06-24 00:35:19 +02:00
if (url.key !== undefined) {
image = new Combine([
image,
2021-12-21 18:35:31 +01:00
new DeleteImage(url.key, tags, state).SetClass(
"delete-image-marker absolute top-0 left-0 pl-3"
2022-09-08 21:40:48 +02:00
),
]).SetClass("relative")
2022-09-08 21:40:48 +02:00
}
image
.SetClass("w-full block")
.SetStyle("min-width: 50px; background: grey;")
uiElements.push(image)
} catch (e) {
console.error("Could not generate image element for", url.url, "due to", e)
}
}
2020-06-24 00:35:19 +02:00
return uiElements
}
2022-09-08 21:40:48 +02:00
)
2020-07-07 15:08:52 +02:00
2021-06-14 19:21:33 +02:00
super(
new SlideShow(uiElements).SetClass("w-full"),
undefined,
uiElements.map((els) => els.length > 0)
)
this.SetClass("block w-full")
2020-06-24 00:35:19 +02:00
}
}