mapcomplete/UI/Image/DeleteImage.ts

63 lines
2.7 KiB
TypeScript
Raw Normal View History

import {UIEventSource} from "../../Logic/UIEventSource";
import Translations from "../i18n/Translations";
2021-06-10 01:36:20 +02:00
import Toggle from "../Input/Toggle";
import Combine from "../Base/Combine";
2020-11-06 04:02:53 +01:00
import Svg from "../../Svg";
2021-03-29 00:41:53 +02:00
import {Tag} from "../../Logic/Tags/Tag";
import ChangeTagAction from "../../Logic/Osm/Actions/ChangeTagAction";
2021-12-21 18:35:31 +01:00
import {Changes} from "../../Logic/Osm/Changes";
import {OsmConnection} from "../../Logic/Osm/OsmConnection";
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
2021-06-15 16:18:58 +02:00
export default class DeleteImage extends Toggle {
constructor(key: string, tags: UIEventSource<any>, state: {layoutToUse: LayoutConfig, changes?: Changes, osmConnection?: OsmConnection}) {
2021-06-15 16:18:58 +02:00
const oldValue = tags.data[key]
const isDeletedBadge = Translations.t.image.isDeleted.Clone()
.SetClass("rounded-full p-1")
.SetStyle("color:white;background:#ff8c8c")
2021-11-07 16:34:51 +01:00
.onClick(async () => {
2021-12-21 18:35:31 +01:00
await state?.changes?.applyAction(new ChangeTagAction(tags.data.id, new Tag(key, oldValue), tags.data, {
changeType: "delete-image",
theme: state.layoutToUse.id
2021-11-07 16:34:51 +01:00
}))
2021-06-15 16:18:58 +02:00
});
const deleteButton = Translations.t.image.doDelete.Clone()
.SetClass("block w-full pl-4 pr-4")
.SetStyle("color:white;background:#ff8c8c; border-top-left-radius:30rem; border-top-right-radius: 30rem;")
2021-11-07 16:34:51 +01:00
.onClick(async () => {
2021-12-21 18:35:31 +01:00
await state?.changes?.applyAction(
2021-11-07 16:34:51 +01:00
new ChangeTagAction(tags.data.id, new Tag(key, ""), tags.data, {
2021-10-06 02:36:58 +02:00
changeType: "answer",
theme: "test"
})
)
});
2021-06-15 16:18:58 +02:00
const cancelButton = Translations.t.general.cancel.Clone().SetClass("bg-white pl-4 pr-4").SetStyle("border-bottom-left-radius:30rem; border-bottom-right-radius: 30rem;");
const openDelete = Svg.delete_icon_svg().SetStyle("width: 2em; height: 2em; display:block;")
const deleteDialog = new Toggle(
new Combine([
deleteButton,
cancelButton
]).SetClass("flex flex-col background-black"),
2021-06-15 16:18:58 +02:00
openDelete
)
cancelButton.onClick(() => deleteDialog.isEnabled.setData(false))
openDelete.onClick(() => deleteDialog.isEnabled.setData(true))
super(
new Toggle(
deleteDialog,
isDeletedBadge,
tags.map(tags => (tags[key] ?? "") !== "")
),
undefined /*Login (and thus editing) is disabled*/,
2021-12-21 18:35:31 +01:00
state.osmConnection.isLoggedIn
2021-06-15 16:18:58 +02:00
)
this.SetClass("cursor-pointer")
}
}