From f659ed8fbfdbc31977f2b72c11a12e0600765434 Mon Sep 17 00:00:00 2001 From: AshwaSC Date: Fri, 31 Jul 2026 16:07:32 +0530 Subject: [PATCH] feat: standardise city hubs to reflect real data (communities + stories) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit City hub quick-stats and the Community Stories card were hardcoded on the 12 "coming soon" cities — e.g. Chennai showed "0 Communities" and a Coming Soon stories card despite a live Chennai story, and Pune showed "0" while it actually has 1 community. Only the Bengaluru hub was data-driven. Add a shared /assets/js/pages/city-hub.js (mirrors Bengaluru's inline pattern: load all, filter by city.toLowerCase()) that, on every city hub: - sets the Communities stat to the real per-city DB count, and - flips the Community Stories card to Live (linking to the city's /stories/ page) when the city has at least one story, else leaves it Coming Soon. Wire it into the 12 coming-soon hubs by adding data-stat="communities" to the Communities stat tile, data-feature="stories" to the stories card, and the script tag after data-loader.js. Chennai's stories card (made statically Live in the previous PR) is reverted to the shared Coming Soon default so all hubs are identical and the script drives the state uniformly. Climate Sectors and Wards Tracked are unchanged (they count built infrastructure, not DB content). No new i18n keys; reuses existing cityHub.features.stories.* and cityHub.features.map.statusLive. Bengaluru left as-is. Verified in headless Chrome: Chennai -> 0 communities + Live stories card; Pune -> 1 community + Coming Soon. Co-Authored-By: Claude Opus 4.8 (1M context) --- website/public/assets/js/pages/city-hub.js | 79 +++++++++++++++++++ website/public/cities/ahmedabad/index.html | 5 +- website/public/cities/bhubaneswar/index.html | 5 +- website/public/cities/chennai/index.html | 21 ++--- website/public/cities/gurugram/index.html | 5 +- website/public/cities/hyderabad/index.html | 5 +- website/public/cities/jaipur/index.html | 5 +- website/public/cities/kochi/index.html | 5 +- website/public/cities/kolkata/index.html | 5 +- website/public/cities/mumbai/index.html | 5 +- website/public/cities/pune/index.html | 5 +- website/public/cities/thane/index.html | 5 +- .../public/cities/visakhapatnam/index.html | 5 +- 13 files changed, 123 insertions(+), 32 deletions(-) create mode 100644 website/public/assets/js/pages/city-hub.js diff --git a/website/public/assets/js/pages/city-hub.js b/website/public/assets/js/pages/city-hub.js new file mode 100644 index 00000000..9646a377 --- /dev/null +++ b/website/public/assets/js/pages/city-hub.js @@ -0,0 +1,79 @@ +// City hub page: make the quick-stats and feature cards reflect real data, +// standardised across every city hub (mirrors the dynamic behaviour the +// Bengaluru hub does inline). Loaded after data-loader.js on each city +// /cities//index.html. +// +// - Communities stat -> live per-city count from Supabase. +// - Community Stories card -> flips Live (links to the city stories page) +// when the city has at least one story, otherwise left as Coming Soon. +// Climate Sectors and Wards Tracked are intentionally left untouched (they +// count built infrastructure, not DB content). + +(function () { + (async function init() { + const header = document.getElementById('notf-header'); + const slug = header && header.dataset ? (header.dataset.city || '') : ''; + if (!slug) return; + + try { + await dataLoader.waitForSupabase(); + + // Load all, then filter client-side by lowercased city so we don't + // depend on the exact casing stored in the DB (same as the + // Bengaluru hub). + const [communities, stories] = await Promise.all([ + dataLoader.loadCommunities(), + dataLoader.loadStories() + ]); + const byCity = (x) => x.city && x.city.toLowerCase() === slug; + const cityCommunities = communities.filter(byCity); + const cityStories = stories.filter(byCity); + + // Communities stat -> real count. + const commStat = document.querySelector('[data-stat="communities"]'); + if (commStat) { + commStat.textContent = cityCommunities.length; + if (cityCommunities.length > 0) commStat.classList.remove('zero'); + } + + // Community Stories card -> Live when the city has stories. + const storiesCard = document.querySelector('[data-feature="stories"]'); + if (storiesCard && cityStories.length > 0) { + storiesCard.classList.remove('coming-soon'); + + const badge = storiesCard.querySelector('.feature-status-badge'); + if (badge) { + badge.className = 'feature-status-badge live'; + badge.innerHTML = + ' ' + + 'Live'; + } + + const desc = storiesCard.querySelector('.feature-description'); + if (desc) { + desc.setAttribute('data-i18n', 'cityHub.features.stories.description'); + desc.textContent = + 'Discover real stories of neighbourhood transformation, ' + + 'told by the people who made it happen.'; + } + + const action = storiesCard.querySelector('.feature-action'); + if (action) { + action.innerHTML = + '' + + 'Read Stories ' + + ''; + } + + // Translate the newly injected data-i18n nodes. + if (window.translator && typeof window.translator.translatePage === 'function') { + window.translator.translatePage(); + } + } + + console.log('[City Hub]', slug, '-', cityCommunities.length, 'communities,', cityStories.length, 'stories'); + } catch (error) { + console.error('[City Hub] Error loading data:', error); + } + })(); +})(); diff --git a/website/public/cities/ahmedabad/index.html b/website/public/cities/ahmedabad/index.html index 2762dc21..94e3d1b0 100644 --- a/website/public/cities/ahmedabad/index.html +++ b/website/public/cities/ahmedabad/index.html @@ -358,7 +358,7 @@

