Skip to content

Commit

Permalink
[b] Fixed bugs: on text change
Browse files Browse the repository at this point in the history
  • Loading branch information
Kien Tran committed Mar 11, 2019
1 parent 6795035 commit a67f961
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ node_modules/
package-lock.json
yarn.lock
.jest/
domain/dist/*
repositories/dist
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "weather-ui"]
path = weather-ui
url = https://github.com/ttkien/weather-ui
branch = master
1 change: 1 addition & 0 deletions weather-ui
Submodule weather-ui added at 506ac1
11 changes: 7 additions & 4 deletions weather/src/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ class Props {
public items: SearchLocationListDataItem[];
public error: Error | null;
public isLoading: boolean;

public text: string;
constructor(
items: SearchLocationListDataItem[],
error: Error | null = null,
isLoading: boolean
isLoading: boolean,
text: string = ""
) {
this.items = items;
this.error = error;
this.isLoading = isLoading;
this.text = text;
}
}

Expand All @@ -33,7 +35,6 @@ export class Home extends Component<Props> {
)
};

public func;
public onChangeText = (text: string) => {
this.props.searchLocation(text);
}
Expand Down Expand Up @@ -62,6 +63,7 @@ export class Home extends Component<Props> {
onCancel={this.onCancel}
onClear={this.onCancel}
placeholder="Enter location"
value= {this.props.text}
/>
{errorView}
<KeyboardAvoidingView
Expand Down Expand Up @@ -90,7 +92,8 @@ const mapStateToProps = (state: ISearchLocationState): Props => {
return {
items: addKeysToItems(locations),
error: searchLocation.error,
isLoading: searchLocation.isLoading
isLoading: searchLocation.isLoading,
text: searchLocation.text
};
};

Expand Down
10 changes: 6 additions & 4 deletions weather/src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ export function willSearchLocation(searchText: string) {
};
}

export function didSearchLocation(locations: Location[]) {
export function didSearchLocation(text: string, locations: Location[]) {
return {
type: DID_SEARCH_LOCATION,
locations,
text
};
}

export function didSearchLocationError(error: Error) {
export function didSearchLocationError(text: string, error: Error) {
return {
type: DID_SEARCH_LOCATION_ERROR,
error,
text
};
}

Expand All @@ -34,10 +36,10 @@ export function searchLocation(text: string) {
const repository = new DefaultLocationRepository("AIzaSyDz8iOOAc-1NqzKRLl5n1qJFYY39NoL6EY");
repository.searchCity(text)
.subscribe((locations) => {
dispatch(didSearchLocation(locations));
dispatch(didSearchLocation(text, locations));
},
(error) => {
dispatch(didSearchLocationError(error));
dispatch(didSearchLocationError(text, error));
}
);
};
Expand Down
7 changes: 6 additions & 1 deletion weather/src/reducer/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import {
export interface ISearchLocationState {
locations: Location[];
isLoading: boolean;
text: string;
error: Error | null;
}

export function reducer(
state: ISearchLocationState = {
locations: [],
text: "",
isLoading: false,
error: null
},
Expand All @@ -25,18 +27,21 @@ export function reducer(
return {
...state,
locations: action.locations,
text: action.text,
isLoading: false,
error: null
};
case WILL_SEARCH_LOCATION:
return {
...state,
isLoading: true,
error: null
error: null,
text: action.text
};
case DID_SEARCH_LOCATION_ERROR:
return {
...state,
text: action.text,
error: action.error
};
default:
Expand Down

0 comments on commit a67f961

Please sign in to comment.