Skip to content

Commit

Permalink
Added Multilanguage and structure for future pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Salec committed Dec 19, 2017
1 parent f927a1c commit 5ba43ca
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 78 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Run ```npm install``` to download all the dependencies
* To generate production code, run ```npm run build```

#### TODO LIST
- [ ] Add multilanguage
- [X] Add multilanguage
- [ ] Show load on fetch times
- [ ] Update webpack
- [X] Publish --> Add ccs
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"repository": "git@github.com/Salec/SDRBuses.git",
"scripts": {
"start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
"build": "webpack -p --config ./webpack.prod.js --define process.env.NODE_ENV='\"production\"' --progress --colors --display-modules"
"build": "webpack -p --config ./webpack.prod.js --define process.env.NODE_ENV='\"production\"' --progress --colors --display-modules",
"extract": "i18n_extract",
"import": "i18n_import --translations=src/translations"
},
"license": "MIT",
"devDependencies": {
Expand Down Expand Up @@ -38,6 +40,7 @@
"react-router-dom": "^4.2.2",
"redux": "^3.7.2",
"redux-form": "^4.1.3",
"redux-i18n": "^1.5.11",
"redux-promise": "^0.5.3",
"underscore": "^1.8.3"
}
Expand Down
31 changes: 17 additions & 14 deletions src/components/about.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
/**
* Created by Fernando on 13/11/2017.
*/
import React, {Component} from 'react';
import PropTypes from 'prop-types';

