Skip to content

Commit e621e5f

Browse files
fix(tools): enable type checking for the client (freeCodeCamp#58579)
1 parent 0f2fdf3 commit e621e5f

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

client/src/components/search/with-instant-search.tsx

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Location } from '@reach/router';
22
import type { WindowLocation } from '@reach/router';
33
import type { SearchOptions } from 'instantsearch.js';
4-
import algoliasearch from 'algoliasearch/lite';
4+
import algoliasearch, { type SearchClient } from 'algoliasearch/lite';
55
import React, { useEffect, useRef } from 'react';
66
import type { ReactNode } from 'react';
77
import { connect } from 'react-redux';
@@ -18,31 +18,32 @@ import {
1818
updateSearchQuery
1919
} from './redux';
2020

21+
const mockSearchClient = {
22+
// When Algolia is not configured, the client will still render,
23+
// the result query is returned to the search component as a mock
24+
//(mainly for testing without relying on Playwright fuffill route as
25+
// there is no request made without a key).
26+
search: (request: Array<{ indexName: string; params: SearchOptions }>) => {
27+
return Promise.resolve({
28+
results: [
29+
{
30+
hits: [],
31+
query: request[0].params?.query === 'test' ? 'test' : '',
32+
params:
33+
'highlightPostTag=__%2Fais-highlight__&highlightPreTag=__ais-highlight__&hitsPerPage=5&query=sdefpuhsdfpiouhdsfgp',
34+
index: 'news'
35+
}
36+
]
37+
});
38+
}
39+
// TODO: mock this in the tests.
40+
} as unknown as SearchClient;
41+
2142
// If a key is missing, searches will fail, but the client will still render.
2243
const searchClient =
2344
algoliaAppId && algoliaAPIKey
2445
? algoliasearch(algoliaAppId, algoliaAPIKey)
25-
: {
26-
// When Algolia is not configured, the client will still render,
27-
// the result query is returned to the search component as a mock
28-
//(mainly for testing without relying on Playwright fuffill route as
29-
// there is no request made without a key).
30-
search: (
31-
request: Array<{ indexName: string; params: SearchOptions }>
32-
) => {
33-
return Promise.resolve({
34-
results: [
35-
{
36-
hits: [],
37-
query: request[0].params?.query === 'test' ? 'test' : '',
38-
params:
39-
'highlightPostTag=__%2Fais-highlight__&highlightPreTag=__ais-highlight__&hitsPerPage=5&query=sdefpuhsdfpiouhdsfgp',
40-
index: 'news'
41-
}
42-
]
43-
});
44-
}
45-
};
46+
: mockSearchClient;
4647

4748
const mapStateToProps = createSelector(
4849
searchQuerySelector,

client/src/templates/Challenges/fill-in-the-blank/show.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ const ShowFillInTheBlank = ({
178178
};
179179

180180
const handlePlayScene = () => {
181-
sceneSubject.notify();
181+
sceneSubject.notify('play');
182182
};
183183

184184
const blockNameTitle = `${t(

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"lint": "NODE_OPTIONS=\"--max-old-space-size=7168\" npm-run-all create:shared -p lint:*",
5555
"lint:challenges": "cd ./curriculum && pnpm run lint",
5656
"lint:js": "eslint --cache --max-warnings 0 .",
57-
"lint:ts": "tsc && tsc -p shared && tsc -p api",
57+
"lint:ts": "tsc && tsc -p shared && tsc -p api && tsc -p client",
5858
"lint:prettier": "prettier --list-different .",
5959
"lint:css": "stylelint '**/*.css'",
6060
"reload:server": "pm2 reload api-server/ecosystem.config.js",

0 commit comments

Comments
 (0)