diff --git a/imports/api/mensajes.js b/imports/api/mensajes.js
index edaacd7..c9ae25d 100644
--- a/imports/api/mensajes.js
+++ b/imports/api/mensajes.js
@@ -19,8 +19,8 @@ Meteor.methods({
check(idChat, String);
//el usuario tiene que estar loggineado
- if (!this.userId) {
- throw new Meteor.Error('not-authorized');
+ if (/*!this.userId ¿esta variable de donde sale?*/ !Meteor.user()) {
+ /*si lo hace con throw, el error se lanza en el server*/return new Meteor.Error('not-authorized');
}
Mensajes.insert({
mensaje,
@@ -30,4 +30,4 @@ Meteor.methods({
username: Meteor.users.findOne(this.userId).username,
});
}
-});
\ No newline at end of file
+});
diff --git a/imports/api/viajes.js b/imports/api/viajes.js
index 221df09..7691b69 100644
--- a/imports/api/viajes.js
+++ b/imports/api/viajes.js
@@ -28,7 +28,7 @@ Meteor.methods({
check(precio, String);
// El usuario debe estar loggineado
- if (!this.userId) {
+ if (!Meteor.user()/*this.userId usar Meteor.user()*/ ) {
throw new Meteor.Error('not-authorized');
}
@@ -41,8 +41,8 @@ Meteor.methods({
cantidad,
precio,
createdAt: new Date(),
- owner: this.userId,
- username: Meteor.users.findOne(this.userId).username
+ owner: Meteor.user()._id,
+ username: Meteor.users.findOne(Meteor.user()._id).username
});
},
@@ -51,7 +51,7 @@ Meteor.methods({
check(viajeId, String);
const viaje = Viajes.findOne(viajeId);
- if (viaje.owner !== this.userId) {
+ if (viaje.owner !== Meteor.user()._id) {
// If the task is private, make sure only the owner can delete it
throw new Meteor.Error('not-authorized');
}
@@ -66,4 +66,4 @@ Meteor.methods({
const numero = parseInt(viaje.cantidad, 10) - 1 + "";
Viajes.update(viajeId, { $set: { cantidad: numero } });
}
-});
\ No newline at end of file
+});
diff --git a/imports/client/routes.js b/imports/client/routes.js
index e68c8cb..0132573 100644
--- a/imports/client/routes.js
+++ b/imports/client/routes.js
@@ -8,7 +8,7 @@ import Home from '../ui/Home.js';
import MensajeApp from '../ui/MensajeApp.js';
import NewUserForm from '../ui/NewUserForm.js';
import SignIn from '../ui/SignIn.js';
-import NewCompanieForm from '../ui/NewCompanieForm.js';
+import NewCompanyForm from '../ui/NewCompanieForm.js';
//Se crean dos rutas, la principal y la de mensajes. En cada uno se renderiza su componente respectivo
Meteor.startup(() => {
@@ -19,10 +19,10 @@ Meteor.startup(() => {
-
+
,
document.getElementById('render-target')
);
-});
\ No newline at end of file
+});
diff --git a/imports/ui/AccountsUIWrapper.js b/imports/ui/AccountsUIWrapper.js
index 6781b77..878eeff 100644
--- a/imports/ui/AccountsUIWrapper.js
+++ b/imports/ui/AccountsUIWrapper.js
@@ -7,7 +7,7 @@ export default class AccountsUIWrapper extends Component {
componentDidMount() {
// Use Meteor Blaze to render login buttons
this.view = Blaze.render(Template.loginButtons,
- ReactDOM.findDOMNode(this.refs.container));
+ ReactDOM.findDOMNode(this.container /*updated declaration*/));
}
componentWillUnmount() {
// Clean up Blaze view
@@ -15,6 +15,6 @@ export default class AccountsUIWrapper extends Component {
}
render() {
// Just render a placeholder container that will be filled in
- return ;
+ return this.container = ref /*Updating deprecated ref declaration*/} />;
}
-}
\ No newline at end of file
+}
diff --git a/imports/ui/App.js b/imports/ui/App.js
index eaae600..a3ebd5a 100644
--- a/imports/ui/App.js
+++ b/imports/ui/App.js
@@ -62,7 +62,7 @@ class App extends Component {
//se utiliza para que un card pueda actulizar el state del APP.JS y poner en su state el id de la publicacion
//y asi saber qué chat abrir con el botón.
- chatId(id) {
+ setChatId(id) { /*Se le puede poner un mejor nombre al método*/
this.setState({
idChat: id
});
@@ -75,7 +75,9 @@ class App extends Component {
renderCards() {
let filteredViajes = this.props.viajes;
- if (this.state.verLlenos) {
+ //Ver llenos significa mostrar los que tienen cupo y los que no (es decir, mostrar todos)
+ if (!this.state.verLlenos) {
+ //Si no se van a ver los llenos, entonces hay que retornar los que tengan cantidad > 0
filteredViajes = filteredViajes.filter(viaje => viaje.cantidad > 0);
}
@@ -84,7 +86,7 @@ class App extends Component {
);
@@ -115,7 +117,8 @@ class App extends Component {
readOnly
checked={this.state.verLleno}
onClick={this.toggleVerLlenos}
- />
Ver viajes llenos
+ /> {/* Respetar la jerarquía! 'Ver viajes llenos' no es el encabezado de una sección
Ver viajes llenos
, también no hay ningún h4 definido, no es correcto saltarse de h3 a h5 */}
+ Ver viajes llenos
: ''}
@@ -126,7 +129,8 @@ class App extends Component {
: ''}
{/*boton para entrar en la sala de chats*/}
- {this.props.currentUser && (this.state.idChat != null) ?
+ {/* this.props.currentUser && (this.state.idChat !== null) cuidado usando '!=', se debe usar '!==', tamibén, es más sencillo: */
+ this.props.currentUser && this.state.idChat ?
{this.renderRedirect()}
@@ -160,4 +164,4 @@ export default withTracker(() => {
viajes: Viajes.find({}, { sort: { createdAt: -1 } }).fetch(),
currentUser: Meteor.user()
};
-})(App);
\ No newline at end of file
+})(App);
diff --git a/imports/ui/CardMensaje.js b/imports/ui/CardMensaje.js
index 1a9fde6..ac40f0e 100644
--- a/imports/ui/CardMensaje.js
+++ b/imports/ui/CardMensaje.js
@@ -1,7 +1,8 @@
import React, { Component } from 'react';
+import PropTypes from 'prop-types';
//el card de un mensaje
-export default class CardMensaje extends Component {
+class CardMensaje extends Component {
render() {
return (
@@ -14,4 +15,11 @@ export default class CardMensaje extends Component {
)
}
-}
\ No newline at end of file
+}
+
+//Set component propTypes
+CardMensaje.propTypes = {
+ mensaje: PropTypes.object.isRequired
+};
+
+export default CardMensaje;
diff --git a/imports/ui/CardViaje.js b/imports/ui/CardViaje.js
index ab32a80..bcea181 100644
--- a/imports/ui/CardViaje.js
+++ b/imports/ui/CardViaje.js
@@ -1,8 +1,9 @@
import React, { Component } from 'react';
import { Meteor } from 'meteor/meteor';
+import PropTypes from 'prop-types';
//el card de un viaje
-export default class CardViaje extends Component {
+class CardViaje extends Component {
constructor(props) {
super(props);
this.reservarCupo = this.reservarCupo.bind(this);
@@ -34,10 +35,10 @@ export default class CardViaje extends Component {
Precio (pesos): {this.props.viaje.precio}
{/*boton para reservar un cupo*/}
- {parseInt(this.props.viaje.cantidad, 10) > 0 ?
+ {parseInt(this.props.viaje.cantidad /*más sencillo*/) > 0 ?
)
}
-}
\ No newline at end of file
+}
+
+CardViaje.propTypes = {
+ viaje: PropTypes.object,
+ establecerChat: PropTypes.func,
+ idOwner: PropTypes.string
+};
+export default CardViaje;
diff --git a/imports/ui/Home.js b/imports/ui/Home.js
index dd49b13..4596178 100644
--- a/imports/ui/Home.js
+++ b/imports/ui/Home.js
@@ -24,7 +24,7 @@ class Home extends Component {
if (this.state.redirectNewCompany) {
return ;
}
@@ -111,13 +111,14 @@ class Home extends Component {
+ {/*Ojo con la jerarquía! no saltarse los h3*/}
-
Register companies and users
+
Register companies and users
Sign up now and start enjoying!
@@ -128,7 +129,7 @@ class Home extends Component {
-
Share journeys
+
Share journeys
Create carpooling entry and wait for your co-workers to join.
@@ -139,7 +140,7 @@ class Home extends Component {
-
Join journeys
+
Join journeys
Join other`s journey with a single click!
@@ -152,4 +153,4 @@ class Home extends Component {
}
}
-export default Home;
\ No newline at end of file
+export default Home;
diff --git a/imports/ui/InsertarForm.js b/imports/ui/InsertarForm.js
index cc7b4e2..c6b647d 100644
--- a/imports/ui/InsertarForm.js
+++ b/imports/ui/InsertarForm.js
@@ -10,6 +10,7 @@ export default class InsertarForm extends Component {
registrarViaje() {
+ //¡Se pueden usar refs para evitar esto y queda mucho más simple!
const origen = document.getElementById("origen").value;
const destino = document.getElementById("destino").value;
const ruta = document.getElementById("routeToTake").value;
@@ -17,9 +18,13 @@ export default class InsertarForm extends Component {
const tiempo = document.getElementById("timeLeaving").value;
const cantidad = document.getElementById("cantidadCupos").value;
const precio = document.getElementById("precioViaje").value;
-
- Meteor.call('viajes.insert', origen, destino, ruta, fecha, tiempo, cantidad, precio);
- this.props.ocultar();
+
+ //No creo que sea buena idea pasarle DOM elements a el servidor (en Node puede ser peligroso manipularlos, porque no hay interfaz gráfica)
+ Meteor.call('viajes.insert', origen, destino, ruta, fecha, tiempo, cantidad, precio, (err) =>{
+ if(err) return alert(err);
+ //Si hay un error, y no se va a ocultar
+ this.props.ocultar();
+ });
}
render() {
@@ -59,4 +64,4 @@ export default class InsertarForm extends Component {
)
}
-}
\ No newline at end of file
+}
diff --git a/imports/ui/MensajeApp.js b/imports/ui/MensajeApp.js
index a5250c4..2952711 100644
--- a/imports/ui/MensajeApp.js
+++ b/imports/ui/MensajeApp.js
@@ -86,6 +86,12 @@ class MensajeApp extends Component {
{this.renderRedirect()}
+
+ {/*mensajes reenderizados*/}
+
+ {this.renderMensajes()}
+
+
{/*el espacio para ingresar un nuevo mensaje*/}
- {/*mensajes reenderizados*/}
-
- {this.renderMensajes()}
-
);
@@ -117,4 +121,4 @@ export default withTracker(() => {
return {
mensajes: Mensajes.find({}, { sort: { createdAt: -1 } }).fetch(),
};
-})(MensajeApp);
\ No newline at end of file
+})(MensajeApp);
diff --git a/imports/ui/NewCompanieForm.js b/imports/ui/NewCompanieForm.js
index f35ec6c..707a137 100644
--- a/imports/ui/NewCompanieForm.js
+++ b/imports/ui/NewCompanieForm.js
@@ -42,7 +42,7 @@ export default class NewCompanieForm extends Component {
renderError( )
{
- if(this.state.error !== '')
+ if(this.state.error /*así es suficiente*/)
{
return(