static site frontend for mapped.at mapped.at
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

Separate data loading

+11 -5
+8 -2
api.js
··· 93 93 // ── fetchServiceData ─────────────────────────────────────────────── 94 94 // Fetches trails, locations, activities from the service account and returns 95 95 // URI→record lookup maps plus normalised arrays for public consumption. 96 - async function fetchServiceData() { 96 + let _servicePromise = null; 97 + export function fetchServiceData() { 98 + if (!_servicePromise) _servicePromise = _fetchServiceData(); 99 + return _servicePromise; 100 + } 101 + 102 + async function _fetchServiceData() { 97 103 const [trailRecs, locationRecs, activityRecs] = await Promise.all([ 98 104 listRecords('at.mapped.trail'), 99 105 listRecords('at.mapped.location'), ··· 258 264 } 259 265 260 266 async function _fetchAll() { 261 - // Step 1: Service account data (parallel) 267 + // Step 1: Service account data (cached — shared with TrailsList/TabSwitcher) 262 268 const serviceData = await fetchServiceData(); 263 269 const { trails, locations, activities } = serviceData; 264 270
+3 -3
script.js
··· 15 15 XrpcHandleResolver, 16 16 } from '@atcute/identity-resolver'; 17 17 import { getRoute, navigate, onRouteChange } from './router.js'; 18 - import { fetchAll } from './api.js'; 18 + import { fetchAll, fetchServiceData } from './api.js'; 19 19 20 20 // ── ATProto OAuth configuration ─────────────────────────────────── 21 21 configureOAuth({ ··· 565 565 select.disabled = true; 566 566 567 567 if (route.view === 'trails') { 568 - fetchAll().then(({ locations }) => { 568 + fetchServiceData().then(({ locations }) => { 569 569 select.disabled = false; 570 570 const defaultOpt = document.createElement('option'); 571 571 defaultOpt.value = ''; ··· 743 743 async _load(shadow) { 744 744 let data; 745 745 try { 746 - data = await fetchAll(); 746 + data = await fetchServiceData(); 747 747 } catch (err) { 748 748 shadow.querySelector('.trails-list').innerHTML = 749 749 `<p style="text-align:center;color:#999;padding:32px">Failed to load trails.</p>`;