Skip to content

Commit 1517626

Browse files
committed
Fixed window width binding
1 parent 7b91db7 commit 1517626

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

public/global.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ body {
1010
/* padding: 8px; */
1111
box-sizing: border-box;
1212
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
13+
overflow: hidden;
1314
}
1415

1516
a {

src/components/ContactBox.svelte

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
<script>
22
export let vizState;
3+
4+
let windowWidth;
35
</script>
46

7+
<svelte:window bind:innerWidth={windowWidth} />
8+
59
<div
6-
style="display: {vizState === 'running' && window.innerWidth > 700
10+
style="display: {vizState === 'running' && windowWidth > 700
711
? 'none'
812
: 'block'};"
913
class={"contact-box"}
1014
>
11-
{#if window.innerWidth > 700}
15+
{#if windowWidth > 700}
1216
<p>
1317
<strong
1418
>Visualization by <a

src/components/Map.svelte

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
getFlowrateData,
4848
} from "./utils/mapUtils";
4949
50+
import config from "../config.json";
51+
5052
export let bounds;
5153
export let stateBoundaries;
5254
export let activeNWISSites;
@@ -64,7 +66,8 @@
6466
? { lngLat: { lat: +urlParams.get("lat"), lng: +urlParams.get("lng") } }
6567
: null;
6668
67-
const mobileBreakpoint = 700;
69+
const mobileBreakpoint = config.mobile_breakpoint;
70+
let windowWidth;
6871
6972
let container;
7073
let map;
@@ -88,8 +91,7 @@
8891
let phaseJump;
8992
9093
// Zoom level won't be adjustable on mobile, but it will be set slightly higher to avoid jiterriness
91-
const defaultAltitudeMultiplier =
92-
window.innerWidth < mobileBreakpoint ? 1.1 : 0.9;
94+
const defaultAltitudeMultiplier = windowWidth < mobileBreakpoint ? 1.1 : 0.9;
9395
let altitudeMultiplier = defaultAltitudeMultiplier;
9496
let altitudeChange = false;
9597
let paused = false;
@@ -119,8 +121,8 @@
119121
container,
120122
style: mapStyle || "mapbox://styles/mapbox/light-v10",
121123
center: [0, 0],
122-
minZoom: window.innerWidth > mobileBreakpoint ? 2 : 1.4,
123-
zoom: window.innerWidth > mobileBreakpoint ? 2.001 : 1.4001,
124+
minZoom: windowWidth > mobileBreakpoint ? 2 : 1.4,
125+
zoom: windowWidth > mobileBreakpoint ? 2.001 : 1.4001,
124126
projection: "globe",
125127
});
126128
@@ -158,7 +160,7 @@
158160
showCompass: true,
159161
visualizePitch: true,
160162
});
161-
// if (window.innerWidth > mobileBreakpoint) {
163+
// if (windowWidth > mobileBreakpoint) {
162164
map.addControl(nav, "top-left");
163165
// }
164166
@@ -195,7 +197,7 @@
195197
flyTo: false,
196198
});
197199
198-
if (window.innerWidth < mobileBreakpoint) {
200+
if (windowWidth < mobileBreakpoint) {
199201
geocoderControl.setLimit(4);
200202
}
201203
@@ -211,7 +213,7 @@
211213
});
212214
213215
const position =
214-
window.innerWidth > mobileBreakpoint ? "top-right" : "bottom-left";
216+
windowWidth > mobileBreakpoint ? "top-right" : "bottom-left";
215217
map.addControl(geocoderControl, position);
216218
217219
return geocoderControl;
@@ -439,7 +441,7 @@
439441
440442
// When using the vizState change/return instead of startRun, it displays the overview before automatically starting the run
441443
// We'll do this with a countdown timer on desktop, and just right into it on mobile
442-
if (window.innerWidth > mobileBreakpoint) {
444+
if (windowWidth > mobileBreakpoint) {
443445
vizState = "overview";
444446
// map.scrollZoom.enable();
445447
// map.dragPan.enable();
@@ -1042,7 +1044,7 @@
10421044
pitch: 0,
10431045
padding: 70,
10441046
maxZoom: 12,
1045-
offset: window.innerWidth < mobileBreakpoint ? [0, -20] : [0, 0], // On mobile, the search bar will get in the way so we actually want it a little off center
1047+
offset: windowWidth < mobileBreakpoint ? [0, -20] : [0, 0], // On mobile, the search bar will get in the way so we actually want it a little off center
10461048
});
10471049
10481050
map.once("moveend", () => {
@@ -1193,7 +1195,7 @@
11931195
// });
11941196
</script>
11951197

1196-
<svelte:window on:keydown={handleKeydown} />
1198+
<svelte:window on:keydown={handleKeydown} bind:innerWidth={windowWidth} />
11971199

11981200
<div
11991201
class="map-wrapper"
@@ -1230,7 +1232,7 @@
12301232
{suggestionModalActive}
12311233
on:hide-suggestion-modal={hideSuggestionModal}
12321234
/>
1233-
{#if window.innerWidth > mobileBreakpoint && advancedFeaturesOn === true}
1235+
{#if windowWidth > mobileBreakpoint && advancedFeaturesOn === true}
12341236
<WaterLevelDisplay
12351237
{currentFlowrate}
12361238
{maxFlowrate}

src/components/Prompt.svelte

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
export let errorStatus;
1010
export let bannerVisible;
1111
12+
let windowWidth;
13+
1214
let loading = false;
1315
let eventActionName =
14-
window.innerWidth > config.mobile_breakpoint ? "Click" : "Tap";
16+
windowWidth > config.mobile_breakpoint ? "Click" : "Tap";
1517
let message = `${eventActionName} to drop a raindrop anywhere in the world and watch where it ends up`;
1618
1719
$: if (currentLocation?.lat && message !== "") {
@@ -23,7 +25,7 @@
2325
loading = false;
2426
} else if (vizState === "overview") {
2527
message =
26-
window.innerWidth > config.mobile_breakpoint
28+
windowWidth > config.mobile_breakpoint
2729
? ""
2830
: "Run the path again, copy a link to share, or exit and try another path using the buttons below.";
2931
loading = false;
@@ -90,6 +92,8 @@
9092
};
9193
</script>
9294
95+
<svelte:window bind:innerWidth={windowWidth} />
96+
9397
<div
9498
class="wrapper"
9599
style="display: {bannerVisible ? 'none' : 'block'};"
@@ -109,7 +113,7 @@
109113
<div
110114
style="display:{vizState === 'uninitialized' &&
111115
loading === false &&
112-
window.innerWidth > config.mobile_breakpoint
116+
windowWidth > config.mobile_breakpoint
113117
? 'block'
114118
: 'none'};"
115119
class="scroll-helper"

0 commit comments

Comments
 (0)