sfc-utils 1.4.73 → 1.4.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/geocoder.mjs +92 -96
- package/nav2.js +4 -11
- package/package.json +2 -2
package/components/geocoder.mjs
CHANGED
|
@@ -57,7 +57,7 @@ const Geocoder = ({
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// We don't want this CONSTANTLY firing, so we debounce it
|
|
60
|
-
const search = (query) => {
|
|
60
|
+
const search = async (query) => {
|
|
61
61
|
// Save value of query so we can check if it's the last one
|
|
62
62
|
latestFetchRef.current = query;
|
|
63
63
|
// If we're already loading, don't fire another request, the request will be re-requested after the first one finishes
|
|
@@ -72,104 +72,100 @@ const Geocoder = ({
|
|
|
72
72
|
}
|
|
73
73
|
// Remove any existing event listeners
|
|
74
74
|
setSingletonEventListener("keydown");
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (resultFunc) {
|
|
152
|
-
resultFunc(selectedLocation);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
// Hide the list now
|
|
156
|
-
setLocData(null);
|
|
75
|
+
// Wait for a sec to check if we're still typing
|
|
76
|
+
await new Promise((resolve) => setTimeout(resolve, 500)); // We can increase this timeout to ease up on requests too
|
|
77
|
+
// If query doesn't match, we're still typing -- reset
|
|
78
|
+
if (latestFetchRef.current !== query) {
|
|
79
|
+
search(latestFetchRef.current);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// We've settled, make the req
|
|
83
|
+
const resp = await fetch(
|
|
84
|
+
"https://projects.sfchronicle.com/feeds/geocode/v2-test.php",
|
|
85
|
+
{
|
|
86
|
+
method: "POST",
|
|
87
|
+
body: formData,
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
if (!resp || !resp.ok) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const output = await resp.json();
|
|
94
|
+
// If this is not the latest fetch after we finished getting results, bail and fetch latest
|
|
95
|
+
if (latestFetchRef.current !== query) {
|
|
96
|
+
search(latestFetchRef.current);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
// Unset loading
|
|
100
|
+
setLoading(false);
|
|
101
|
+
// Remove any existing event listeners
|
|
102
|
+
setSingletonEventListener("keydown");
|
|
103
|
+
// Show results
|
|
104
|
+
setLocData(output.data);
|
|
105
|
+
// Bail early if there's no data
|
|
106
|
+
if (!output) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
if (output.data.length === 0) {
|
|
110
|
+
// We could show something saying "No results" ... or we could not
|
|
111
|
+
if (output.fallback) {
|
|
112
|
+
// If we're using the fallback, we need to encourage the user to enter city
|
|
113
|
+
setLocData([{ name: "No results, make sure to include city name" }]);
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
// Create a keydown event listener
|
|
117
|
+
setSingletonEventListener("keydown", function resultsKeyHandler(e) {
|
|
118
|
+
setActiveKeyboardIndex((prevIndex) => {
|
|
119
|
+
let newIndex = prevIndex;
|
|
120
|
+
switch (e.key) {
|
|
121
|
+
case "ArrowDown":
|
|
122
|
+
// Handle the index
|
|
123
|
+
if (prevIndex === null) {
|
|
124
|
+
newIndex = 0;
|
|
125
|
+
} else if (prevIndex < output.data.length - 1) {
|
|
126
|
+
newIndex = prevIndex + 1;
|
|
127
|
+
} else {
|
|
128
|
+
newIndex = 0;
|
|
129
|
+
}
|
|
130
|
+
break;
|
|
131
|
+
case "ArrowUp":
|
|
132
|
+
// Handle the index
|
|
133
|
+
if (prevIndex === null) {
|
|
134
|
+
newIndex = output.data.length - 1;
|
|
135
|
+
} else if (prevIndex > 0) {
|
|
136
|
+
newIndex = prevIndex - 1;
|
|
137
|
+
} else {
|
|
138
|
+
newIndex = output.data.length - 1;
|
|
139
|
+
}
|
|
140
|
+
break;
|
|
141
|
+
case "Enter":
|
|
142
|
+
// Do something with the data
|
|
143
|
+
const selectedLocation = output.data[prevIndex];
|
|
144
|
+
// Update the input value with the choice
|
|
145
|
+
if (selectedLocation) {
|
|
146
|
+
setInputValue(selectedLocation.name);
|
|
147
|
+
// Call function if it exists
|
|
148
|
+
if (resultFunc) {
|
|
149
|
+
resultFunc(selectedLocation);
|
|
150
|
+
}
|
|
157
151
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
152
|
+
// Hide the list now
|
|
153
|
+
setLocData(null);
|
|
154
|
+
}
|
|
155
|
+
return newIndex;
|
|
156
|
+
});
|
|
157
|
+
});
|
|
161
158
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
});
|
|
171
|
-
}
|
|
159
|
+
// Start listening for a click outside the div
|
|
160
|
+
document.addEventListener("click", function resultsClickHandler(e) {
|
|
161
|
+
// Whether we clicked inside or outside, we hide the list
|
|
162
|
+
setLocData(null);
|
|
163
|
+
// Also cancel the keydown listener
|
|
164
|
+
setSingletonEventListener("keydown");
|
|
165
|
+
// Received click, cancel this listener
|
|
166
|
+
this.removeEventListener("click", resultsClickHandler);
|
|
172
167
|
});
|
|
168
|
+
}
|
|
173
169
|
};
|
|
174
170
|
|
|
175
171
|
// Handle the change event
|
package/nav2.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
let { getBrands } = require("./brands");
|
|
2
2
|
|
|
3
3
|
// Handle nav for various markets and include nav options for other links
|
|
4
|
-
let getNav2 = function (
|
|
5
|
-
meta,
|
|
6
|
-
urlAdd,
|
|
7
|
-
forceColor,
|
|
8
|
-
navLink,
|
|
9
|
-
navArray
|
|
10
|
-
) {
|
|
4
|
+
let getNav2 = function (meta, urlAdd, forceColor, navLink, navArray) {
|
|
11
5
|
// If we aren't passing meta in, we have to call getSettings here
|
|
12
6
|
if (!meta) {
|
|
13
7
|
let { getSettings } = require("./settings");
|
|
@@ -141,7 +135,7 @@ let getNav2 = function (
|
|
|
141
135
|
>
|
|
142
136
|
${navLink.text}${dropdownIcon}
|
|
143
137
|
</a>
|
|
144
|
-
|
|
138
|
+
`;
|
|
145
139
|
}
|
|
146
140
|
|
|
147
141
|
let rightBlock = `
|
|
@@ -149,7 +143,6 @@ let getNav2 = function (
|
|
|
149
143
|
<div>Subscribe</div>
|
|
150
144
|
</a>
|
|
151
145
|
`;
|
|
152
|
-
|
|
153
146
|
|
|
154
147
|
let navHTML = `<nav class="nav2-container ${invertClass}">
|
|
155
148
|
<div class="nav2-left">
|
|
@@ -166,12 +159,12 @@ let getNav2 = function (
|
|
|
166
159
|
class="nav2-desk-logo"
|
|
167
160
|
alt="Logo"
|
|
168
161
|
src="https://files.sfchronicle.com/static-assets/logos/${marketPrefix}-${color}.png"
|
|
169
|
-
|
|
162
|
+
/>
|
|
170
163
|
<img
|
|
171
164
|
class="nav2-mobile-logo"
|
|
172
165
|
alt="Logo"
|
|
173
166
|
src="https://files.sfchronicle.com/static-assets/logos/${marketPrefix}-square-${color}.png"
|
|
174
|
-
|
|
167
|
+
/>
|
|
175
168
|
</div>
|
|
176
169
|
</a>
|
|
177
170
|
</div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sfc-utils",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.75",
|
|
4
4
|
"author": "ewagstaff <evanjwagstaff@gmail.com>",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"archieml": "^0.4.2",
|
|
@@ -14,4 +14,4 @@
|
|
|
14
14
|
"react-transition-group": "^4.4.5",
|
|
15
15
|
"write": "^2.0.0"
|
|
16
16
|
}
|
|
17
|
-
}
|
|
17
|
+
}
|