Commit 858fbb93 authored by Solveig Hergot Langås's avatar Solveig Hergot Langås
Browse files

#13 Searchword saved in store

parent c37930ba
......@@ -5,7 +5,12 @@ import { createAppContainer } from 'react-navigation';
import { Icon } from 'react-native-elements';
import HomePage from './pages/HomePage';
import ExplorePage from './pages/ExplorePage';
import { createStore, applyMiddleware } from 'redux';
import rootReducer from './reducers/index'
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';
const store = createStore(rootReducer, applyMiddleware(thunk))
const TabNavigator = createBottomTabNavigator(
{ Home: { screen: HomePage,
......@@ -24,4 +29,6 @@ const TabNavigator = createBottomTabNavigator(
showLabel : false,
}});
export default createAppContainer(TabNavigator);
const AppContainer = createAppContainer(TabNavigator)
export default () => (<Provider store = {store}><View style = {{flex: 1}}><AppContainer /></View></Provider>);
\ No newline at end of file
import React, { Component } from 'react';
import { StyleSheet, Text, View, TextInput, Alert } from 'react-native';
import { Icon } from 'react-native-elements';
import { connect } from 'react-redux'
import { changeSearchword } from '../actions/SearchAction'
class SearchBox extends Component {
......@@ -11,13 +13,13 @@ class SearchBox extends Component {
}
}
search = () => {
if (this.state.searchWord.length === 0){
word = "All"
search = () => {
if (this.state.searchWord.length === 0){ //search blank, show all places
word = "all"
} else {
word = this.state.searchWord
}
console.log("HEIDHK", word)
this.props.changeSearchword(word.toLowerCase())
}
handleSearchWord = (e) => {
......@@ -45,12 +47,27 @@ class SearchBox extends Component {
return(
<View style = {{flexDirection: "row", margin: 20}}>
<TextInput style = {inputfield} onKeyPress = {(e) => this.handleSearchWord(e)} onSubmitEditing = {() => this.search()} />
<TextInput style = {inputfield} autoCorrect = "false" onKeyPress = {(e) => this.handleSearchWord(e)} onSubmitEditing = {() => this.search()} />
<Icon name = "search" onPress = {() => this.search()}/>
<Text> {this.props.word} </Text>
</View>
);
}
}
export default SearchBox;
\ No newline at end of file
const mapDispatchToProps = (dispatch) => {
return {
changeSearchword: (word) => dispatch(changeSearchword(word))
}
};
const mapStateToProps = (state) => { //give us accsess to the data in store
const filter = state.filter
return {
word: filter.searchWord
}
}
export default connect(mapStateToProps, mapDispatchToProps)(SearchBox);
\ No newline at end of file
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment