Show loading screen when logging in

This commit is contained in:
Pieter Vander Vennet 2022-02-15 15:42:09 +01:00
parent 0a43a69a0c
commit e721146ca1
7 changed files with 75 additions and 353 deletions

View file

@ -46,6 +46,7 @@ export class OsmConnection {
public auth;
public userDetails: UIEventSource<UserDetails>;
public isLoggedIn: UIEventSource<boolean>
public loadingStatus = new UIEventSource<"not-attempted" | "loading" | "error" | "logged-in">("not-attempted")
public preferencesHandler: OsmPreferences;
public changesetHandler: ChangesetHandler;
public readonly _oauth_config: {
@ -141,10 +142,13 @@ export class OsmConnection {
this.userDetails.data.name = "";
this.userDetails.ping();
console.log("Logged out")
this.loadingStatus.setData("not-attempted")
}
public AttemptLogin() {
this.loadingStatus.setData("loading")
if (this.fakeUser) {
this.loadingStatus.setData("logged-in")
console.log("AttemptLogin called, but ignored as fakeUser is set")
return;
}
@ -157,6 +161,7 @@ export class OsmConnection {
}, function (err, details) {
if (err != null) {
console.log(err);
self.loadingStatus.setData("error")
if (err.status == 401) {
console.log("Clearing tokens...")
// Not authorized - our token probably got revoked
@ -171,6 +176,7 @@ export class OsmConnection {
}
if (details == null) {
self.loadingStatus.setData("error")
return;
}
@ -202,6 +208,7 @@ export class OsmConnection {
data.home = {lat: lat, lon: lon};
}
self.loadingStatus.setData("logged-in")
const messages = userInfo.getElementsByTagName("messages")[0].getElementsByTagName("received")[0];
data.unreadMessages = parseInt(messages.getAttribute("unread"));
data.totalMessages = parseInt(messages.getAttribute("count"));
@ -305,7 +312,7 @@ export class OsmConnection {
})
}
public addCommentToNode(id: number | string, text: string): Promise<any> {
if (this._dryRun.data) {
console.warn("Dryrun enabled - not actually adding comment ", text, "to note ", id)