Loginbutton now shows a warning if the API is offline, fix #880

This commit is contained in:
Pieter Vander Vennet 2023-01-06 03:32:17 +01:00
parent 29b0b2871b
commit e4c586ef99
3 changed files with 69 additions and 18 deletions

View file

@ -1,11 +1,13 @@
import { SubtleButton } from "../Base/SubtleButton" import { SubtleButton } from "../Base/SubtleButton"
import BaseUIElement from "../BaseUIElement" import BaseUIElement from "../BaseUIElement"
import Svg from "../../Svg" import Svg from "../../Svg"
import { OsmConnection } from "../../Logic/Osm/OsmConnection" import { OsmConnection, OsmServiceState } from "../../Logic/Osm/OsmConnection"
import Toggle from "../Input/Toggle"
import { VariableUiElement } from "../Base/VariableUIElement" import { VariableUiElement } from "../Base/VariableUIElement"
import Loading from "../Base/Loading" import Loading from "../Base/Loading"
import Translations from "../i18n/Translations" import Translations from "../i18n/Translations"
import { Store } from "../../Logic/UIEventSource"
import Combine from "../Base/Combine"
import { Translation } from "../i18n/Translation"
class LoginButton extends SubtleButton { class LoginButton extends SubtleButton {
constructor( constructor(
@ -23,30 +25,67 @@ class LoginButton extends SubtleButton {
} }
export class LoginToggle extends VariableUiElement { export class LoginToggle extends VariableUiElement {
/**
* Constructs an element which shows 'el' if the user is logged in
* If not logged in, 'text' is shown on the button which invites to login.
*
* If logging in is not possible for some reason, an appropriate error message is shown
*
* State contains the 'osmConnection' to work with
*/
constructor( constructor(
el: BaseUIElement, el: BaseUIElement,
text: BaseUIElement | string, text: BaseUIElement | string,
state: { state: {
osmConnection: OsmConnection readonly osmConnection: OsmConnection
readonly featureSwitchUserbadge: Store<boolean>
} }
) { ) {
const loading = new Loading("Trying to log in...") const loading = new Loading("Trying to log in...")
const login = new LoginButton(text, state) const login = text === undefined ? undefined : new LoginButton(text, state)
super( const t = Translations.t.general
state.osmConnection.loadingStatus.map((osmConnectionState) => { const offlineModes: Partial<Record<OsmServiceState, Translation>> = {
if (osmConnectionState === "loading") { offline: t.loginFailedOfflineMode,
return loading unreachable: t.loginFailedUnreachableMode,
} readonly: t.loginFailedReadonlyMode,
if (osmConnectionState === "not-attempted") { }
return login
}
if (osmConnectionState === "logged-in") {
return el
}
// Error! super(
return new LoginButton(Translations.t.general.loginFailed, state, Svg.invalid_svg()) state.osmConnection.loadingStatus.map(
}) (osmConnectionState) => {
if (state.featureSwitchUserbadge.data == false) {
// All features to login with are disabled
return undefined
}
const apiState = state.osmConnection.apiIsOnline.data
const apiTranslation = offlineModes[apiState]
if (apiTranslation !== undefined) {
return new Combine([
Svg.invalid_svg().SetClass("w-8 h-8 m-2 shrink-0"),
apiTranslation,
]).SetClass("flex items-center alert max-w-64")
}
if (osmConnectionState === "loading") {
return loading
}
if (osmConnectionState === "not-attempted") {
return login
}
if (osmConnectionState === "logged-in") {
return el
}
// Error!
return new LoginButton(
Translations.t.general.loginFailed,
state,
Svg.invalid_svg()
)
},
[state.featureSwitchUserbadge, state.osmConnection.apiIsOnline]
)
) )
} }
} }

View file

@ -1382,6 +1382,10 @@ video {
border-bottom-width: 1px; border-bottom-width: 1px;
} }
.border-b-2 {
border-bottom-width: 2px;
}
.border-dotted { .border-dotted {
border-style: dotted; border-style: dotted;
} }
@ -1561,6 +1565,10 @@ video {
padding-right: 0.5rem; padding-right: 0.5rem;
} }
.pb-8 {
padding-bottom: 2rem;
}
.pl-5 { .pl-5 {
padding-left: 1.25rem; padding-left: 1.25rem;
} }

View file

@ -188,6 +188,9 @@
"loading": "Loading…", "loading": "Loading…",
"loadingTheme": "Loading {theme}…", "loadingTheme": "Loading {theme}…",
"loginFailed": "Logging in into OpenStreetMap failed", "loginFailed": "Logging in into OpenStreetMap failed",
"loginFailedOfflineMode": "OpenStreetMap.org is currently not available due to maintenance. Making edits will be possible soon",
"loginFailedReadonlyMode": "OpenStreetMap.org is currently in readonly mode due to maintenance. Making edits will be possible soon",
"loginFailedUnreachableMode": "OpenStreetMap.org is currently not reachable. Are you connected to the internet or do you block third parties? Try again later",
"loginOnlyNeededToEdit": "if you want to edit the map", "loginOnlyNeededToEdit": "if you want to edit the map",
"loginToStart": "Log in to answer this question", "loginToStart": "Log in to answer this question",
"loginWithOpenStreetMap": "Login with OpenStreetMap", "loginWithOpenStreetMap": "Login with OpenStreetMap",
@ -284,6 +287,7 @@
"uploadGpx": { "uploadGpx": {
"choosePermission": "Choose below if your track should be shared:", "choosePermission": "Choose below if your track should be shared:",
"confirm": "Confirm upload", "confirm": "Confirm upload",
"gpxServiceOffline": "The GPX-service is currently offline - uploading is currently not possible. Try again later.",
"intro0": "By uploading your track, OpenStreetMap.org will retain a full copy of the track.", "intro0": "By uploading your track, OpenStreetMap.org will retain a full copy of the track.",
"intro1": "You will be able to download your track again and to load them into OpenStreetMap editing programs", "intro1": "You will be able to download your track again and to load them into OpenStreetMap editing programs",
"meta": { "meta": {