Ver código fonte

agrego lista de clases

David 9 anos atrás
pai
commit
da476ae449

+ 2 - 0
src/Router.js

@@ -3,6 +3,7 @@ import { Scene, Router, Actions } from 'react-native-router-flux';
 import LoginForm from './components/LoginForm';
 import LiveVideo from './components/LiveVideo';
 import ListaCursadas from './components/ListaCursadas';
+import Cursada from './components/Cursada';
 
 const RouterComponent = () => {
 	return (
@@ -13,6 +14,7 @@ const RouterComponent = () => {
 
 			<Scene key="main">
 				<Scene key="ListaCursadas" component={ListaCursadas} />
+				<Scene key="ViewCursada" component={Cursada} />
 				<Scene key="Live" component={LiveVideo} />
 			</Scene>
 		</Router>

+ 26 - 1
src/actions/CursadaActions.js

@@ -1,6 +1,7 @@
 import { Actions } from 'react-native-router-flux';
 import {
-	CURSADA_FETCH_SUCCESS
+	CURSADA_FETCH_SUCCESS,
+	CURSADAS_FETCH_SUCCESS
 } from './types';
 
 export const cursadasFetch = () => {
@@ -21,6 +22,30 @@ export const cursadasFetch = () => {
     .then( (response) => response.json() )
       .then( (responseJson) => {
         console.log(responseJson);
+        dispatch({
+          type: CURSADAS_FETCH_SUCCESS,
+          payload: responseJson
+        });
+      });
+	};
+};
+
+export const cursadaFetch = ({_id}) => {
+	console.log({_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) => {
+        console.log("cursadita",responseJson);
         dispatch({
           type: CURSADA_FETCH_SUCCESS,
           payload: responseJson

+ 1 - 0
src/actions/types.js

@@ -4,3 +4,4 @@ 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 CURSADAS_FETCH_SUCCESS = "cursadas_fetch_success";

+ 54 - 0
src/components/Cursada.js

@@ -0,0 +1,54 @@
+import _ from 'lodash';
+import React, { Component } from 'react';
+import { Text, ListView, View } from 'react-native';
+import { connect } from 'react-redux';
+import { cursadaFetch } from '../actions/';
+import { Card, CardSection } from './common';
+
+class Cursada extends Component  {
+
+	componentWillMount() {
+    this.props.cursadaFetch(this.props);
+    this.createDataSource(this.props);
+	}
+	componentWillReceiveProps(nextProps) {
+		this.createDataSource(nextProps);
+	}
+  createDataSource({cursada}){
+    const { clases } = cursada;
+    const ds = new ListView.DataSource({
+      rowHasChanged: (r1,r2) => r1 !== r2
+    });
+    this.dataSource = ds.cloneWithRows(clases);
+  }
+
+  renderRow(data) {
+		return (
+      <CardSection>
+        <Text>{data.titulo}</Text>
+      </CardSection>
+    );
+	}
+
+	render() {
+    const { cursada } = this.props;
+		return (
+      <View>
+        <CardSection>
+          <Text style={{fontSize:18}}>{cursada.titulo}</Text>
+        </CardSection>
+        <ListView
+          enableEmptySections
+          dataSource={this.dataSource}
+          renderRow={this.renderRow}
+        />
+      </View>
+		);
+	}
+};
+
+const mapStateToProps = state => {
+	return { cursada: state.cursadasR.curCursada };
+};
+
+export default connect(mapStateToProps, { cursadaFetch })(Cursada);

+ 3 - 2
src/components/ItemCursada.js

@@ -5,8 +5,8 @@ import { Button, Card, CardSection } from './common';
 
 class ItemCursada extends Component {
   onRowPress(){
-    console.log(this.props.data); //_id
-    //Actions.cursadaView( { _id: this.props.data._id } );
+    //console.log(this.props.data); //_id
+    Actions.ViewCursada( { _id: this.props.data._id } );
   }
 
   render() {
@@ -22,6 +22,7 @@ class ItemCursada extends Component {
 
           <CardSection>
             <Text>{data.descCorta}</Text>
+            <Text>Mas info</Text>
           </CardSection>
 
           <CardSection>

+ 0 - 4
src/components/ListaCursadas.js

@@ -28,8 +28,6 @@ class ListaCursadas extends Component  {
 	}
 
 	render() {
-    console.log("props");
-    console.log(this.props);
 		return (
       <ListView
         enableEmptySections
@@ -40,8 +38,6 @@ class ListaCursadas extends Component  {
 };
 
 const mapStateToProps = state => {
-  console.log("state");
-  console.log(state);
 	/*const cursadas = _.map(state.cursadas, (val, uid) => {
 		return { ...val, uid };
 	});*/

+ 6 - 2
src/reducers/CursadaReducer.js

@@ -1,17 +1,21 @@
 import {
+  CURSADAS_FETCH_SUCCESS,
   CURSADA_FETCH_SUCCESS
 } from '../actions/types';
 
 const INITIAL_STATE = {
   cursos: [],
-  cursadas: []
+  cursadas: [],
+  curCursada: { clases: [] }
 };
 
 export default (state = INITIAL_STATE, action) => {
   switch(action.type) {
-    case CURSADA_FETCH_SUCCESS:
+    case CURSADAS_FETCH_SUCCESS:
       const { cursadas, cursos } = action.payload;
       return { ...state, cursadas, cursos };
+    case CURSADA_FETCH_SUCCESS:
+      return { ...state, curCursada: action.payload };
     default:
       return state;
   }