Skip to content

Commit 52dd617

Browse files
Merge pull request #4886 from topcoder-platform/feature-contentful
Feature contentful - gig work updates
2 parents 16bd8dc + d6a9f3c commit 52dd617

File tree

9 files changed

+99
-12
lines changed

9 files changed

+99
-12
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ workflows:
260260
filters:
261261
branches:
262262
only:
263-
- develop
263+
- feature-contentful
264264
# Production builds are exectuted
265265
# when PR is merged to the master
266266
# Don't change anything in this configuration

src/shared/components/Contentful/Article/Article.jsx

+22-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import LoadingIndicator from 'components/LoadingIndicator';
1515
import YouTubeVideo from 'components/YouTubeVideo';
1616
import moment from 'moment';
1717
import localStorage from 'localStorage';
18-
import { config, Link, isomorphy } from 'topcoder-react-utils';
18+
import { Helmet } from 'react-helmet';
19+
import {
20+
config, Link, isomorphy,
21+
} from 'topcoder-react-utils';
1922
import qs from 'qs';
2023
// SVGs and assets
2124
import GestureIcon from 'assets/images/icon-gesture.svg';
@@ -110,9 +113,27 @@ export default class Article extends React.Component {
110113
if (isomorphy.isClientSide()) {
111114
shareUrl = encodeURIComponent(window.location.href);
112115
}
116+
const description = htmlToText.fromString(
117+
ReactDOMServer.renderToString(markdown(fields.content)),
118+
{
119+
ignoreHref: true,
120+
ignoreImage: true,
121+
singleNewLineParagraphs: true,
122+
uppercaseHeadings: false,
123+
},
124+
).substring(0, CONTENT_PREVIEW_LENGTH);
113125

114126
return (
115127
<React.Fragment>
128+
<Helmet>
129+
<title>{fields.title}</title>
130+
<meta name="title" property="og:title" content={fields.title} />
131+
<meta name="description" property="og:description" content={description} />
132+
<meta name="description" property="description" content={description} />
133+
<meta name="twitter:description" content={description} />
134+
<meta name="image" property="og:image" content={fields.featuredImage ? `https:${subData.assets.items[fields.featuredImage.sys.id].fields.file.url}` : null} />
135+
<meta name="twitter:image" content={fields.featuredImage ? `https:${subData.assets.items[fields.featuredImage.sys.id].fields.file.url}` : null} />
136+
</Helmet>
116137
{/* Banner */}
117138
{
118139
fields.featuredImage ? (

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

+43-5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class SearchBarInner extends Component {
5656
this.getSuggestionList = this.getSuggestionList.bind(this);
5757
this.handleSearchChange = this.handleSearchChange.bind(this);
5858
this.handleClickOutside = this.handleClickOutside.bind(this);
59+
this.onKeyDown = this.onKeyDown.bind(this);
5960
// using debounce to avoid processing or requesting too much
6061
this.updateSuggestionListWithNewSearch = _.debounce(
6162
this.updateSuggestionListWithNewSearch.bind(this), 400,
@@ -71,6 +72,29 @@ export class SearchBarInner extends Component {
7172
document.removeEventListener('mousedown', this.handleClickOutside);
7273
}
7374

75+
onKeyDown(e) {
76+
const { inputlVal, selectedFilter } = this.state;
77+
if (inputlVal && e.which === 13) {
78+
const searchQuery = {};
79+
if (this.searchFieldRef && this.searchFieldRef.value) {
80+
if (selectedFilter.name === 'Tags') {
81+
searchQuery.tags = [this.searchFieldRef.value];
82+
}
83+
if (selectedFilter.name === 'All') {
84+
searchQuery.phrase = this.searchFieldRef.value;
85+
}
86+
if (selectedFilter.name === 'Title') {
87+
searchQuery.title = this.searchFieldRef.value;
88+
}
89+
}
90+
if (selectedFilter.name !== 'Author') {
91+
window.location.href = `${config.TC_EDU_BASE_PATH}${config.TC_EDU_SEARCH_PATH}?${qs.stringify(searchQuery)}`;
92+
} else {
93+
window.location.href = `${config.TC_EDU_BASE_PATH}${config.TC_EDU_SEARCH_PATH}?author=${inputlVal}`;
94+
}
95+
}
96+
}
97+
7498
/**
7599
* Set the search field ref
76100
*/
@@ -136,6 +160,7 @@ export class SearchBarInner extends Component {
136160
isShowSuggestion,
137161
suggestionList,
138162
selectedFilter,
163+
noResults,
139164
} = this.state;
140165

141166
const searchQuery = {};
@@ -151,7 +176,8 @@ export class SearchBarInner extends Component {
151176
}
152177
}
153178

154-
return (suggestionList && !_.isEmpty(suggestionList) && isShowSuggestion && (
179+
// eslint-disable-next-line no-nested-ternary
180+
return suggestionList && !_.isEmpty(suggestionList) && isShowSuggestion ? (
155181
<div
156182
className={theme['popup-search-result']}
157183
ref={this.setPopupSearchResultRef}
@@ -319,7 +345,14 @@ export class SearchBarInner extends Component {
319345
) : null
320346
}
321347
</div>
322-
));
348+
) : noResults ? (
349+
<div
350+
className={theme['popup-search-result']}
351+
ref={this.setPopupSearchResultRef}
352+
>
353+
<span>No Results</span>
354+
</div>
355+
) : null;
323356
}
324357

325358
handleClickOutside(e) {
@@ -379,23 +412,26 @@ export class SearchBarInner extends Component {
379412
.then((results) => {
380413
// Nothing found?
381414
if (!results.total) {
382-
this.setState({ suggestionList: {} });
415+
this.setState({
416+
suggestionList: {},
417+
noResults: true,
418+
});
383419
return;
384420
}
385421
// Author query?
386422
if (selectedFilter.name === 'Author') {
387423
const suggestionList = {
388424
Author: _.map(results.items, item => ({ ...item.fields })),
389425
};
390-
this.setState({ suggestionList });
426+
this.setState({ suggestionList, noResults: false });
391427
return;
392428
}
393429
// ALL && Tags
394430
const suggestionList = this.groupResults(results);
395431
this.setState({ suggestionList });
396432
});
397433
} else {
398-
this.setState({ suggestionList: {} });
434+
this.setState({ suggestionList: {}, noResults: false });
399435
}
400436
}
401437

@@ -419,6 +455,7 @@ export class SearchBarInner extends Component {
419455
contentAuthor: contentAuthor.fields,
420456
externalArticle: fields.externalArticle,
421457
contentUrl: fields.contentUrl,
458+
slug: fields.slug,
422459
};
423460
}),
424461
'type',
@@ -471,6 +508,7 @@ export class SearchBarInner extends Component {
471508
document.addEventListener('mousedown', this.handleClickOutside);
472509
}}
473510
onChange={this.handleSearchChange}
511+
onKeyDown={this.onKeyDown}
474512
/>
475513
<div className={theme.dropdown}>
476514
<button

