mapcomplete/UI/BigComponents/AllDownloads.ts

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

55 lines
2 KiB
TypeScript
Raw Normal View History

2021-07-28 16:48:59 +02:00
import Combine from "../Base/Combine"
import Translations from "../i18n/Translations"
import {UIEventSource} from "../../Logic/UIEventSource"
2021-07-28 16:48:59 +02:00
import Toggle from "../Input/Toggle"
import {SubtleButton} from "../Base/SubtleButton"
2021-07-28 16:48:59 +02:00
import Svg from "../../Svg"
import ExportPDF from "../ExportPDF"
import FilteredLayer from "../../Models/FilteredLayer"
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"
import {BBox} from "../../Logic/BBox"
import Loc from "../../Models/Loc"
export default class AllDownloads extends SubtleButton {
constructor(
isShown: UIEventSource<boolean>,
state: {
filteredLayers: UIEventSource<FilteredLayer[]>
layoutToUse: LayoutConfig
currentBounds: UIEventSource<BBox>
locationControl: UIEventSource<Loc>
featureSwitchExportAsPdf: UIEventSource<boolean>
featureSwitchEnableExport: UIEventSource<boolean>
}
) {
const isExporting = new UIEventSource(false, "Pdf-is-exporting")
2021-07-28 16:48:59 +02:00
const generatePdf = () => {
isExporting.setData(true)
2021-07-28 16:48:59 +02:00
new ExportPDF({
freeDivId: "belowmap",
location: state.locationControl,
layout: state.layoutToUse,
}).isRunning.addCallbackAndRun((isRunning) => isExporting.setData(isRunning))
2021-07-28 16:48:59 +02:00
}
const loading = Svg.loading_svg().SetClass("animate-rotate")
2021-10-03 01:38:57 +02:00
const dloadTrans = Translations.t.general.download
const icon = new Toggle(loading, Svg.floppy_svg(), isExporting)
const text = new Toggle(
2021-10-03 01:38:57 +02:00
dloadTrans.exporting.Clone(),
new Combine([
2021-10-03 01:38:57 +02:00
dloadTrans.downloadAsPdf.Clone().SetClass("font-bold"),
dloadTrans.downloadAsPdfHelper.Clone(),
2022-09-08 21:40:48 +02:00
])
.SetClass("flex flex-col")
.onClick(() => {
generatePdf()
}),
isExporting
2022-09-08 21:40:48 +02:00
)
super(icon, text)
}
2021-07-28 16:48:59 +02:00
}