aboutsummaryrefslogtreecommitdiff
path: root/src/client/react
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-01-06 12:11:05 +0100
committerNoah Loomans <noahloomans@gmail.com>2018-01-06 12:11:05 +0100
commit95041dffbd23fe81802efd5fb25cffe492cdb551 (patch)
treecb66d325fb5d16d8b7fa0f14c91ad17dd4ff7c6c /src/client/react
parent4ca30295d7d9f3dd7ba2e105952ff627f6b702a4 (diff)
Revert "Add strict typing"
This reverts commit 4ca30295d7d9f3dd7ba2e105952ff627f6b702a4.
Diffstat (limited to 'src/client/react')
-rw-r--r--src/client/react/components/container/Search.tsx27
-rw-r--r--src/client/react/components/presentational/IconFromUserType.tsx2
-rw-r--r--src/client/react/reducers.ts1
-rw-r--r--src/client/react/reducers/search.ts2
-rw-r--r--src/client/react/users.ts23
5 files changed, 29 insertions, 26 deletions
diff --git a/src/client/react/components/container/Search.tsx b/src/client/react/components/container/Search.tsx
index b22c26e..fdd6c83 100644
--- a/src/client/react/components/container/Search.tsx
+++ b/src/client/react/components/container/Search.tsx
@@ -13,8 +13,8 @@ import users from '../../users';
import Results from './Results';
import IconFromUserType from '../presentational/IconFromUserType';
-interface SearchStateProps {
- selectedResult: string | null,
+interface SearchStatehProps {
+ selectedResult: string,
isExactMatch: boolean,
}
@@ -23,8 +23,8 @@ interface SearchDispatchProps {
inputChange(typedValue: string): void,
}
-class Search extends React.Component<SearchStateProps & SearchDispatchProps, any> {
- constructor(props: SearchStateProps & SearchDispatchProps) {
+class Search extends React.Component<SearchStatehProps & SearchDispatchProps, any> {
+ constructor(props: SearchStatehProps & SearchDispatchProps) {
super(props);
this.state = {
@@ -80,7 +80,7 @@ class Search extends React.Component<SearchStateProps & SearchDispatchProps, any
<div className="search__input-wrapper">
<div className="search__icon-wrapper">
<IconFromUserType
- userType={(selectedResult && isExactMatch) ? users.byId[selectedResult].type : undefined}
+ userType={isExactMatch ? users.byId[selectedResult].type : null}
defaultIcon={<SearchIcon />}
/>
</div>
@@ -99,11 +99,26 @@ class Search extends React.Component<SearchStateProps & SearchDispatchProps, any
}
}
-const mapStateToProps = (state: State):SearchStateProps => ({
+// Search.propTypes = {
+// selectedResult: PropTypes.string,
+// isExactMatch: PropTypes.bool.isRequired,
+// dispatch: PropTypes.func.isRequired,
+// };
+
+// Search.defaultProps = {
+// selectedResult: null,
+// };
+
+const mapStateToProps = (state: State):SearchStatehProps => ({
selectedResult: state.search.selectedResult,
isExactMatch: state.search.isExactMatch,
});
+// const mapDispatchToProps = {
+// inputChange,
+// changeSelectedResult,
+// };
+
const mapDispatchToProps = (dispatch: any): SearchDispatchProps => ({
inputChange(typedValue) {
dispatch(inputChange(typedValue));
diff --git a/src/client/react/components/presentational/IconFromUserType.tsx b/src/client/react/components/presentational/IconFromUserType.tsx
index 83af34c..d77ea1b 100644
--- a/src/client/react/components/presentational/IconFromUserType.tsx
+++ b/src/client/react/components/presentational/IconFromUserType.tsx
@@ -9,7 +9,7 @@ import TeacherIcon = require('react-icons/lib/md/account-circle');
// defaultIcon?: JSX.Element,
// }
-const IconFromUserType: React.StatelessComponent<{ userType?: string, defaultIcon?: JSX.Element }> = (props) => {
+const IconFromUserType: React.StatelessComponent<{ userType: string, defaultIcon?: JSX.Element }> = (props) => {
switch (props.userType) {
case 'c':
return <ClassIcon />;
diff --git a/src/client/react/reducers.ts b/src/client/react/reducers.ts
index 6f92e1d..254fe76 100644
--- a/src/client/react/reducers.ts
+++ b/src/client/react/reducers.ts
@@ -5,7 +5,6 @@ export interface State {
search: SearchState,
}
-// @ts-ignore
const rootReducer = combineReducers<State>({
search,
});
diff --git a/src/client/react/reducers/search.ts b/src/client/react/reducers/search.ts
index 470e650..658d3ca 100644
--- a/src/client/react/reducers/search.ts
+++ b/src/client/react/reducers/search.ts
@@ -61,7 +61,7 @@ const search = (state = DEFAULT_STATE, action: Action): State => {
if (isExactMatch) return state;
const prevSelectedResult = state.selectedResult;
- const prevSelectedResultIndex = prevSelectedResult ? results.indexOf(prevSelectedResult) : -1;
+ const prevSelectedResultIndex = results.indexOf(prevSelectedResult);
let nextSelectedResultIndex =
prevSelectedResultIndex + action.relativeChange;
diff --git a/src/client/react/users.ts b/src/client/react/users.ts
index a16e40f..a80a1c5 100644
--- a/src/client/react/users.ts
+++ b/src/client/react/users.ts
@@ -1,9 +1,6 @@
/* global USERS */
import { combineReducers, createStore } from 'redux';
-import { AnyAction } from 'redux';
-import { Reducer } from 'redux';
-import { ReducersMapObject } from 'redux';
export interface User {
type: string,
@@ -24,11 +21,7 @@ declare global {
const getId = ({ type, value }: User) => `${type}/${value}`;
-type ByIdState = {
- [userId: string]: User,
-}
-
-const byId = (state: ByIdState = {}, action: Action): ByIdState => {
+const byId = (state = {}, action: Action) => {
switch (action.type) {
case 'USERS/ADD_USER':
return {
@@ -42,9 +35,7 @@ const byId = (state: ByIdState = {}, action: Action): ByIdState => {
}
};
-type AllIdsState = string[]
-
-const allIds = (state: AllIdsState = [], action: Action): AllIdsState => {
+const allIds = (state : any[] = [], action : Action) => {
switch (action.type) {
case 'USERS/ADD_USER':
return [
@@ -56,9 +47,7 @@ const allIds = (state: AllIdsState = [], action: Action): AllIdsState => {
}
};
-type AllUsersState = User[];
-
-const allUsers = (state: AllUsersState = [], action: Action): AllUsersState => {
+const allUsers = (state : any[] = [], action : Action) => {
switch (action.type) {
case 'USERS/ADD_USER':
return [
@@ -73,9 +62,9 @@ const allUsers = (state: AllUsersState = [], action: Action): AllUsersState => {
};
interface State {
- byId: ByIdState,
- allIds: AllIdsState,
- allUsers: AllUsersState,
+ byId: any,
+ allIds: string[],
+ allUsers: User[]
}
const store = createStore(combineReducers<State>({