@@ -2377,26 +2377,33 @@ function sharedCTABanner() {
23772377 </div>` ;
23782378}
23792379
2380- async function initSharedView ( ) {
2381- document . body . classList . add ( 'shared-view' ) ;
2382- document . getElementById ( 'auth-screen' ) . style . display = 'none' ;
2383- document . getElementById ( 'guest-banner' ) . style . display = 'none' ;
2384-
2380+ async function fetchSharedData ( ) {
23852381 try {
23862382 const r = await fetch ( `/shared/${ SHARED_TOKEN } /data` ) ;
2387- if ( ! r . ok ) {
2388- document . getElementById ( 'app' ) . innerHTML = sharedCTABanner ( ) +
2389- '<div class="done-page"><div class="done-empty">Shared profile not found.</div></div>' ;
2390- return ;
2391- }
2383+ if ( ! r . ok ) return false ;
23922384 data = await r . json ( ) ;
23932385 ensureDataShape ( ) ;
2394- if ( data . theme ) {
2395- localStorage . setItem ( THEME_KEY , data . theme ) ;
2396- applyTheme ( ) ;
2397- }
2386+ return true ;
23982387 } catch {
2399- data = { tasks : [ ] , later : [ ] , projects : [ ] } ;
2388+ return false ;
2389+ }
2390+ }
2391+
2392+ async function initSharedView ( ) {
2393+ document . body . classList . add ( 'shared-view' ) ;
2394+ document . getElementById ( 'auth-screen' ) . style . display = 'none' ;
2395+ document . getElementById ( 'guest-banner' ) . style . display = 'none' ;
2396+
2397+ const ok = await fetchSharedData ( ) ;
2398+ if ( ! ok ) {
2399+ document . getElementById ( 'app' ) . innerHTML = sharedCTABanner ( ) +
2400+ '<div class="done-page"><div class="done-empty">Shared profile not found.</div></div>' ;
2401+ return ;
2402+ }
2403+
2404+ if ( data . theme ) {
2405+ localStorage . setItem ( THEME_KEY , data . theme ) ;
2406+ applyTheme ( ) ;
24002407 }
24012408
24022409 // Insert CTA before the app content
@@ -2410,6 +2417,11 @@ async function initSharedView() {
24102417
24112418 render ( ) ;
24122419 ensureTick ( ) ;
2420+
2421+ // Poll for live updates
2422+ setInterval ( async ( ) => {
2423+ if ( await fetchSharedData ( ) ) { render ( ) ; }
2424+ } , 5000 ) ;
24132425}
24142426
24152427async function initSharedDonePage ( ) {
0 commit comments