Prechádzať zdrojové kódy

clase-list & clase fetch error

David 9 rokov pred
rodič
commit
1fc037c5ce

+ 27 - 41
src/actions/CursadaActions.js

@@ -2,17 +2,18 @@ import { Actions } from 'react-native-router-flux';
 import { post } from '../api/'
 
 import {
-	CURSADA_FETCH_SUCCESS,
 	CURSADAS_FETCH_SUCCESS,
+	CURSADA_FETCH_SUCCESS,
 	CURSADAS_FETCH_FAIL,
+	CURSADA_FETCH_FAIL,
 	CLASE_FETCH_SUCCESS,
+	CLASE_FETCH_FAIL,
 	CLASE_FETCH
 } from './types';
 
 export const cursadasFetch = () => {
 	return (dispatch) => {
-		//const path = 'listaCursos.php';
-		const path = 'qwrpoiewquewquoiewquoiewq.php';
+		const path = 'listaCursos.php';
 		post(path, { cursadas: 1 })
 		  .then( (response) => {
 			dispatch({
@@ -21,55 +22,40 @@ export const cursadasFetch = () => {
 			});
 		  })
 		.catch( (error) => {
-			dispatch({
-				type: CURSADAS_FETCH_FAIL
-			})
+			dispatch({ type: CURSADAS_FETCH_FAIL })
 		});
 	};
 };
 
 export const cursadaFetch = ({_id}) => {
 	return (dispatch) => {
-		fetch('https://plataforma.especificosba.com.ar/back/getCourse.php', {
-	  method: 'POST',
-	  headers: {
-		  'Accept': 'application/json',
-		  'Content-Type': 'application/json',
-	  },
-	  body: JSON.stringify({
-		id: _id
-	  })
-	})
-	.then( (response) => response.json() )
-	  .then( (responseJson) => {
-		dispatch({
-		  type: CURSADA_FETCH_SUCCESS,
-		  payload: responseJson
-		});
-	  });
+		const path = 'getCourse.php';
+		post(path,{ id: _id })
+		  .then( (response) => {
+			dispatch({
+		  		type: CURSADA_FETCH_SUCCESS,
+		  		payload: response
+			});
+		  })
+		  .catch( (error) => {
+		  	dispatch({ type: CURSADA_FETCH_FAIL });
+		  });
 	};
 };
 
 export const claseFetch = ({cursada, _id}) => {
 	return (dispatch) => {
 		dispatch({type: CLASE_FETCH});
-		fetch('https://plataforma.especificosba.com.ar/back/getClase.php', {
-	  method: 'POST',
-	  headers: {
-		  'Accept': 'application/json',
-		  'Content-Type': 'application/json',
-	  },
-	  body: JSON.stringify({
-				cursada,
-		id: _id
-	  })
-	})
-	.then( (response) => response.json() )
-	  .then( (responseJson) => {
-		dispatch({
-		  type: CLASE_FETCH_SUCCESS,
-		  payload: responseJson
-		});
-	  });
+		const path = 'qqqgetClase.php';
+	  	post(path, { cursada, id: _id })
+	  		.then( (response) => {
+				dispatch({
+				  type: CLASE_FETCH_SUCCESS,
+				  payload: response
+				});
+	  		})
+			.catch( (error) => {
+				dispatch({ type: CLASE_FETCH_FAIL });
+			});
 	};
 };

+ 2 - 0
src/actions/types.js

@@ -4,8 +4,10 @@ export const LOGIN_USER_SUCCESS = "login_user_success";
 export const LOGIN_USER_FAIL = "login_user_fail";
 export const LOGIN_USER = "login_user";
 export const CURSADA_FETCH_SUCCESS = "cursada_fetch_success";
+export const CURSADA_FETCH_FAIL = "cursada_fetch_fail";
 export const CURSADAS_FETCH_FAIL = "cursadas_fetch_fail";
 export const CURSADAS_FETCH_SUCCESS = "cursadas_fetch_success";
+export const CLASE_FETCH_FAIL = "clase_fetch_fail";
 export const CLASE_FETCH_SUCCESS = "clase_fetch_success";
 export const CLASE_FETCH = "clase_fetch";
 export const PROFESOR_FETCH = "profesor_fetch";

+ 7 - 1
src/reducers/CursadaReducer.js

@@ -1,8 +1,10 @@
 import {
   CURSADAS_FETCH_SUCCESS,
-  CURSADAS_FETCH_FAIL,
   CURSADA_FETCH_SUCCESS,
+  CURSADAS_FETCH_FAIL,
+  CURSADA_FETCH_FAIL,
   CLASE_FETCH_SUCCESS,
+  CLASE_FETCH_FAIL,
   CLASE_FETCH
 } from '../actions/types';
 
@@ -25,10 +27,14 @@ export default (state = INITIAL_STATE, action) => {
       return { ...state, error: true };
     case CURSADA_FETCH_SUCCESS:
       return { ...state, curCursada: action.payload };
+    case CURSADA_FETCH_FAIL:
+      return { ...state, curCursada: { error: true } };
 	case CLASE_FETCH:
 	  return { ...state, loading: true };
     case CLASE_FETCH_SUCCESS:
       return { ...state, loading: false, curClase: action.payload };
+	case CLASE_FETCH_FAIL:
+	  return { ...state, loading: false, curClase: { error: true } };
     default:
       return state;
   }

+ 4 - 0
src/scenes/Clase.js

@@ -8,6 +8,7 @@ import Teoria from './Clase/Teoria';
 import Comentarios from './Clase/Comentarios';
 import { Spinner } from '../components/common/';
 import MyActionButton from '../components/ActionButton';
+import { ConnectionError } from '../components/common';
 
 class Clase extends Component {
   state = { page: 'Teoria' };
@@ -31,6 +32,9 @@ class Clase extends Component {
 	if (this.props.loading)
 		return <Spinner size="large" />;
 
+	if (clase.error)
+		return <ConnectionError />;
+
     var ScrollableTabView = require('react-native-scrollable-tab-view');
     const { titulo, profesor, texto, comentarios, respuestas } = this.props.clase;
 

+ 6 - 1
src/scenes/ListaClases.js

@@ -6,6 +6,7 @@ import { Actions } from 'react-native-router-flux';
 import { cursadaFetch } from '../actions/';
 import { Card, CardSection, Button } from '../components/common/';
 import MyActionButton from '../components/ActionButton';
+import { ConnectionError } from '../components/common';
 
 class ListaClases extends Component  {
 	componentWillMount() {
@@ -74,7 +75,11 @@ class ListaClases extends Component  {
 	}
 
 	render() {
-    const { cursada } = this.props;
+	    const { cursada } = this.props;
+		if (cursada.error) {
+			return <ConnectionError />;
+		}
+
 		return (
       <View style={{flex:1}}>
         <CardSection>