Skip to content

Commit 2427220

Browse files
committed
ADD: Integracion con react
Desarrollo de aplicacion de ejemplo utilizando react. issue #32
1 parent 9990c34 commit 2427220

9 files changed

Lines changed: 205 additions & 0 deletions

File tree

public/favicon.ico

24.3 KB
Binary file not shown.

public/index.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
<meta name="theme-color" content="#000000">
7+
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
8+
<!--
9+
manifest.json provides metadata used when your web app is added to the
10+
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
11+
-->
12+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
13+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
14+
<!--
15+
Notice the use of %PUBLIC_URL% in the tags above.
16+
It will be replaced with the URL of the `public` folder during the build.
17+
Only files inside the `public` folder can be referenced from the HTML.
18+
19+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
20+
work correctly both with client-side routing and a non-root public URL.
21+
Learn how to configure a non-root public URL by running `npm run build`.
22+
-->
23+
<title>React App</title>
24+
</head>
25+
<body>
26+
<noscript>
27+
You need to enable JavaScript to run this app.
28+
</noscript>
29+
<div id="root"></div>
30+
<!--
31+
This HTML file is a template.
32+
If you open it directly in the browser, you will see an empty page.
33+
34+
You can add webfonts, meta tags, or analytics to this file.
35+
The build step will place the bundled scripts into the <body> tag.
36+
37+
To begin the development, run `npm start` or `yarn start`.
38+
To create a production bundle, use `npm run build` or `yarn build`.
39+
-->
40+
</body>
41+
</html>

public/manifest.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "192x192",
8+
"type": "image/png"
9+
}
10+
],
11+
"start_url": "./index.html",
12+
"display": "standalone",
13+
"theme_color": "#000000",
14+
"background_color": "#ffffff"
15+
}

src/app/App.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.App {
2+
text-align: center;
3+
}
4+
5+
.Curso {
6+
background-color: #AEAEAE;
7+
width: 30em;
8+
margin: 1em auto;
9+
padding: 1em;
10+
border-radius: .3em;
11+
}

src/app/App.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React from "react";
2+
import "./App.css";
3+
import { graphql } from "react-apollo";
4+
import gql from "graphql-tag";
5+
6+
const App = (props) => {
7+
const { data } = props;
8+
let render = "";
9+
if (data.loading) {
10+
render = (
11+
<div className="App">
12+
<h1>Cargando</h1>
13+
</div>
14+
);
15+
} else {
16+
render = (
17+
<div className="App">
18+
<h1>Listado de Cursos</h1>
19+
{
20+
data.cursos.map(curso => (
21+
<div className="Curso">
22+
<h3>{curso.titulo}</h3>
23+
<p>{curso.descripcion}</p>
24+
<hr />
25+
<p>
26+
Profesor:
27+
{curso.profesor.nombre}
28+
</p>
29+
</div>
30+
))
31+
}
32+
</div>
33+
);
34+
}
35+
return render;
36+
};
37+
38+
const CursosQuery = gql`
39+
query CursosQuery {
40+
cursos {
41+
titulo
42+
descripcion
43+
raiting
44+
profesor {
45+
nombre
46+
}
47+
}
48+
}
49+
`;
50+
51+
export default graphql(CursosQuery, {
52+
options: {
53+
pollInterval: 2000,
54+
},
55+
})(App);

src/app/App.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import App from './App';
4+
5+
it('renders without crashing', () => {
6+
const div = document.createElement('div');
7+
ReactDOM.render(<App />, div);
8+
});

src/app/index.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
body {
2+
margin: 0;
3+
padding: 0;
4+
font-family: 'Lato', sans-serif;
5+
}

src/app/registerServiceWorker.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// In production, we register a service worker to serve assets from local cache.
2+
3+
// This lets the app load faster on subsequent visits in production, and gives
4+
// it offline capabilities. However, it also means that developers (and users)
5+
// will only see deployed updates on the "N+1" visit to a page, since previously
6+
// cached resources are updated in the background.
7+
8+
// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
9+
// This link also includes instructions on opting out of this behavior.
10+
11+
export default function register() {
12+
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
13+
window.addEventListener('load', () => {
14+
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
15+
navigator.serviceWorker
16+
.register(swUrl)
17+
.then(registration => {
18+
registration.onupdatefound = () => {
19+
const installingWorker = registration.installing;
20+
installingWorker.onstatechange = () => {
21+
if (installingWorker.state === 'installed') {
22+
if (navigator.serviceWorker.controller) {
23+
// At this point, the old content will have been purged and
24+
// the fresh content will have been added to the cache.
25+
// It's the perfect time to display a "New content is
26+
// available; please refresh." message in your web app.
27+
console.log('New content is available; please refresh.');
28+
} else {
29+
// At this point, everything has been precached.
30+
// It's the perfect time to display a
31+
// "Content is cached for offline use." message.
32+
console.log('Content is cached for offline use.');
33+
}
34+
}
35+
};
36+
};
37+
})
38+
.catch(error => {
39+
console.error('Error during service worker registration:', error);
40+
});
41+
});
42+
}
43+
}
44+
45+
export function unregister() {
46+
if ('serviceWorker' in navigator) {
47+
navigator.serviceWorker.ready.then(registration => {
48+
registration.unregister();
49+
});
50+
}
51+
}

src/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
import ApolloClient from "apollo-boost";
4+
import { ApolloProvider } from "react-apollo";
5+
import registerServiceWorker from "./app/registerServiceWorker";
6+
import App from "./app/App";
7+
import "./app/index.css";
8+
9+
const CLIENT_APOLLO = new ApolloClient({
10+
uri: "/api",
11+
});
12+
13+
14+
ReactDOM.render(
15+
<ApolloProvider client={CLIENT_APOLLO}>
16+
<App />
17+
</ApolloProvider>, document.getElementById("root"),
18+
);
19+
registerServiceWorker();

0 commit comments

Comments
 (0)