Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 1x 6x 6x 12x 6x 9x 9x 9x 9x 6x 8x 11x 3x 6x | /**
* Rows for the `/interiors` city index. Depth is printed as it is: the
* designer count the API gives, "so far" while a city is thin, and a rate
* only where the city has approved prices and a published cost table.
*/
import { HYDERABAD_DEFAULT_COSTS } from "../content/costs";
import { HYDERABAD_FALLBACK, liveCities, type PublicCity } from "./live-directory";
/** Below this many published designers a city reads "so far", not as a full directory. */
export const THIN_CITY_PROS = 5;
export type CityIndexRow = {
slug: string;
name: string;
state?: string;
/** null when the API failed and the count is unknown. */
designers: string | null;
cost: string | null;
};
export function cityIndex(cities: PublicCity[]): {
rows: CityIndexRow[];
/** Listed cities with no published designer yet, for the recruiting block. */
unstaffed: string[];
} {
// The fallback's count of 0 is a placeholder, not a fact: print no count.
const countsKnown = !(cities.length === 1 && cities[0] === HYDERABAD_FALLBACK);
const live = liveCities(cities);
const twoBhk = HYDERABAD_DEFAULT_COSTS.find((r) => r.type === "2BHK");
const rows = live.map((city) => {
const n = city.publishedProCount ?? 0;
const designers = !countsKnown
? null
: n === 0
? "No designers yet"
: `${n} ${n === 1 ? "designer" : "designers"}${n < THIN_CITY_PROS ? " so far" : ""}`;
// Only Hyderabad has a published cost table (lib/content/costs.ts).
const cost =
city.pricesApproved && city.id === "hyderabad" && twoBhk
? `2BHK typically ${twoBhk.range}`
: city.pricesApproved
? null
: "No local costs yet";
return { slug: city.slug, name: city.publicName, state: city.state, designers, cost };
});
const unstaffed = [
...(countsKnown ? live.filter((c) => (c.publishedProCount ?? 0) === 0) : []),
...cities.filter((c) => c.marketplaceStatus !== "live"),
].map((c) => c.publicName);
return { rows, unstaffed };
}
|