MapComplete/UI/Popup/LoginButton.ts

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

53 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-01-08 14:08:04 +01:00
import { SubtleButton } from "../Base/SubtleButton"
import BaseUIElement from "../BaseUIElement"
import Svg from "../../Svg"
import { OsmConnection } from "../../Logic/Osm/OsmConnection"
import Toggle from "../Input/Toggle"
2022-02-15 15:42:09 +01:00
import { VariableUiElement } from "../Base/VariableUIElement"
import Loading from "../Base/Loading"
import Translations from "../i18n/Translations"
2022-01-08 14:08:04 +01:00
2022-02-15 15:42:09 +01:00
class LoginButton extends SubtleButton {
2022-01-08 14:08:04 +01:00
constructor(
text: BaseUIElement | string,
state: {
osmConnection: OsmConnection
2022-02-15 15:42:09 +01:00
},
icon?: BaseUIElement | string
) {
super(icon ?? Svg.osm_logo_ui(), text)
2022-01-08 14:08:04 +01:00
this.onClick(() => {
state.osmConnection.AttemptLogin()
})
}
}
2022-02-15 15:42:09 +01:00
export class LoginToggle extends VariableUiElement {
2022-01-08 14:08:04 +01:00
constructor(
el,
text: BaseUIElement | string,
state: {
osmConnection: OsmConnection
}
) {
2022-02-15 15:42:09 +01:00
const loading = new Loading("Trying to log in...")
const login = new LoginButton(text, state)
super(
state.osmConnection.loadingStatus.map((osmConnectionState) => {
if (osmConnectionState === "loading") {
return loading
}
if (osmConnectionState === "not-attempted") {
return login
}
if (osmConnectionState === "logged-in") {
return el
}
2022-09-08 21:40:48 +02:00
2022-02-15 15:42:09 +01:00
// Error!
return new LoginButton(Translations.t.general.loginFailed, state, Svg.invalid_svg())
})
)
2022-01-08 14:08:04 +01:00
}
}