From 3c5c1756d1c968e75e4af84d273233987148b5d1 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 30 Jul 2025 19:49:08 -0400 Subject: [PATCH] ssb: A progress bar experiment. --- apps/ssb.json | 2 +- apps/ssb/tf-app.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/apps/ssb.json b/apps/ssb.json index 804cc2f3..e77a7f68 100644 --- a/apps/ssb.json +++ b/apps/ssb.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "🦀", - "previous": "&DGtlnm5wWRZCgJMF8JsP6VtzNRrd4KLoERJRpFULqOY=.sha256" + "previous": "&Sxc7sz+X6FHHJiaLQU+E9Q0guS5yvqKyrZjF3ZyFStc=.sha256" } diff --git a/apps/ssb/tf-app.js b/apps/ssb/tf-app.js index 4389cbd3..dc53a174 100644 --- a/apps/ssb/tf-app.js +++ b/apps/ssb/tf-app.js @@ -25,6 +25,7 @@ class TfElement extends LitElement { recent_reactions: {type: Array}, is_administrator: {type: Boolean}, stay_connected: {type: Boolean}, + progress: {type: Number}, }; } @@ -450,7 +451,25 @@ class TfElement extends LitElement { this.schedule_load_latest(); } + reset_progress() { + if (this.progress === undefined) { + requestAnimationFrame(this.update_progress.bind(this)); + } + this.progress = 0; + } + + update_progress() { + if (!this.loading_latest && !this.loading_latest_scheduled) { + this.progress = undefined; + return; + } + const factor = 0.75; + this.progress = (this.progress * factor) + (100.0 * (1.0 - factor)); + requestAnimationFrame(this.update_progress.bind(this)); + } + schedule_load_latest() { + this.reset_progress(); if (!this.loading_latest) { this.shadowRoot.getElementById('tf-tab-news')?.load_latest(); this.load(); @@ -495,6 +514,7 @@ class TfElement extends LitElement { async load() { this.loading_latest = true; + this.reset_progress(); try { let start_time = new Date(); let whoami = this.whoami; @@ -646,6 +666,7 @@ class TfElement extends LitElement { async set_tab(tab) { this.tab = tab; if (tab === 'news') { + this.schedule_load_latest(); await tfrpc.rpc.setHash('#'); } else if (tab === 'connections') { await tfrpc.rpc.setHash('#connections'); @@ -751,11 +772,19 @@ class TfElement extends LitElement { Loading... ` : this.render_tab(); + let progress = this.progress !== undefined ? + html` +
+
+
+ ` : + undefined; return html`
+ ${progress}
${tabs}
${contents}