diff --git a/src/shared/components/Contentful/SearchBar/SearchBar.jsx b/src/shared/components/Contentful/SearchBar/SearchBar.jsx
index 3fe97914e3..ab0abb9e09 100644
--- a/src/shared/components/Contentful/SearchBar/SearchBar.jsx
+++ b/src/shared/components/Contentful/SearchBar/SearchBar.jsx
@@ -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 = {
@@ -499,6 +500,7 @@ export class SearchBarInner extends Component {
{
+ 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,
diff --git a/src/shared/services/contentful.js b/src/shared/services/contentful.js
index ded9dacaf7..81b7dd1e1c 100644
--- a/src/shared/services/contentful.js
+++ b/src/shared/services/contentful.js
@@ -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]) {
@@ -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;