|
|
@@ -3,7 +3,7 @@ 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';
|
|
|
+import { Card, CardSection, Button } from './common';
|
|
|
|
|
|
class Cursada extends Component {
|
|
|
|
|
|
@@ -14,20 +14,46 @@ class Cursada extends Component {
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
this.createDataSource(nextProps);
|
|
|
}
|
|
|
- createDataSource({cursada}){
|
|
|
- const { clases } = cursada;
|
|
|
+ createDataSource({clases}){
|
|
|
const ds = new ListView.DataSource({
|
|
|
rowHasChanged: (r1,r2) => r1 !== r2
|
|
|
});
|
|
|
this.dataSource = ds.cloneWithRows(clases);
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ renderButton(data) {
|
|
|
+ if (data.desactivada){
|
|
|
+ return <View />;
|
|
|
+ }
|
|
|
+ return (
|
|
|
+ <CardSection>
|
|
|
+ <Button>Ingresar</Button>
|
|
|
+ </CardSection>
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
renderRow(data) {
|
|
|
+ const fecha = new Date(data.fecha).toDateString();
|
|
|
return (
|
|
|
- <CardSection>
|
|
|
- <Text>{data.titulo}</Text>
|
|
|
- </CardSection>
|
|
|
+ <Card>
|
|
|
+ <CardSection>
|
|
|
+ <Text>{data.titulo}</Text>
|
|
|
+ </CardSection>
|
|
|
+
|
|
|
+ <CardSection>
|
|
|
+ <Text style={{flex:1}}>Profesor:</Text>
|
|
|
+ <Text style={{flex:1}}>{data.profesor.nombre} {data.profesor.apellido}</Text>
|
|
|
+ </CardSection>
|
|
|
+
|
|
|
+ <CardSection>
|
|
|
+ <Text style={{flex:1}}>Fecha:</Text>
|
|
|
+ <Text style={{flex:1}}>{fecha}</Text>
|
|
|
+ </CardSection>
|
|
|
+
|
|
|
+ {this.renderButton(data)}
|
|
|
+ </Card>
|
|
|
);
|
|
|
+ //<Text>{data.profesor._id}</Text>
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
@@ -35,20 +61,26 @@ class Cursada extends Component {
|
|
|
return (
|
|
|
<View>
|
|
|
<CardSection>
|
|
|
- <Text style={{fontSize:18}}>{cursada.titulo}</Text>
|
|
|
+ <Text style={{textAlign:'center', flex: 1, fontSize:18}}>{cursada.titulo}</Text>
|
|
|
</CardSection>
|
|
|
<ListView
|
|
|
enableEmptySections
|
|
|
dataSource={this.dataSource}
|
|
|
- renderRow={this.renderRow}
|
|
|
+ renderRow={this.renderRow.bind(this)}
|
|
|
/>
|
|
|
+
|
|
|
</View>
|
|
|
);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const mapStateToProps = state => {
|
|
|
- return { cursada: state.cursadasR.curCursada };
|
|
|
+ const { curCursada } = state.cursadasR;
|
|
|
+ const clases = _.partition(curCursada.clases, n => n.desactivada);
|
|
|
+ const inactivas = _.sortBy(clases[0], [ o => new Date(o.fecha) ]);
|
|
|
+ const activas = _.reverse(_.sortBy(clases[1], [ o => new Date(o.fecha) ]));
|
|
|
+
|
|
|
+ return { cursada: curCursada, clases: _.concat(activas,inactivas) };
|
|
|
};
|
|
|
|
|
|
export default connect(mapStateToProps, { cursadaFetch })(Cursada);
|