src/shared/components/Contentful/SearchBar/themes/default.scss

+4
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ $link-color: #0d61bf;
156156
overflow-y: auto;
157157
box-shadow: 0 25px 50px 0 rgba(0, 0, 0, 0.15);
158158
z-index: 999;
159+
160+
> span {
161+
margin-left: 15px;
162+
}
159163
}
160164

161165
.icon-search {

src/shared/containers/EDU/Home.jsx

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
import React from 'react';
55
import { config } from 'topcoder-react-utils';
6+
import { Helmet } from 'react-helmet';
67
import Viewport from 'components/Contentful/Viewport';
78
import SearchBar from 'components/Contentful/SearchBar/SearchBar';
89
import { getService } from 'services/contentful';
@@ -45,6 +46,13 @@ export default class EDUHome extends React.Component {
4546
const { taxonomy } = this.state;
4647
return (
4748
<div className={homeTheme.container}>
49+
<Helmet>
50+
<title>THRIVE - Grow with us. Tutorials and workshops that matter.</title>
51+
<meta name="title" property="og:title" content="THRIVE - Grow with us. Tutorials and workshops that matter." />
52+
<meta name="description" property="og:description" content="THRIVE - Grow with us. Tutorials and workshops that matter." />
53+
<meta name="description" property="description" content="THRIVE - Grow with us. Tutorials and workshops that matter." />
54+
<meta name="twitter:description" content="THRIVE - Grow with us. Tutorials and workshops that matter." />
55+
</Helmet>
4856
{/* Banner */}
4957
<div className={homeTheme.bannerContainer}>
5058
<div className={homeTheme.bannerImage} />

src/shared/containers/EDU/Search.jsx

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { updateQuery } from 'utils/url';
1313
import qs from 'qs';
1414
import LoadingIndicator from 'components/LoadingIndicator';
1515
import SearchPageFilter from 'components/Contentful/SearchPageFilter/SearchPageFilter';
16+
import { Helmet } from 'react-helmet';
1617
// Partials
1718
import ResultTabs from './partials/ResultTabs';
1819
// CSS
@@ -91,6 +92,13 @@ export default class EDUSearch extends React.Component {
9192
if (!taxonomy) return <LoadingIndicator />;
9293
return (
9394
<div className={searchTheme.container}>
95+
<Helmet>
96+
<title>THRIVE - Search {`${query.title}`}</title>
97+
<meta name="title" property="og:title" content="THRIVE - Grow with us. Tutorials and workshops that matter." />
98+
<meta name="description" property="og:description" content="THRIVE - Grow with us. Tutorials and workshops that matter." />
99+
<meta name="description" property="description" content="THRIVE - Grow with us. Tutorials and workshops that matter." />
100+
<meta name="twitter:description" content="THRIVE - Grow with us. Tutorials and workshops that matter." />
101+
</Helmet>
94102
{/* Banner */}
95103
<div className={searchTheme.bannerContainer}>
96104
<div className={searchTheme.searchBarWrapp}>

src/shared/containers/EDU/Tracks.jsx

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import qs from 'qs';
1414
import TracksTree from 'components/Contentful/TracksTree/TracksTree';
1515
import LoadingIndicator from 'components/LoadingIndicator';
1616
import TracksFilter from 'components/Contentful/TracksFilter/TracksFilter';
17+
import { Helmet } from 'react-helmet';
1718
// SVGs & Assets
1819
import Dev from 'assets/images/img-development.png';
1920
import Design from 'assets/images/img_design.png';
@@ -167,6 +168,13 @@ export default class EDUTracks extends React.Component {
167168
if (!taxonomy) return <LoadingIndicator />;
168169
return (
169170
<div className={tracksTheme.container}>
171+
<Helmet>
172+
<title>THRIVE - {`${query.track}`}</title>
173+
<meta name="title" property="og:title" content="THRIVE - Grow with us. Tutorials and workshops that matter." />
174+
<meta name="description" property="og:description" content="THRIVE - Grow with us. Tutorials and workshops that matter." />
175+
<meta name="description" property="description" content="THRIVE - Grow with us. Tutorials and workshops that matter." />
176+
<meta name="twitter:description" content="THRIVE - Grow with us. Tutorials and workshops that matter." />
177+
</Helmet>
170178
{/* Banner */}
171179
<div
172180
className={tracksTheme.bannerContainer}

src/shared/containers/EDU/partials/ResultTabs.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export default class ResultTabs extends React.Component {
162162
]}
163163
/>
164164
))
165-
) : (<h3>Nothing Found</h3>)
165+
) : (<h3>No results found</h3>)
166166
}
167167
{
168168
articles.total > articles.items.length ? (
@@ -193,7 +193,7 @@ export default class ResultTabs extends React.Component {
193193
))
194194
}
195195
</div>
196-
) : (<h3>Nothing Found</h3>)
196+
) : (<h3>No results found</h3>)
197197
}
198198
{
199199
videos.total > videos.items.length ? (
@@ -225,7 +225,7 @@ export default class ResultTabs extends React.Component {
225225
/>
226226
);
227227
})
228-
) : (<h3>Nothing Found</h3>)
228+
) : (<h3>No results found</h3>)
229229
}
230230
{
231231
posts.total > posts.items.length ? (

src/shared/services/contentful.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ class Service {
346346
query.query = tags.join(' ');
347347
}
348348
}
349-
if (startDate) query['sys.createdAt[gte]'] = startDate;
350-
if (endDate) query['sys.createdAt[lte]'] = endDate;
349+
if (startDate) query['fields.creationDate[gte]'] = startDate;
350+
if (endDate) query['fields.creationDate[lte]'] = endDate;
351351
if (phrase) query.query = phrase;
352352
if (title) query['fields.title[match]'] = title;
353353
const content = {};

0 commit comments

Comments
 (0)