mapcomplete/UI/Popup/SaveButton.ts

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

49 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-06-06 19:37:22 +02:00
import { ImmutableStore, Store } from "../../Logic/UIEventSource"
2020-10-14 12:15:09 +02:00
import Translations from "../i18n/Translations"
2021-06-12 02:58:32 +02:00
import { OsmConnection } from "../../Logic/Osm/OsmConnection"
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"
export class EditButton extends Toggle {
constructor(osmConnection: OsmConnection, onClick: () => void) {
super(
new Combine([Svg.pencil_ui()])
.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
2021-06-14 02:39:23 +02:00
export class SaveButton extends Toggle {
constructor(
value: Store<any>,
osmConnection: OsmConnection,
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 pleaseLogin = Translations.t.general.loginToStart
.Clone()
2020-10-27 01:01:34 +01:00
.SetClass("login-button-friendly")
2020-12-08 23:44:34 +01:00
.onClick(() => osmConnection?.AttemptLogin())
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)
2022-06-06 19:37:22 +02:00
super(save, pleaseLogin, osmConnection?.isLoggedIn ?? new ImmutableStore(false))
2020-07-05 18:59:47 +02:00
}
}