Feature: offline: more features to be able to work fully offline

This commit is contained in:
Pieter Vander Vennet 2025-08-03 16:35:38 +02:00
parent 825efdee34
commit 06aa8a3406
23 changed files with 203 additions and 60 deletions

View file

@ -8,6 +8,7 @@ import Constants from "../../Models/Constants"
import { Feature, Point } from "geojson"
import { AndroidPolyfill } from "../Web/AndroidPolyfill"
import { QueryParameters } from "../Web/QueryParameters"
import { IsOnline } from "../Web/IsOnline"
interface OsmUserInfo {
id: number
@ -131,6 +132,7 @@ export class OsmConnection {
* Details of the currently logged-in user; undefined if not logged in
*/
public userDetails: UIEventSource<UserDetails | undefined>
public isLoggedIn: Store<boolean>
public gpxServiceIsOnline: UIEventSource<OsmServiceState> = new UIEventSource<OsmServiceState>(
"unknown"
@ -182,7 +184,7 @@ export class OsmConnection {
this._oauth_config.oauth_secret = import.meta.env.VITE_OSM_OAUTH_SECRET
}
this.userDetails = new UIEventSource<UserDetails>(undefined, "userDetails")
this.userDetails = UIEventSource.asObject<UserDetails>(LocalStorageSource.get("user_details"), undefined)
if (options.fakeUser) {
const ud = this.userDetails.data
ud.csCount = 5678
@ -197,13 +199,7 @@ export class OsmConnection {
}
this.updateCapabilities()
this.isLoggedIn = this.userDetails.map(
(user) =>
!!user &&
(this.apiIsOnline.data === "unknown" || this.apiIsOnline.data === "online"),
[this.apiIsOnline]
)
this.isLoggedIn = this.userDetails.map((user) => !!user)
this._dryRun = options.dryRun ?? new UIEventSource<boolean>(false)
if (options?.shared_cookie) {
@ -284,6 +280,9 @@ export class OsmConnection {
}
public async AttemptLogin() {
if (!IsOnline.isOnline.data) {
return
}
this.updateCapabilities()
if (this.loadingStatus.data !== "logged-in") {
this.loadingStatus.setData("loading")
@ -308,6 +307,9 @@ export class OsmConnection {
}
private async loadUserInfo() {
if (!IsOnline.isOnline.data) {
return
}
try {
const result = await this.interact("user/details.json")
if (result === null) {