Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/shared/components/Contentful/SearchBar/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,13 @@ export class SearchBarInner extends Component {
* Update suggestion list with new search text
* This function use debounce delay to avoid processing or requesting too much
*
* @param {String} searchText Search text
* @param {String} searchTerm Search text
*/
updateSuggestionListWithNewSearch(searchText) {
updateSuggestionListWithNewSearch(searchTerm) {
const {
selectedFilter,
} = this.state;
const searchText = searchTerm ? encodeURIComponent(searchTerm) : '';

if (searchText) {
const query = {
Expand Down Expand Up @@ -499,6 +500,7 @@ export class SearchBarInner extends Component {
<IconSearch className={theme['icon-search']} />
<input
value={inputlVal}
maxLength={115}
ref={this.setSearchFieldRef}
type="text"
placeholder="Search..."
Expand Down
31 changes: 31 additions & 0 deletions src/shared/containers/EDU/Tracks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ export default class EDUTracks extends React.Component {
? urlQuery.tags : (urlQuery.tags ? [urlQuery.tags] : []);
if (urlQuery.startDate) urlQuery.startDate = moment(urlQuery.startDate).format();
if (urlQuery.endDate) urlQuery.endDate = moment(urlQuery.endDate).format();
// validate track string in URL query
// set CP if missing or wrong
const tracks = _.keys(TRACK_BANNER_BACK_COLORS);
if (!urlQuery.track || _.indexOf(tracks, urlQuery.track) === -1) {
urlQuery.track = 'Competitive Programming';
updateQuery({
...query,
...urlQuery,
});
}
this.setState({
query: {
...query,
Expand All @@ -96,6 +106,27 @@ export default class EDUTracks extends React.Component {
// Get the EDU taxonomy
this.apiService.getEDUTaxonomy()
.then((taxonomy) => {
if (urlQuery.tax) {
// check if tax exists or is wrong
const foundSome = _.some(
_.flatten(
_.values(taxonomy),
), cat => cat.name.toLowerCase() === urlQuery.tax.toLowerCase(),
);
if (!foundSome) {
delete urlQuery.tax;
updateQuery({
...query,
...urlQuery,
});
this.setState({
query: {
...query,
...urlQuery,
},
});
}
}
const tree = tracksTreeBuilder(taxonomy, urlQuery);
this.setState({
tree,
Expand Down
16 changes: 7 additions & 9 deletions src/shared/services/contentful.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,10 @@ class Service {
// thus we need to find it first
await this.queryEntries({
content_type: 'person',
query: author,
query: encodeURIComponent(author),
})
.then((result) => {
if (result.total) {
query['fields.contentAuthor.sys.id'] = result.items[0].sys.id;
}
query['fields.contentAuthor.sys.id'] = result.total ? result.items[0].sys.id : 'NO_SUCH_ID';
});
}
if (tax && track && taxonomy && taxonomy[track]) {
Expand All @@ -335,19 +333,19 @@ class Service {
}
});
} else {
const taxId = _.find(taxonomy[track], ['name', tax]).id;
taxIDs.push(taxId);
const taxId = _.find(taxonomy[track], ['name', tax]);
if (taxId) taxIDs.push(taxId.id);
}
if (taxIDs.length) query['fields.contentCategory.sys.id[in]'] = taxIDs.join(',');
}
if (track) query['fields.trackCategory'] = track;
if (!_.isEmpty(tags)) {
query['fields.tags[all]'] = tags.join(',');
query['fields.tags[all]'] = tags.map(t => encodeURIComponent(t)).join(',');
}
if (startDate) query['fields.creationDate[gte]'] = startDate;
if (endDate) query['fields.creationDate[lte]'] = endDate;
if (phrase) query.query = phrase;
if (title) query['fields.title[match]'] = title;
if (phrase) query.query = encodeURIComponent(phrase);
if (title) query['fields.title[match]'] = encodeURIComponent(title);
if (sortBy) {
switch (sortBy) {
case 'Likes': query.order = '-fields.upvotes,-fields.creationDate'; break;
Expand Down