aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/components/container
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-01-06 12:11:19 +0100
committerNoah Loomans <noahloomans@gmail.com>2018-01-06 12:11:19 +0100
commit77dccd31b32ee0a9a53b2186bae231069c5ab152 (patch)
treef90c5c524f1d3536a1f6ab665a7350739f590b7a /src/client/react/components/container
parent95041dffbd23fe81802efd5fb25cffe492cdb551 (diff)
Revert "Move to typescript"
This reverts commit f0c8cf0e79f003514fd65a70def5820205955a77.
Diffstat (limited to 'src/client/react/components/container')
-rw-r--r--src/client/react/components/container/Results.js35
-rw-r--r--src/client/react/components/container/Results.tsx26
-rw-r--r--src/client/react/components/container/Search.js (renamed from src/client/react/components/container/Search.tsx)69
3 files changed, 57 insertions, 73 deletions
diff --git a/src/client/react/components/container/Results.js b/src/client/react/components/container/Results.js
new file mode 100644
index 0000000..911ea27
--- /dev/null
+++ b/src/client/react/components/container/Results.js
@@ -0,0 +1,35 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { connect } from 'react-redux';
+import classnames from 'classnames';
+import Result from '../presentational/Result';
+
+const Results = (({ results, isExactMatch, selectedResult }) => (
+ <div
+ className={classnames('search__results', {
+ 'search__results--has-results': !isExactMatch && results.length > 0,
+ })}
+ >
+ {!isExactMatch && results.map(userId => (
+ <Result key={userId} userId={userId} isSelected={userId === selectedResult} />
+ ))}
+ </div>
+));
+
+Results.propTypes = {
+ results: PropTypes.arrayOf(PropTypes.string).isRequired,
+ isExactMatch: PropTypes.bool.isRequired,
+ selectedResult: PropTypes.string,
+};
+
+Results.defaultProps = {
+ selectedResult: null,
+};
+
+const mapStateToProps = state => ({
+ results: state.search.results,
+ isExactMatch: state.search.isExactMatch,
+ selectedResult: state.search.selectedResult,
+});
+
+export default connect(mapStateToProps)(Results);
diff --git a/src/client/react/components/container/Results.tsx b/src/client/react/components/container/Results.tsx
deleted file mode 100644
index 21d3378..0000000
--- a/src/client/react/components/container/Results.tsx
+++ /dev/null
@@ -1,26 +0,0 @@
-import * as React from 'react';
-import { connect } from 'react-redux';
-import * as classnames from 'classnames';
-import Result from '../presentational/Result';
-import { User } from '../../users';
-import { State } from '../../reducers';
-
-const Results: React.StatelessComponent<{ results: string[], isExactMatch: boolean, selectedResult: string }> = (props) => (
- <div
- className={classnames('search__results', {
- 'search__results--has-results': !props.isExactMatch && props.results.length > 0,
- })}
- >
- {!props.isExactMatch && props.results.map(userId => (
- <Result key={userId} userId={userId} isSelected={userId === props.selectedResult} />
- ))}
- </div>
-);
-
-const mapStateToProps = (state: State) => ({
- results: state.search.results,
- isExactMatch: state.search.isExactMatch,
- selectedResult: state.search.selectedResult,
-});
-
-export default connect(mapStateToProps)(Results);
diff --git a/src/client/react/components/container/Search.tsx b/src/client/react/components/container/Search.js
index fdd6c83..e49e6a7 100644
--- a/src/client/react/components/container/Search.tsx
+++ b/src/client/react/components/container/Search.js
@@ -1,30 +1,18 @@
-import * as React from 'react';
-import { Dispatch } from 'redux';
+import React from 'react';
+import PropTypes from 'prop-types';
import { connect } from 'react-redux';
-import * as classnames from 'classnames';
+import classnames from 'classnames';
-import SearchIcon = require('react-icons/lib/md/search');
+import SearchIcon from 'react-icons/lib/md/search';
import { inputChange, changeSelectedResult } from '../../actions/search';
-import { Action } from '../../reducers/search';
-import { State } from '../../reducers';
import users from '../../users';
import Results from './Results';
import IconFromUserType from '../presentational/IconFromUserType';
-interface SearchStatehProps {
- selectedResult: string,
- isExactMatch: boolean,
-}
-
-interface SearchDispatchProps {
- changeSelectedResult(relativeChange: 1 | -1): void,
- inputChange(typedValue: string): void,
-}
-
-class Search extends React.Component<SearchStatehProps & SearchDispatchProps, any> {
- constructor(props: SearchStatehProps & SearchDispatchProps) {
+class Search extends React.Component {
+ constructor(props) {
super(props);
this.state = {
@@ -48,15 +36,15 @@ class Search extends React.Component<SearchStatehProps & SearchDispatchProps, an
});
}
- onKeyDown(event: React.KeyboardEvent<any>) {
+ onKeyDown(event) {
if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
event.preventDefault();
switch (event.key) {
case 'ArrowUp':
- this.props.changeSelectedResult(-1);
+ this.props.dispatch(changeSelectedResult(-1));
break;
case 'ArrowDown':
- this.props.changeSelectedResult(+1);
+ this.props.dispatch(changeSelectedResult(+1));
break;
default:
throw new Error('This should never happen... pls?');
@@ -68,7 +56,7 @@ class Search extends React.Component<SearchStatehProps & SearchDispatchProps, an
const {
selectedResult,
isExactMatch,
- inputChange,
+ dispatch,
} = this.props;
const {
@@ -86,7 +74,7 @@ class Search extends React.Component<SearchStatehProps & SearchDispatchProps, an
</div>
<input
id="search__input"
- onChange={event => inputChange(event.target.value)}
+ onChange={event => dispatch(inputChange(event.target.value))}
onKeyDown={this.onKeyDown}
placeholder="Zoeken"
onFocus={this.onFocus}
@@ -99,33 +87,20 @@ class Search extends React.Component<SearchStatehProps & SearchDispatchProps, an
}
}
-// Search.propTypes = {
-// selectedResult: PropTypes.string,
-// isExactMatch: PropTypes.bool.isRequired,
-// dispatch: PropTypes.func.isRequired,
-// };
+Search.propTypes = {
+ selectedResult: PropTypes.string,
+ isExactMatch: PropTypes.bool.isRequired,
+ dispatch: PropTypes.func.isRequired,
+};
-// Search.defaultProps = {
-// selectedResult: null,
-// };
+Search.defaultProps = {
+ selectedResult: null,
+};
-const mapStateToProps = (state: State):SearchStatehProps => ({
+const mapStateToProps = state => ({
+ results: state.search.results,
selectedResult: state.search.selectedResult,
isExactMatch: state.search.isExactMatch,
});
-// const mapDispatchToProps = {
-// inputChange,
-// changeSelectedResult,
-// };
-
-const mapDispatchToProps = (dispatch: any): SearchDispatchProps => ({
- inputChange(typedValue) {
- dispatch(inputChange(typedValue));
- },
- changeSelectedResult(relativeChange) {
- dispatch(changeSelectedResult(relativeChange))
- }
-});
-
-export default connect(mapStateToProps, mapDispatchToProps)(Search);
+export default connect(mapStateToProps)(Search);