Skip to content

Commit 7b196f2

Browse files
Merge pull request #5756 from topcoder-platform/thrive-spooky1-p0
Thrive spooky1 p0
2 parents 07934d1 + 18baf14 commit 7b196f2

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

src/shared/components/Contentful/SearchBar/SearchBar.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,13 @@ export class SearchBarInner extends Component {
379379
* Update suggestion list with new search text
380380
* This function use debounce delay to avoid processing or requesting too much
381381
*
382-
* @param {String} searchText Search text
382+
* @param {String} searchTerm Search text
383383
*/
384-
updateSuggestionListWithNewSearch(searchText) {
384+
updateSuggestionListWithNewSearch(searchTerm) {
385385
const {
386386
selectedFilter,
387387
} = this.state;
388+
const searchText = searchTerm ? encodeURIComponent(searchTerm) : '';
388389

389390
if (searchText) {
390391
const query = {
@@ -499,6 +500,7 @@ export class SearchBarInner extends Component {
499500
<IconSearch className={theme['icon-search']} />
500501
<input
501502
value={inputlVal}
503+
maxLength={115}
502504
ref={this.setSearchFieldRef}
503505
type="text"
504506
placeholder="Search..."

src/shared/containers/EDU/Tracks.jsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ export default class EDUTracks extends React.Component {
8484
? urlQuery.tags : (urlQuery.tags ? [urlQuery.tags] : []);
8585
if (urlQuery.startDate) urlQuery.startDate = moment(urlQuery.startDate).format();
8686
if (urlQuery.endDate) urlQuery.endDate = moment(urlQuery.endDate).format();
87+
// validate track string in URL query
88+
// set CP if missing or wrong
89+
const tracks = _.keys(TRACK_BANNER_BACK_COLORS);
90+
if (!urlQuery.track || _.indexOf(tracks, urlQuery.track) === -1) {
91+
urlQuery.track = 'Competitive Programming';
92+
updateQuery({
93+
...query,
94+
...urlQuery,
95+
});
96+
}
8797
this.setState({
8898
query: {
8999
...query,
@@ -96,6 +106,27 @@ export default class EDUTracks extends React.Component {
96106
// Get the EDU taxonomy
97107
this.apiService.getEDUTaxonomy()
98108
.then((taxonomy) => {
109+
if (urlQuery.tax) {
110+
// check if tax exists or is wrong
111+
const foundSome = _.some(
112+
_.flatten(
113+
_.values(taxonomy),
114+
), cat => cat.name.toLowerCase() === urlQuery.tax.toLowerCase(),
115+
);
116+
if (!foundSome) {
117+
delete urlQuery.tax;
118+
updateQuery({
119+
...query,
120+
...urlQuery,
121+
});
122+
this.setState({
123+
query: {
124+
...query,
125+
...urlQuery,
126+
},
127+
});
128+
}
129+
}
99130
const tree = tracksTreeBuilder(taxonomy, urlQuery);
100131
this.setState({
101132
tree,

src/shared/services/contentful.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,10 @@ class Service {
316316
// thus we need to find it first
317317
await this.queryEntries({
318318
content_type: 'person',
319-
query: author,
319+
query: encodeURIComponent(author),
320320
})
321321
.then((result) => {
322-
if (result.total) {
323-
query['fields.contentAuthor.sys.id'] = result.items[0].sys.id;
324-
}
322+
query['fields.contentAuthor.sys.id'] = result.total ? result.items[0].sys.id : 'NO_SUCH_ID';
325323
});
326324
}
327325
if (tax && track && taxonomy && taxonomy[track]) {
@@ -335,19 +333,19 @@ class Service {
335333
}
336334
});
337335
} else {
338-
const taxId = _.find(taxonomy[track], ['name', tax]).id;
339-
taxIDs.push(taxId);
336+
const taxId = _.find(taxonomy[track], ['name', tax]);
337+
if (taxId) taxIDs.push(taxId.id);
340338
}
341339
if (taxIDs.length) query['fields.contentCategory.sys.id[in]'] = taxIDs.join(',');
342340
}
343341
if (track) query['fields.trackCategory'] = track;
344342
if (!_.isEmpty(tags)) {
345-
query['fields.tags[all]'] = tags.join(',');
343+
query['fields.tags[all]'] = tags.map(t => encodeURIComponent(t)).join(',');
346344
}
347345
if (startDate) query['fields.creationDate[gte]'] = startDate;
348346
if (endDate) query['fields.creationDate[lte]'] = endDate;
349-
if (phrase) query.query = phrase;
350-
if (title) query['fields.title[match]'] = title;
347+
if (phrase) query.query = encodeURIComponent(phrase);
348+
if (title) query['fields.title[match]'] = encodeURIComponent(title);
351349
if (sortBy) {
352350
switch (sortBy) {
353351
case 'Likes': query.order = '-fields.upvotes,-fields.creationDate'; break;

0 commit comments

Comments
 (0)