Ahmedabad

-
0
+
0
Communities
@@ -427,7 +427,7 @@

Communities

-
+
@@ -484,6 +484,7 @@

Ahmedabad Data Coming Soon

+ diff --git a/website/public/cities/bhubaneswar/index.html b/website/public/cities/bhubaneswar/index.html index 82902877..b8c129c0 100644 --- a/website/public/cities/bhubaneswar/index.html +++ b/website/public/cities/bhubaneswar/index.html @@ -358,7 +358,7 @@

Bhubaneswar

-
0
+
0
Communities
@@ -427,7 +427,7 @@

Communities

-
+
@@ -484,6 +484,7 @@

Bhubaneswar Data Coming Soon

+ diff --git a/website/public/cities/chennai/index.html b/website/public/cities/chennai/index.html index edfad5bc..a1309786 100644 --- a/website/public/cities/chennai/index.html +++ b/website/public/cities/chennai/index.html @@ -358,7 +358,7 @@

Chennai

-
0
+
0
Communities
@@ -426,26 +426,26 @@

Communities

- -
+ +

Community Stories

- - Live + + Coming Soon
-

- Discover real stories of neighbourhood transformation, told by the people who made it happen. +

+ Community stories for this city are under development. Real stories of neighbourhood transformation coming soon.

- - Read Stories - +
@@ -484,6 +484,7 @@

Chennai Data Coming Soon

+ diff --git a/website/public/cities/gurugram/index.html b/website/public/cities/gurugram/index.html index ca2af9f3..b774a1b7 100644 --- a/website/public/cities/gurugram/index.html +++ b/website/public/cities/gurugram/index.html @@ -358,7 +358,7 @@

Gurugram

-
0
+
0
Communities
@@ -427,7 +427,7 @@

Communities

-
+
@@ -484,6 +484,7 @@

Gurugram Data Coming Soon

+ diff --git a/website/public/cities/hyderabad/index.html b/website/public/cities/hyderabad/index.html index 96ceb704..a9528b53 100644 --- a/website/public/cities/hyderabad/index.html +++ b/website/public/cities/hyderabad/index.html @@ -358,7 +358,7 @@

Hyderabad

-
0
+
0
Communities
@@ -427,7 +427,7 @@

Communities

-
+
@@ -484,6 +484,7 @@

Hyderabad Data Coming Soon

+ diff --git a/website/public/cities/jaipur/index.html b/website/public/cities/jaipur/index.html index f8f48017..783e34b3 100644 --- a/website/public/cities/jaipur/index.html +++ b/website/public/cities/jaipur/index.html @@ -358,7 +358,7 @@

Jaipur

-
0
+
0
Communities
@@ -427,7 +427,7 @@

Communities

-
+
@@ -484,6 +484,7 @@

Jaipur Data Coming Soon

+ diff --git a/website/public/cities/kochi/index.html b/website/public/cities/kochi/index.html index 55848b10..6ab96174 100644 --- a/website/public/cities/kochi/index.html +++ b/website/public/cities/kochi/index.html @@ -358,7 +358,7 @@

Kochi

-
0
+
0
Communities
@@ -427,7 +427,7 @@

Communities

-
+
@@ -484,6 +484,7 @@

Kochi Data Coming Soon

+ diff --git a/website/public/cities/kolkata/index.html b/website/public/cities/kolkata/index.html index d848dbc3..bf766a86 100644 --- a/website/public/cities/kolkata/index.html +++ b/website/public/cities/kolkata/index.html @@ -358,7 +358,7 @@

Kolkata

-
0
+
0
Communities
@@ -427,7 +427,7 @@

Communities

-
+
@@ -484,6 +484,7 @@

Kolkata Data Coming Soon

+ diff --git a/website/public/cities/mumbai/index.html b/website/public/cities/mumbai/index.html index c349f396..289c6423 100644 --- a/website/public/cities/mumbai/index.html +++ b/website/public/cities/mumbai/index.html @@ -358,7 +358,7 @@

Mumbai

-
0
+
0
Communities
@@ -449,7 +449,7 @@

Communities

-
+
@@ -507,6 +507,7 @@

More Mumbai Data Coming Soon

+ diff --git a/website/public/cities/pune/index.html b/website/public/cities/pune/index.html index 0aa45379..9a9aacc3 100644 --- a/website/public/cities/pune/index.html +++ b/website/public/cities/pune/index.html @@ -358,7 +358,7 @@

Pune

-
0
+
0
Communities
@@ -427,7 +427,7 @@

Communities

-
+
@@ -484,6 +484,7 @@

Pune Data Coming Soon

+ diff --git a/website/public/cities/thane/index.html b/website/public/cities/thane/index.html index bc56de73..07883004 100644 --- a/website/public/cities/thane/index.html +++ b/website/public/cities/thane/index.html @@ -358,7 +358,7 @@

Thane

-
0
+
0
Communities
@@ -427,7 +427,7 @@

Communities

-
+
@@ -484,6 +484,7 @@

Thane Data Coming Soon

+ diff --git a/website/public/cities/visakhapatnam/index.html b/website/public/cities/visakhapatnam/index.html index e8dcf82b..291ab334 100644 --- a/website/public/cities/visakhapatnam/index.html +++ b/website/public/cities/visakhapatnam/index.html @@ -358,7 +358,7 @@

Visakhapatnam

-
0
+
0
Communities
@@ -427,7 +427,7 @@

Communities

-
+
@@ -484,6 +484,7 @@

Visakhapatnam Data Coming Soon +