From 6057199bb1d926f40fe32bbee1422e22d61b6073 Mon Sep 17 00:00:00 2001 From: Gustavo Saiani Date: Sat, 4 Apr 2026 07:42:38 -0300 Subject: [PATCH] Poll for live updates in shared view (#109) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Shared profile viewers now see task changes in real time — fetches fresh data every 5 seconds and re-renders. --- static/app.js | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/static/app.js b/static/app.js index 60ac6de..4652fe4 100644 --- a/static/app.js +++ b/static/app.js @@ -2377,26 +2377,33 @@ function sharedCTABanner() { `; } -async function initSharedView() { - document.body.classList.add('shared-view'); - document.getElementById('auth-screen').style.display = 'none'; - document.getElementById('guest-banner').style.display = 'none'; - +async function fetchSharedData() { try { const r = await fetch(`/shared/${SHARED_TOKEN}/data`); - if (!r.ok) { - document.getElementById('app').innerHTML = sharedCTABanner() + - '
Shared profile not found.
'; - return; - } + if (!r.ok) return false; data = await r.json(); ensureDataShape(); - if (data.theme) { - localStorage.setItem(THEME_KEY, data.theme); - applyTheme(); - } + return true; } catch { - data = { tasks: [], later: [], projects: [] }; + return false; + } +} + +async function initSharedView() { + document.body.classList.add('shared-view'); + document.getElementById('auth-screen').style.display = 'none'; + document.getElementById('guest-banner').style.display = 'none'; + + const ok = await fetchSharedData(); + if (!ok) { + document.getElementById('app').innerHTML = sharedCTABanner() + + '
Shared profile not found.
'; + return; + } + + if (data.theme) { + localStorage.setItem(THEME_KEY, data.theme); + applyTheme(); } // Insert CTA before the app content @@ -2410,6 +2417,11 @@ async function initSharedView() { render(); ensureTick(); + + // Poll for live updates + setInterval(async () => { + if (await fetchSharedData()) { render(); } + }, 5000); } async function initSharedDonePage() {