mapcomplete/UI/Popup/SaveButton.ts

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

48 lines
1.6 KiB
TypeScript
Raw Normal View History

import {Store} from "../../Logic/UIEventSource"
2020-10-14 12:15:09 +02:00
import Translations from "../i18n/Translations"
import {OsmConnection} from "../../Logic/Osm/OsmConnection"
2021-06-12 02:58:32 +02:00
import Toggle from "../Input/Toggle"
import BaseUIElement from "../BaseUIElement"
2022-11-02 14:44:06 +01:00
import Combine from "../Base/Combine"
import Svg from "../../Svg"
import {LoginToggle} from "./LoginButton";
export class EditButton extends Toggle {
constructor(osmConnection: OsmConnection, onClick: () => void) {
super(
new Combine([Svg.pencil_svg()])
.SetClass("block relative h-10 w-10 p-2 float-right")
.SetStyle("border: 1px solid black; border-radius: 0.7em")
.onClick(onClick),
undefined,
osmConnection.isLoggedIn
)
}
}
2020-07-05 18:59:47 +02:00
export class SaveButton extends LoginToggle {
constructor(
value: Store<any>,
state: {
readonly osmConnection?: OsmConnection
readonly featureSwitchUserbadge?: Store<boolean>
},
textEnabled?: BaseUIElement,
textDisabled?: BaseUIElement
) {
2021-06-12 02:58:32 +02:00
if (value === undefined) {
2020-07-05 18:59:47 +02:00
throw "No event source for savebutton, something is wrong"
}
2021-06-12 02:58:32 +02:00
const isSaveable = value.map((v) => v !== false && (v ?? "") !== "")
const saveEnabled = (textEnabled ?? Translations.t.general.save.Clone()).SetClass(`btn`)
const saveDisabled = (textDisabled ?? Translations.t.general.save.Clone()).SetClass(
`btn btn-disabled`
2021-06-12 02:58:32 +02:00
)
const save = new Toggle(saveEnabled, saveDisabled, isSaveable)
super(save, Translations.t.general.loginToStart, state)
2020-07-05 18:59:47 +02:00
}
}