Skip to content
This repository has been archived by the owner on Aug 28, 2019. It is now read-only.

Fix absolute/relative paths in results #7954

Merged
merged 4 commits into from
Jan 25, 2018
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"react-bootstrap": "^0.31.0",
"react-dom": "^15.6.1",
"react-fontawesome": "^1.6.1",
"react-freecodecamp-search": "^1.2.1",
"react-freecodecamp-search": "^1.4.1",
"react-redux": "^5.0.5",
"redux": "^3.7.2",
"redux-actions": "^2.2.1",
Expand Down
24 changes: 11 additions & 13 deletions src/LayoutComponents/search/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
const propTypes = {
results: PropTypes.arrayOf(PropTypes.object),
searchTerm: PropTypes.string,
updateIsSearching: PropTypes.func.isRequired,
updateLastPage: PropTypes.func.isRequired,
updateSearchResults: PropTypes.func.isRequired,
updateSearchTerm: PropTypes.func.isRequired
Expand All @@ -35,35 +36,32 @@ function mapDispatchToProps(dispatch) {
}

class SearchBar extends PureComponent {
constructor() {
super();
this.handleResults = this.handleResults.bind(this);
constructor(props) {
super(props);
this.handleSearchTerm = this.handleSearchTerm.bind(this);
}

handleResults(results) {
handleSearchTerm(searchTerm) {
const {
searchTerm,
updateLastPage,
updateSearchResults
updateSearchTerm
} = this.props;
updateSearchTerm(searchTerm);
const { push } = this.context.router.history;
const { pathname } = this.context.router.history.location;

if (pathname !== '/search' && searchTerm.length >= 2) {
if (pathname !== '/search' && searchTerm.length > 2) {
updateLastPage(pathname);
push('/search');
}
updateSearchResults(results);
}


render() {
const { updateSearchTerm } = this.props;
const { updateIsSearching, updateSearchResults } = this.props;
return (
<FCCSearchBar
handleResults={this.handleResults}
handleResults={updateSearchResults}
handleSearchingStatus={updateIsSearching}
handleSearchTerm={updateSearchTerm}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updateSearchTerm action is not dispatched at all anymore. NoResults.jsx needs to know the search term to decide to display "you didn't search" or "no results found." I tried adding it in the handleSearchTerm function, and that seemed to work properly.

handleSearchTerm={this.handleSearchTerm}
/>
);
}
Expand Down
14 changes: 13 additions & 1 deletion src/pageComponents/search/Results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ function mapDispatchToProps() {
return {};
}

function truncate(str) {
return str.replace('\n', '').slice(0, 150) + '...';
}

function MediaWrapper(props) {
const { url } = props;
return isGuidesUrl.test(url) ?
Expand Down Expand Up @@ -57,7 +61,15 @@ class Results extends PureComponent {
renderResultItems() {
const { results } = this.props;
return results.map((result, i) => {
const { _index, _source: { title, url, description } } = result;
const {
_index,
_source: {
title,
url,
friendlySearchString = ''
}
} = result;
const description = truncate(friendlySearchString);
return (
<MediaWrapper key={ i } url={ url }>
<Media>
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6807,9 +6807,9 @@ react-fontawesome@^1.6.1:
dependencies:
prop-types "^15.5.6"

react-freecodecamp-search@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/react-freecodecamp-search/-/react-freecodecamp-search-1.2.1.tgz#315c7a495d214a00dc7a69203fecd5c8bd3ffaec"
react-freecodecamp-search@^1.4.1:
version "1.4.2"
resolved "https://registry.yarnpkg.com/react-freecodecamp-search/-/react-freecodecamp-search-1.4.2.tgz#3af1bcbfa84002acd72deeb0710cfdee62f952ca"
dependencies:
rxjs "^5.5.5"
xhr "^2.4.1"
Expand Down Expand Up @@ -7504,8 +7504,8 @@ rx@^4.1.0:
resolved "https://registry.yarnpkg.com/rx/-/rx-4.1.0.tgz#a5f13ff79ef3b740fe30aa803fb09f98805d4782"

rxjs@^5.5.5:
version "5.5.5"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.5.5.tgz#e164f11d38eaf29f56f08c3447f74ff02dd84e97"
version "5.5.6"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.5.6.tgz#e31fb96d6fd2ff1fd84bcea8ae9c02d007179c02"
dependencies:
symbol-observable "1.0.1"

Expand Down