diff --git a/.circleci/config.yml b/.circleci/config.yml index 6180803b84..cd03e3288f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -260,7 +260,7 @@ workflows: filters: branches: only: - - develop + - feature-contentful # Production builds are exectuted # when PR is merged to the master # Don't change anything in this configuration diff --git a/src/shared/components/Contentful/Article/Article.jsx b/src/shared/components/Contentful/Article/Article.jsx index 150d213290..c9078713ea 100644 --- a/src/shared/components/Contentful/Article/Article.jsx +++ b/src/shared/components/Contentful/Article/Article.jsx @@ -15,7 +15,10 @@ import LoadingIndicator from 'components/LoadingIndicator'; import YouTubeVideo from 'components/YouTubeVideo'; import moment from 'moment'; import localStorage from 'localStorage'; -import { config, Link, isomorphy } from 'topcoder-react-utils'; +import { Helmet } from 'react-helmet'; +import { + config, Link, isomorphy, +} from 'topcoder-react-utils'; import qs from 'qs'; // SVGs and assets import GestureIcon from 'assets/images/icon-gesture.svg'; @@ -110,9 +113,27 @@ export default class Article extends React.Component { if (isomorphy.isClientSide()) { shareUrl = encodeURIComponent(window.location.href); } + const description = htmlToText.fromString( + ReactDOMServer.renderToString(markdown(fields.content)), + { + ignoreHref: true, + ignoreImage: true, + singleNewLineParagraphs: true, + uppercaseHeadings: false, + }, + ).substring(0, CONTENT_PREVIEW_LENGTH); return ( + + {fields.title} + + + + + + + {/* Banner */} { fields.featuredImage ? ( diff --git a/src/shared/components/Contentful/SearchBar/SearchBar.jsx b/src/shared/components/Contentful/SearchBar/SearchBar.jsx index 9444c56777..d23301d0ed 100644 --- a/src/shared/components/Contentful/SearchBar/SearchBar.jsx +++ b/src/shared/components/Contentful/SearchBar/SearchBar.jsx @@ -56,6 +56,7 @@ export class SearchBarInner extends Component { this.getSuggestionList = this.getSuggestionList.bind(this); this.handleSearchChange = this.handleSearchChange.bind(this); this.handleClickOutside = this.handleClickOutside.bind(this); + this.onKeyDown = this.onKeyDown.bind(this); // using debounce to avoid processing or requesting too much this.updateSuggestionListWithNewSearch = _.debounce( this.updateSuggestionListWithNewSearch.bind(this), 400, @@ -71,6 +72,29 @@ export class SearchBarInner extends Component { document.removeEventListener('mousedown', this.handleClickOutside); } + onKeyDown(e) { + const { inputlVal, selectedFilter } = this.state; + if (inputlVal && e.which === 13) { + const searchQuery = {}; + if (this.searchFieldRef && this.searchFieldRef.value) { + if (selectedFilter.name === 'Tags') { + searchQuery.tags = [this.searchFieldRef.value]; + } + if (selectedFilter.name === 'All') { + searchQuery.phrase = this.searchFieldRef.value; + } + if (selectedFilter.name === 'Title') { + searchQuery.title = this.searchFieldRef.value; + } + } + if (selectedFilter.name !== 'Author') { + window.location.href = `${config.TC_EDU_BASE_PATH}${config.TC_EDU_SEARCH_PATH}?${qs.stringify(searchQuery)}`; + } else { + window.location.href = `${config.TC_EDU_BASE_PATH}${config.TC_EDU_SEARCH_PATH}?author=${inputlVal}`; + } + } + } + /** * Set the search field ref */ @@ -136,6 +160,7 @@ export class SearchBarInner extends Component { isShowSuggestion, suggestionList, selectedFilter, + noResults, } = this.state; const searchQuery = {}; @@ -151,7 +176,8 @@ export class SearchBarInner extends Component { } } - return (suggestionList && !_.isEmpty(suggestionList) && isShowSuggestion && ( + // eslint-disable-next-line no-nested-ternary + return suggestionList && !_.isEmpty(suggestionList) && isShowSuggestion ? (
- )); + ) : noResults ? ( +
+ No Results +
+ ) : null; } handleClickOutside(e) { @@ -379,7 +412,10 @@ export class SearchBarInner extends Component { .then((results) => { // Nothing found? if (!results.total) { - this.setState({ suggestionList: {} }); + this.setState({ + suggestionList: {}, + noResults: true, + }); return; } // Author query? @@ -387,7 +423,7 @@ export class SearchBarInner extends Component { const suggestionList = { Author: _.map(results.items, item => ({ ...item.fields })), }; - this.setState({ suggestionList }); + this.setState({ suggestionList, noResults: false }); return; } // ALL && Tags @@ -395,7 +431,7 @@ export class SearchBarInner extends Component { this.setState({ suggestionList }); }); } else { - this.setState({ suggestionList: {} }); + this.setState({ suggestionList: {}, noResults: false }); } } @@ -419,6 +455,7 @@ export class SearchBarInner extends Component { contentAuthor: contentAuthor.fields, externalArticle: fields.externalArticle, contentUrl: fields.contentUrl, + slug: fields.slug, }; }), 'type', @@ -471,6 +508,7 @@ export class SearchBarInner extends Component { document.addEventListener('mousedown', this.handleClickOutside); }} onChange={this.handleSearchChange} + onKeyDown={this.onKeyDown} />