mapcomplete/UI/Image/DeleteImage.ts

72 lines
2.8 KiB
TypeScript
Raw Normal View History

2022-09-08 21:40:48 +02:00
import { Store } from "../../Logic/UIEventSource"
import Translations from "../i18n/Translations"
import Toggle, { ClickableToggle } from "../Input/Toggle"
import Combine from "../Base/Combine"
import Svg from "../../Svg"
import { Tag } from "../../Logic/Tags/Tag"
import ChangeTagAction from "../../Logic/Osm/Actions/ChangeTagAction"
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 {
2022-09-08 21:40:48 +02:00
constructor(
key: string,
tags: Store<any>,
2023-03-28 05:13:48 +02:00
state: { layout: LayoutConfig; changes?: Changes; osmConnection?: OsmConnection }
2022-09-08 21:40:48 +02:00
) {
2021-06-15 16:18:58 +02:00
const oldValue = tags.data[key]
2022-09-08 21:40:48 +02:00
const isDeletedBadge = Translations.t.image.isDeleted
.Clone()
2021-06-15 16:18:58 +02:00
.SetClass("rounded-full p-1")
.SetStyle("color:white;background:#ff8c8c")
2021-11-07 16:34:51 +01:00
.onClick(async () => {
2022-09-08 21:40:48 +02:00
await state?.changes?.applyAction(
new ChangeTagAction(tags.data.id, new Tag(key, oldValue), tags.data, {
changeType: "delete-image",
2023-03-28 05:13:48 +02:00
theme: state.layout.id,
2022-09-08 21:40:48 +02:00
})
)
})
2022-09-08 21:40:48 +02:00
const deleteButton = Translations.t.image.doDelete
.Clone()
.SetClass("block w-full pl-4 pr-4")
2022-09-08 21:40:48 +02:00
.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",
2023-03-28 05:13:48 +02:00
theme: state.layout.id,
2021-10-06 02:36:58 +02:00
})
)
2022-09-08 21:40:48 +02:00
})
2022-09-08 21:40:48 +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;")
2021-06-15 16:18:58 +02:00
const openDelete = Svg.delete_icon_svg().SetStyle("width: 2em; height: 2em; display:block;")
const deleteDialog = new ClickableToggle(
2022-09-08 21:40:48 +02:00
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,
2022-09-08 21:40:48 +02:00
tags.map((tags) => (tags[key] ?? "") !== "")
2021-06-15 16:18:58 +02:00
),
undefined /*Login (and thus editing) is disabled*/,
state?.osmConnection?.isLoggedIn
2021-06-15 16:18:58 +02:00
)
this.SetClass("cursor-pointer")
}
2022-09-08 21:40:48 +02:00
}