From e10803de68876a289f8b888a9e1fe20d0870a879 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sat, 12 Aug 2023 18:37:15 +0000 Subject: [PATCH] Fix GPX upload. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4396 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- apps/gg/script.js | 66 ++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/apps/gg/script.js b/apps/gg/script.js index 29ea7208..6e532c6a 100644 --- a/apps/gg/script.js +++ b/apps/gg/script.js @@ -65,6 +65,7 @@ class GgAppElement extends LitElement { async get_activities_from_ssb() { this.status = {text: 'loading activities'}; + this.loaded_activities = []; let blob_ids = await tfrpc.rpc.query(` SELECT json_extract(mention.value, '$.link') AS blob_id FROM messages_fts('"gg-activity"') @@ -165,7 +166,6 @@ class GgAppElement extends LitElement { } let shared = await tfrpc.rpc.sharedDatabaseGet(name); if (shared) { - console.log('shared =', shared); await tfrpc.rpc.databaseSet('strava', shared); await tfrpc.rpc.sharedDatabaseRemove(name); } @@ -446,7 +446,6 @@ class GgAppElement extends LitElement { } } if (activity?.segments) { - console.log('have a gpx'); for (let segment of activity.segments) { let last; for (let pt of segment) { @@ -464,37 +463,40 @@ class GgAppElement extends LitElement { } async on_upload(event) { - let file = event.srcElement.files[0]; - let xml = await file.text(); - let gpx = gpx_parse(xml); - let blob_id = await tfrpc.rpc.store_blob(xml); - console.log('blob_id = ', blob_id); - let message = { - type: 'gg-activity', - mentions: [ - { - link: `https://${gpx.link}/activity/${gpx.time}`, - name: 'activity_url', - }, - { - link: blob_id, - name: 'activity_data', - } - ], - }; - console.log('message = ', message); try { + let file = event.srcElement.files[0]; + let xml = await file.text(); + let gpx = gpx_parse(xml); + let blob_id = await tfrpc.rpc.store_blob(xml); + console.log('blob_id = ', blob_id); + console.log(gpx); + let message = { + type: 'gg-activity', + mentions: [ + { + link: `https://${gpx.link}/activity/${gpx.time}`, + name: 'activity_url', + }, + { + link: blob_id, + name: 'activity_data', + } + ], + }; + console.log('id =', this.id, 'message = ', message); let id = await tfrpc.rpc.appendMessage(this.id, message); console.log('appended message', id); + alert('Activity uploaded.'); + await this.get_activities_from_ssb(); } catch (e) { - console.log('augh', e); + alert(`Error: ${JSON.stringify(e, null, 2)}`); } } upload() { let input = document.createElement('input'); input.type = 'file'; - input.onchange = this.on_upload; + input.onchange = (event) => this.on_upload(event); input.click(); } @@ -504,17 +506,23 @@ class GgAppElement extends LitElement { } if (!this.strava?.access_token) { let strava_url = `https://www.strava.com/oauth/authorize?client_id=${k_client_id}&redirect_uri=${k_redirect_url}&response_type=code&approval_prompt=auto&scope=activity%3Aread&state=${g_data.state}`; - return html`
Please login to Strava.
`; + return html` +
+
Please login to Strava.
+ ${this.id} + +
+ `; } return html`
-

- Welcome, ${this.user.credentials.session.name} - ${this.id} +
+

Welcome, ${this.user.credentials.session.name}

+ ${this.id} -

-

${this.status?.text} ${this.status?.value}

+
+

${this.status?.text} ${this.status?.value}

`; }