@codecademy/brand 3.36.2-alpha.114f8c1aad.0 → 3.36.2-alpha.7b9e1afbb4.0
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.
|
@@ -102,11 +102,7 @@ export function serializeSearchWorkerSrc() {
|
|
|
102
102
|
* the worker via onmessage and passed back to the main thread via postMessage.
|
|
103
103
|
*/
|
|
104
104
|
function worker() {
|
|
105
|
-
const preloadTitlesPromise = (
|
|
106
|
-
const f = await fetch('{BASE_URL}/autocomplete-preload{SEARCH}');
|
|
107
|
-
const rawTitles = await f.json();
|
|
108
|
-
return rawTitles.map(preparseTitle);
|
|
109
|
-
})();
|
|
105
|
+
const preloadTitlesPromise = fetch('{BASE_URL}/autocomplete-preload{SEARCH}').then(f => f.json()).then(rawTitles => rawTitles.map(preparseTitle));
|
|
110
106
|
function preparseTitle({
|
|
111
107
|
value,
|
|
112
108
|
popularity
|
|
@@ -158,41 +154,42 @@ function worker() {
|
|
|
158
154
|
};
|
|
159
155
|
}
|
|
160
156
|
const maxResults = 5;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
157
|
+
function autocompleteHandler(q) {
|
|
158
|
+
preloadTitlesPromise.then(titles => {
|
|
159
|
+
const scoredTitles = titles.map(t => getScoredTitle(q, t));
|
|
160
|
+
const topAutocompleteTitles = scoredTitles.filter(x => x.score > 0).sort((a, b) => a.score > b.score ? -1 : 1).slice(0, maxResults).map(t => ({
|
|
161
|
+
title: t.title,
|
|
162
|
+
segments: getHighlightSegments(t.title, t.charScores)
|
|
163
|
+
}));
|
|
164
|
+
postMessage({
|
|
165
|
+
query: q.query,
|
|
166
|
+
result: topAutocompleteTitles,
|
|
167
|
+
action: 'autocomplete'
|
|
168
|
+
});
|
|
172
169
|
});
|
|
173
170
|
}
|
|
174
|
-
|
|
175
|
-
|
|
171
|
+
function searchAsYouTypeHandler(q) {
|
|
172
|
+
fetch('{BASE_URL}/search-as-you-type{SEARCH}', {
|
|
176
173
|
body: JSON.stringify({
|
|
177
174
|
query: q.query,
|
|
178
175
|
max: maxResults
|
|
179
176
|
}),
|
|
180
177
|
method: 'POST'
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
178
|
+
}).then(f => f.json()).then(searchAsYouTypeResults => {
|
|
179
|
+
for (const entry of searchAsYouTypeResults.top) {
|
|
180
|
+
const t = preparseTitle({
|
|
181
|
+
value: entry.title,
|
|
182
|
+
popularity: 0
|
|
183
|
+
});
|
|
184
|
+
const charScores = getCharScores(q, t);
|
|
185
|
+
entry.segments = getHighlightSegments(entry.title, charScores);
|
|
186
|
+
entry.key = q.query + ':' + entry.title;
|
|
187
|
+
}
|
|
188
|
+
postMessage({
|
|
189
|
+
query: q.query,
|
|
190
|
+
result: searchAsYouTypeResults,
|
|
191
|
+
action: 'search-as-you-type'
|
|
187
192
|
});
|
|
188
|
-
const charScores = getCharScores(q, t);
|
|
189
|
-
entry.segments = getHighlightSegments(entry.title, charScores);
|
|
190
|
-
entry.key = q.query + ':' + entry.title;
|
|
191
|
-
}
|
|
192
|
-
postMessage({
|
|
193
|
-
query: q.query,
|
|
194
|
-
result: searchAsYouTypeResults,
|
|
195
|
-
action: 'search-as-you-type'
|
|
196
193
|
});
|
|
197
194
|
}
|
|
198
195
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codecademy/brand",
|
|
3
3
|
"description": "Brand component library for Codecademy",
|
|
4
|
-
"version": "3.36.2-alpha.
|
|
4
|
+
"version": "3.36.2-alpha.7b9e1afbb4.0",
|
|
5
5
|
"author": "Codecademy Engineering <dev@codecademy.com>",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@emotion/is-prop-valid": "^1.2.1",
|