Guest User

Untitled

a guest
Sep 18th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.87 KB | None | 0 0
  1. import React from 'react';
  2. import { StyleSheet, Text, View } from 'react-native';
  3. import { createStore, applyMiddleware} from 'redux';
  4. import { Provider, connect} from 'react-redux';
  5. import axios from 'axios';
  6. import axiosMiddleware from 'redux-axios-middleware';
  7. import Navigation from './navigation.js';
  8. import reducer from './reducer.js';
  9.  
  10. const httpClient = axios.create({
  11. baseURL: '',
  12. responseType: 'json'
  13. });
  14.  
  15. const store = createStore(reducer, applyMiddleware(axiosMiddleware(client)));
  16.  
  17. export default class App extends React.Component {
  18. render() {
  19. return (
  20. <Provider store={store}>
  21. <Navigation />
  22. </Provider>
  23. );
  24. }
  25. }
  26.  
  27. import { createStackNavigator } from 'react-navigation';
  28. import * as React from 'react';
  29. import MapScreen from './pageComponents/MapScreen.js'
  30. import LoginScreen from './pageComponents/LoginScreen.js'
  31. import MenuNavButton from "./components/MenuNavButton";
  32.  
  33.  
  34. export default createStackNavigator({
  35. Map: MapScreen,
  36. Login: LoginScreen
  37. },
  38. {
  39. initialRouteName: 'Map',
  40. navigationOptions: {
  41. headerRight: <MenuNavButton toScreen="Login" />
  42. }
  43. });
  44.  
  45. import React from 'react';
  46. import { StyleSheet, Text, TextInput, Button, View, AsyncStorage, ActivityIndicator } from 'react-native';
  47. import { connect } from 'react-redux';
  48. import { postLogin } from '../actionCreators/loginScreenAction.js';
  49. /*
  50. <View style={styles.container}>
  51. <Text>Open up App.js to start working on your app!</Text>
  52. <Text>Changes you make will automatically reload.</Text>
  53. <Text>Shake your phone to open the developer menu.</Text>
  54. </View>
  55. */
  56.  
  57.  
  58. class LoginScreen extends React.Component {
  59. constructor(props) {
  60. super(props);
  61. this.state = {
  62. username: '',
  63. password: '',
  64. isLoading: false
  65. };
  66. }
  67.  
  68. handleChange = fieldName => event => {
  69. this.setState({
  70. [fieldName]: event.target.value,
  71. });
  72. };
  73.  
  74. signInAsync = async () => {
  75. await this.props.postLogin(this.state.username, this.state.password)
  76. .then((response) => console.log(response));
  77. //this.setState(() => {
  78. // return{ isLoading: true }
  79. //});
  80. //await AsyncStorage.setItem('userToken', 'abc');
  81. //this.props.navigation.navigate('Carte');
  82. };
  83.  
  84. render() {
  85. console.log(this.state);
  86. let spinner = (this.state.isLoading) ? (
  87. <ActivityIndicator
  88. animating={true}
  89. size="large" color="#0000ff"
  90. />
  91. ) : (
  92. null
  93. );
  94. return (<View style={styles.container}>
  95. <Text>userName Guss is god</Text>
  96. <TextInput
  97. style={{height: 40, width: 350}}
  98. onChange={this.handleChange('username')}
  99. value={this.state.userName}
  100. />
  101. <Text>password</Text>
  102. <TextInput
  103. style={{height: 40, width: 350}}
  104. onChange={this.handleChange('password')}
  105. value={this.state.password}
  106. />
  107. <Button title="login" onPress={this.signInAsync} />
  108. {spinner}
  109. </View>);
  110. }
  111. }
  112. //<ActivityIndicator size="large" color="#0000ff" animating={this.state.isLoading}/>
  113. const styles = StyleSheet.create({
  114. container: {
  115. flex: 1,
  116. backgroundColor: '#fff',
  117. alignItems: 'center',
  118. justifyContent: 'center',
  119. },
  120. });
  121.  
  122. const mapStateToProps = state => {
  123. return {
  124. isLoading: state.loading
  125. }
  126. };
  127.  
  128. const mapDispatchToProps = {
  129. postLogin
  130. };
  131.  
  132. export default connect(mapStateToProps, mapDispatchToProps)(LoginScreen);
  133.  
  134. export const POST_LOGIN = "evenMap/login/POST";
  135. export const POST_LOGIN_SUCCESS = "evenMap/login/POST_SUCCESS";
  136. export const POST_LOGIN_FAIL = "evenMap/login/POST_FAIL";
  137.  
  138. export default function reducer(state = { event: []}, action) {
  139. switch (action.type) {
  140. case POST_LOGIN:
  141. return { ...state, loading: true};
  142. case POST_LOGIN_SUCCESS:
  143. return { ...state, loading: false};
  144. case POST_LOGIN_FAIL:
  145. return { ...state, loading:false};
  146. default:
  147. return state;
  148. }
  149. }
  150.  
  151. import {POST_LOGIN} from "../reducer.js";
  152.  
  153. export function postLogin(email, password) {
  154. return {
  155. type: POST_LOGIN,
  156. payload: {
  157. request: {
  158. method: 'POST',
  159. url: '/login',
  160. data: {
  161. email: email,
  162. password: password
  163. }
  164. }
  165. }
  166. };
  167. }
  168.  
  169. Invariant Violation: Invariant Violation: Could not find "store" in either the context or props of "Connect(LoginScreen)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(LoginScreen)".
  170.  
  171. This error is located at:
  172. in Connect(LoginScreen) (at SceneView.js:9)
  173. in SceneView (at StackViewLayout.js:476)
  174. in RCTView (at View.js:60)
  175. in View (at StackViewLayout.js:475)
  176. in RCTView (at View.js:60)
  177. in View (at StackViewLayout.js:474)
  178. in RCTView (at View.js:60)
  179. in View (at createAnimatedComponent.js:154)
  180. in AnimatedComponent (at screens.js:47)
  181. in Screen (at StackViewCard.js:41)
  182. in Card (at createPointerEventsContainer.js:26)
  183. in Container (at StackViewLayout.js:506)
  184. in RCTView (at View.js:60)
  185. in View (at screens.js:72)
  186. in ScreenContainer (at StackViewLayout.js:399)
  187. in RCTView (at View.js:60)
  188. in View (at StackViewLayout.js:398)
  189. in StackViewLayout (at withOrientation.js:30)
  190. in withOrientation (at StackView.js:40)
  191. in RCTView (at View.js:60)
  192. in View (at Transitioner.js:141)
  193. in Transitioner (at StackView.js:19)
  194. in StackView (at createNavigator.js:59)
  195. in Navigator (at createKeyboardAwareNavigator.js:11)
  196. in KeyboardAwareNavigator (at createNavigationContainer.js:376)
  197. in NavigationContainer (at App.js:12)
  198. in App (at registerRootComponent.js:35)
  199. in RootErrorBoundary (at registerRootComponent.js:34)
  200. in ExpoRootComponent (at renderApplication.js:33)
  201. in RCTView (at View.js:60)
  202. in View (at AppContainer.js:102)
  203. in RCTView (at View.js:60)
  204. in View (at AppContainer.js:122)
  205. in AppContainer (at renderApplication.js:32)
  206.  
  207. This error is located at:
  208. in NavigationContainer (at App.js:12)
  209. in App (at registerRootComponent.js:35)
  210. in RootErrorBoundary (at registerRootComponent.js:34)
  211. in ExpoRootComponent (at renderApplication.js:33)
  212. in RCTView (at View.js:60)
  213. in View (at AppContainer.js:102)
  214. in RCTView (at View.js:60)
  215. in View (at AppContainer.js:122)
  216. in AppContainer (at renderApplication.js:32)
  217. - node_modules/react-redux/lib/components/connectAdvanced.js:116:24 in Connect(LoginScreen)
  218. - node_modules/react-native/Libraries/Renderer/ReactNativeRenderer-dev.js:6569:28 in constructClassInstance
  219. - ... 17 more stack frames from framework internals
Add Comment
Please, Sign In to add comment