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 +