Skip to content

Commit f8da28e

Browse files
committed
Default non-production hosts to test environment theming
1 parent 719ec78 commit f8da28e

4 files changed

Lines changed: 20 additions & 18 deletions

File tree

src/components/MapView.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,11 @@ import { getPathLossByModel } from "../lib/rfModels";
1212
import { sampleSrtmElevation } from "../lib/srtm";
1313
import { estimateTerrainExcessLossDb } from "../lib/terrainLoss";
1414
import { useSystemTheme } from "../hooks/useSystemTheme";
15+
import { isCurrentTestEnvironment } from "../lib/environment";
1516
import { useAppStore } from "../store/appStore";
1617
import type { Link, Site } from "../types/radio";
1718

18-
const isStagingHost = (() => {
19-
if (typeof window === "undefined") return false;
20-
const host = window.location.hostname.toLowerCase();
21-
return host.startsWith("staging.") || host.endsWith(".linksim-staging.pages.dev");
22-
})();
23-
24-
const mapLinkColor = isStagingHost ? "#ff73b4" : "#00c2ff";
19+
const mapLinkColor = isCurrentTestEnvironment() ? "#ff73b4" : "#00c2ff";
2520

2621
const mapLineLayer: LayerProps = {
2722
id: "link-lines",

src/components/Sidebar.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { fetchElevations } from "../lib/elevationService";
1616
import { FREQUENCY_PRESETS } from "../lib/frequencyPlans";
1717
import { searchLocations, type GeocodeResult } from "../lib/geocode";
1818
import { LEGACY_ASSETS } from "../lib/legacyAssets";
19+
import { isCurrentTestEnvironment } from "../lib/environment";
1920
import {
2021
fetchCollaboratorDirectory,
2122
fetchResourceChanges,
@@ -86,12 +87,6 @@ const styleByTheme = {
8687
dark: "https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json",
8788
};
8889

89-
const isStagingHost = (() => {
90-
if (typeof window === "undefined") return false;
91-
const host = window.location.hostname.toLowerCase();
92-
return host.startsWith("staging.") || host.endsWith(".linksim-staging.pages.dev");
93-
})();
94-
9590
const RADIO_CLIMATE_OPTIONS: RadioClimate[] = [
9691
"Equatorial",
9792
"Continental Subtropical",
@@ -107,7 +102,7 @@ const meshmapNodesLayer: LayerProps = {
107102
type: "circle",
108103
paint: {
109104
"circle-radius": ["interpolate", ["linear"], ["zoom"], 4, 2, 8, 4, 12, 6],
110-
"circle-color": isStagingHost ? "#ff73b4" : "#2bc0ff",
105+
"circle-color": isCurrentTestEnvironment() ? "#ff73b4" : "#2bc0ff",
111106
"circle-opacity": 0.82,
112107
"circle-stroke-width": 1,
113108
"circle-stroke-color": "#0a1a24",
@@ -126,7 +121,7 @@ const meshmapLabelsLayer: LayerProps = {
126121
"text-allow-overlap": false,
127122
},
128123
paint: {
129-
"text-color": isStagingHost ? "#ffd6e8" : "#e7f1ff",
124+
"text-color": isCurrentTestEnvironment() ? "#ffd6e8" : "#e7f1ff",
130125
"text-halo-color": "rgba(10, 26, 36, 0.95)",
131126
"text-halo-width": 1.3,
132127
},

src/lib/environment.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const PROD_HOSTS = new Set(["linksim.wilhelmfrancke.com", "linksim.pages.dev"]);
2+
3+
const normalizeHost = (host: string): string => host.trim().toLowerCase();
4+
5+
export const isProductionHostname = (hostname: string): boolean => PROD_HOSTS.has(normalizeHost(hostname));
6+
7+
export const isTestEnvironmentHostname = (hostname: string): boolean => !isProductionHostname(hostname);
8+
9+
export const isCurrentTestEnvironment = (): boolean => {
10+
if (typeof window === "undefined") return false;
11+
return isTestEnvironmentHostname(window.location.hostname);
12+
};
13+

src/main.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createRoot } from "react-dom/client";
33
import "maplibre-gl/dist/maplibre-gl.css";
44
import "./index.css";
55
import App from "./App";
6+
import { isCurrentTestEnvironment } from "./lib/environment";
67

78
if (window.location.hostname === "127.0.0.1") {
89
const redirectUrl =
@@ -12,9 +13,7 @@ if (window.location.hostname === "127.0.0.1") {
1213
window.location.replace(redirectUrl);
1314
}
1415

15-
const host = window.location.hostname.toLowerCase();
16-
const isStagingHost = host.startsWith("staging.") || host.endsWith(".linksim-staging.pages.dev");
17-
if (isStagingHost) {
16+
if (isCurrentTestEnvironment()) {
1817
document.documentElement.classList.add("env-staging");
1918
}
2019

0 commit comments

Comments
 (0)