export default class About extends Component {
render() {
return (<div>
<h3 className="text-center text-primary mt-2">Sobre esta página</h3>
<p className="text-left">
Proyecto de código abierto creado por Fernando Martín usando técnologias de react y redux
<h3 className="text-center text-primary mt-2">{this.context.t("About this page")}</h3>
<p className="text-left">{this.context.t("Open source project created by Fernando Martín García usign react and redux tecnologies")}
</p>
<p className="text-left">Puedes contribuir con el projecto en github:
<p className="text-left">{this.context.t("You can collaborate with the project in github:")}
<a target="_blank" href="https://github.com/Salec/SDRBuses">
<button type="button" className="ml-3 btn btn-outline-info m">
<svg height="32" version="1.1" viewBox="0 0 16 16" width="32">
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z">
<path
d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z">
</path>
</svg>
Colabora
{this.context.t("Collaborate")}
</button>
</a>

Expand All @@ -26,7 +24,7 @@ export default class About extends Component {
<div className="row justify-content-md-center">

<h6 className="col-md-auto mt-5">
Actuales Colaboradores
{this.context.t("Current Colaborators")}
</h6>
</div>

Expand All @@ -38,7 +36,8 @@ export default class About extends Component {
alt="Fernando Martín García"/>
<div className="card-body">
<h4 className="card-title">Fernando Martín García</h4>
<button type="button" className="btn btn-primary">Contacto</button>
<button type="button"
className="btn btn-primary">{this.context.t("Contacto")}</button>
<button type="button" className="btn btn-primary dropdown-toggle"
data-toggle="dropdown">
<span className="caret"/>
Expand All @@ -53,10 +52,11 @@ export default class About extends Component {
</div>
<div className="col-sm-3">
<div className="card">
<img className="card-img-top" src="" alt="Tu foto aquí"/>
<img className="card-img-top" src="" alt="Your photo here"/>
<div className="card-body">
<h4 className="card-title">Tu nombre aquí</h4>
<button type="button" className="btn btn-primary">Contacto</button>
<h4 className="card-title">{this.context.t("Your name here")}</h4>
<button type="button"
className="btn btn-primary">{this.context.t("Contact")}</button>
<button type="button" className="btn btn-primary dropdown-toggle"
data-toggle="dropdown">
<span className="caret"/>
Expand All @@ -69,4 +69,7 @@ export default class About extends Component {
</div>
);
}
}
About.contextTypes = {
t: PropTypes.func
}
6 changes: 4 additions & 2 deletions src/components/app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, {Component} from 'react';
import I18n from "redux-i18n";
import Main from './main'
import {translations} from '../translations/translations';

const App = () => (
<div>
<I18n translations={translations} initialLang="es">
<Main />
</div>
</I18n>
);
export default App
27 changes: 11 additions & 16 deletions src/components/buses_lines.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
/**
* Created by Fernando on 4/10/2017.
*/
import _ from 'underscore';
import React, {Component} from 'react';
import {connect} from 'react-redux';
import PropTypes from 'prop-types';
import {fecthListBuses} from '../actions/index';


class BusLines extends Component {

constructor(props) {
super(props);

this.state = { isOpen: false };
this.state = {isOpen: false};
}

toggleModal = () => {
Expand All @@ -35,24 +31,23 @@ class BusLines extends Component {
})
}

goto = (event) =>{
goto = (event) => {
this.props.history.push(event.target.parentElement.dataset.url)
}

render() {
if (!this.props.lines) {
return <div>Cargando...</div>
return <div>{this.context.t("Loading...")}</div>
}

return (<div>

<h3 className="text-center text-primary mt-2">Índice de líneas</h3>
<h3 className="text-center text-primary mt-2">{this.context.t("Line Index")}</h3>

<table className="table table-striped">
<thead>
<tr>
<th>Nombre</th>
<th>Linea</th>
<th>{this.context.t("Name")}</th>
<th>{this.context.t("Line")}</th>
</tr>
</thead>
<tbody>
Expand All @@ -65,18 +60,18 @@ class BusLines extends Component {
};

componentWillMount() {

this.props.fecthListBuses();
};
}

BusLines.contextTypes = {
t: PropTypes.func
}
function mapStateToProps(state) {
let order = _.sortBy(state.lines.busLines.resources, info =>{
let order = _.sortBy(state.lines.busLines.resources, info => {
return parseInt(info['dc:identifier']);
});
return {lines: order};

}


export default connect(mapStateToProps, {fecthListBuses})(BusLines);
22 changes: 22 additions & 0 deletions src/components/languageSelector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, {Component} from 'react';
import {connect} from 'react-redux';
import {setLanguage} from "redux-i18n";

class LanguageSelector extends Component {
render() {
return (
<div className="dropdown">
<button className="ml-2 btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Idioma
</button>
<div className="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a className="dropdown-item" onClick={() => {this.props.dispatch(setLanguage("es"))}} href="#">Español</a>
<a className="dropdown-item" onClick={() => {this.props.dispatch(setLanguage("en"))}} href="#">English</a>
</div>
</div>
);
}
}
export default connect(state => ({
lang: state.i18nState.lang,
}))(LanguageSelector)
22 changes: 14 additions & 8 deletions src/components/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {orderTimes} from '../auxFunctions/common';
import _ from 'underscore';
import PropTypes from 'prop-types';

export const MODAL_ID = 'myModal';

Expand All @@ -19,7 +20,8 @@ class Modal extends Component {
<div className="modal-dialog" role="document">
<div className="modal-content">
<div className="modal-header">
<h5 className="modal-title">Tiempo Parada {this.props.stop} - <b>{this.props.name}</b></h5>
<h5 className="modal-title">{this.context.t("Time for stop ")} {this.props.stop} -
<b>{this.props.name}</b></h5>
<button type="button" className="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">&times;</span>
Expand All @@ -33,7 +35,7 @@ class Modal extends Component {
</div>
<div className="modal-footer">
<button type="button" className="btn btn-secondary" data-dismiss="modal"
>Close
>{this.context.t("Close")}
</button>
</div>
</div>
Expand Down Expand Up @@ -63,13 +65,17 @@ class Modal extends Component {
}

}

}

}
Modal.contextTypes = {
t: PropTypes.func
}
function mapsStateToProps(state) {
return {time: state.lines.time,
stop: state.lines.stop,
name: state.lines.name
}
return {
time: state.lines.time,
stop: state.lines.stop,
name: state.lines.name
}
}
function mapDispatchToProps(dispatch) {
return bindActionCreators({fetchTimes: fetchTimes}, dispatch)
Expand Down
61 changes: 44 additions & 17 deletions src/components/navegation.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,81 @@
import React from 'react';
import { withRouter } from 'react-router-dom';
import {withRouter} from 'react-router-dom';
import {connect} from 'react-redux';
import {changeStop} from '../actions/index';
import LanguageSelector from "./languageSelector"
import PropTypes from 'prop-types';

const SCHEDULE = "http://www.tusantander.es/sites/tus.int.ayto-santander.es/files/tusinvierno2017_optimizado.pdf";
const MAP = "http://www.tusantander.es/sites/tus.int.ayto-santander.es/files/planos-red-lineas_1.pdf";
class Nav extends React.Component {
render() {
return (
<nav className="navbar navbar-expand-lg navbar-light bg-light " >
<button type="button" className="btn btn-outline-info" onClick={() =>{this.props.history.push('/')}}>Inicio</button>
<button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<nav className="navbar navbar-expand-lg navbar-light bg-light ">
<button type="button" className="btn btn-outline-info" onClick={() => {
this.props.history.push('/')
}}>{this.context.t("Home")}</button>
<button className="navbar-toggler" type="button" data-toggle="collapse"
data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"/>
</button>



<div className="navbar-collapse collapse " id="navbarSupportedContent">
<ul className="navbar-nav mr-auto">
<li className="nav-item dropdown">
<a className="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Más...
<a className="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{this.context.t("More...")}
</a>
<div className="dropdown-menu" aria-labelledby="downloadDropdown">
<a className="dropdown-item disabled" href="/fares">{this.context.t("Fares")}</a>
<a className="dropdown-item disabled" href="/recharge">{this.context.t("Where to top up")}</a>
<a className="dropdown-item" href="/about">{this.context.t("About the page")}</a>

</div>
</li>
</ul>

<ul className="navbar-nav">
<li className="nav-item dropdown">
<a className="nav-link dropdown-toggle" href="#" id="dowloadDropdown" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{this.context.t("Downloads")}
</a>
<div className="dropdown-menu" aria-labelledby="navbarDropdown">
<a target="_blank" className="dropdown-item" href={SCHEDULE}>Horarios</a>
<a target="_blank" className="dropdown-item" href={MAP}>Plano
General</a>
<div className="dropdown-divider"></div>
<a className="dropdown-item" href="/about">Acerca de la página</a>
<div className="dropdown-menu" aria-labelledby="dowloadDropdown">
<a target="_blank" className="dropdown-item"
href={SCHEDULE}>{this.context.t("Schedule")}</a>
<a target="_blank" className="dropdown-item" href={MAP}>{this.context.t("Map")}</a>
</div>
</li>
</ul>

<form className="form-inline my-2 my-lg-0" onSubmit={this.onFormSubmit}>
<input className="form-control mr-sm-2" type="number" min="0"
placeholder="Número Parada"/>
<button className="btn btn-outline-success my-2 my-sm-0" type="submit">Tiempo</button>
placeholder={this.context.t("Stop Number")}/>
<button className="btn btn-outline-success my-2 my-sm-0" type="submit">{this.context.t("Time")}</button>
</form>
<LanguageSelector/>
</div>
</nav>

);
}
onFormSubmit = (event) =>{

onFormSubmit = (event) => {
event.preventDefault();
this.props.changeStop({stop: event.target[0].value});
}

}
Nav.contextTypes = {
t: PropTypes.func
}
function mapsStateToProps(state) {
return {
stop: state.lines.stop,
}
}
Nav = withRouter(Nav);
export default connect(mapsStateToProps,{changeStop})(Nav);
export default connect(mapsStateToProps, {changeStop})(Nav);
Loading

0 comments on commit 5ba43ca

Please sign in to comment.