Просмотр исходного кода

set a spinner while loading classes

David 9 лет назад
Родитель
Сommit
c39e0785d1
4 измененных файлов с 17 добавлено и 7 удалено
  1. 3 1
      src/actions/CursadaActions.js
  2. 1 0
      src/actions/types.js
  3. 7 3
      src/reducers/CursadaReducer.js
  4. 6 3
      src/scenes/Clase.js

+ 3 - 1
src/actions/CursadaActions.js

@@ -2,7 +2,8 @@ import { Actions } from 'react-native-router-flux';
 import {
 import {
 	CURSADA_FETCH_SUCCESS,
 	CURSADA_FETCH_SUCCESS,
 	CURSADAS_FETCH_SUCCESS,
 	CURSADAS_FETCH_SUCCESS,
-	CLASE_FETCH_SUCCESS
+	CLASE_FETCH_SUCCESS,
+	CLASE_FETCH
 } from './types';
 } from './types';
 
 
 export const cursadasFetch = () => {
 export const cursadasFetch = () => {
@@ -51,6 +52,7 @@ export const cursadaFetch = ({_id}) => {
 
 
 export const claseFetch = ({cursada, _id}) => {
 export const claseFetch = ({cursada, _id}) => {
 	return (dispatch) => {
 	return (dispatch) => {
+		dispatch({type: CLASE_FETCH});
 		fetch('https://plataforma.especificosba.com.ar/back/getClase.php', {
 		fetch('https://plataforma.especificosba.com.ar/back/getClase.php', {
       method: 'POST',
       method: 'POST',
       headers: {
       headers: {

+ 1 - 0
src/actions/types.js

@@ -6,6 +6,7 @@ export const LOGIN_USER = "login_user";
 export const CURSADA_FETCH_SUCCESS = "cursada_fetch_success";
 export const CURSADA_FETCH_SUCCESS = "cursada_fetch_success";
 export const CURSADAS_FETCH_SUCCESS = "cursadas_fetch_success";
 export const CURSADAS_FETCH_SUCCESS = "cursadas_fetch_success";
 export const CLASE_FETCH_SUCCESS = "clase_fetch_success";
 export const CLASE_FETCH_SUCCESS = "clase_fetch_success";
+export const CLASE_FETCH = "clase_fetch";
 export const PROFESOR_FETCH = "profesor_fetch";
 export const PROFESOR_FETCH = "profesor_fetch";
 export const PROFESOR_FETCH_SUCCESS = "profesor_fetch_success";
 export const PROFESOR_FETCH_SUCCESS = "profesor_fetch_success";
 export const PROP_CHANGED = "prop_changed";
 export const PROP_CHANGED = "prop_changed";

+ 7 - 3
src/reducers/CursadaReducer.js

@@ -1,14 +1,16 @@
 import {
 import {
   CURSADAS_FETCH_SUCCESS,
   CURSADAS_FETCH_SUCCESS,
   CURSADA_FETCH_SUCCESS,
   CURSADA_FETCH_SUCCESS,
-  CLASE_FETCH_SUCCESS
+  CLASE_FETCH_SUCCESS,
+  CLASE_FETCH
 } from '../actions/types';
 } from '../actions/types';
 
 
 const INITIAL_STATE = {
 const INITIAL_STATE = {
   cursos: [],
   cursos: [],
   cursadas: [],
   cursadas: [],
   curCursada: { clases: [] },
   curCursada: { clases: [] },
-  curClase: { profesor: {} }
+  curClase: { profesor: {} },
+  loading: true
 };
 };
 
 
 export default (state = INITIAL_STATE, action) => {
 export default (state = INITIAL_STATE, action) => {
@@ -18,8 +20,10 @@ export default (state = INITIAL_STATE, action) => {
       return { ...state, cursadas, cursos };
       return { ...state, cursadas, cursos };
     case CURSADA_FETCH_SUCCESS:
     case CURSADA_FETCH_SUCCESS:
       return { ...state, curCursada: action.payload };
       return { ...state, curCursada: action.payload };
+	case CLASE_FETCH:
+	  return { ...state, loading: true };
     case CLASE_FETCH_SUCCESS:
     case CLASE_FETCH_SUCCESS:
-      return { ...state, curClase: action.payload };
+      return { ...state, loading: false, curClase: action.payload };
     default:
     default:
       return state;
       return state;
   }
   }

+ 6 - 3
src/scenes/Clase.js

@@ -6,6 +6,7 @@ import Tabs from 'react-native-tabs';
 import { claseFetch } from '../actions/';
 import { claseFetch } from '../actions/';
 import Teoria from './Clase/Teoria';
 import Teoria from './Clase/Teoria';
 import Comentarios from './Clase/Comentarios';
 import Comentarios from './Clase/Comentarios';
+import { Spinner } from '../components/common/';
 
 
 class Clase extends Component {
 class Clase extends Component {
   state = { page: 'Teoria' };
   state = { page: 'Teoria' };
@@ -26,7 +27,9 @@ class Clase extends Component {
   }
   }
   render() {
   render() {
     const { clase } = this.props;
     const { clase } = this.props;
-    console.log(clase);
+
+	if (this.props.loading)
+		return <Spinner size="large" />;
 
 
     return (
     return (
       <View style={styles.container, {flex:1}}>
       <View style={styles.container, {flex:1}}>
@@ -55,8 +58,8 @@ const styles = {
 };
 };
 
 
 const mapStateToProps = state => {
 const mapStateToProps = state => {
-  const { curClase } = state.cursadasR;
-	return { clase: curClase };
+  const { curClase, loading } = state.cursadasR;
+	return { loading, clase: curClase };
 };
 };
 
 
 export default connect(mapStateToProps, { claseFetch })(Clase);
 export default connect(mapStateToProps, { claseFetch })(Clase);