Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit 1f115e3

Browse files
committed
Updated example to use new approach
1 parent c6ea6fa commit 1f115e3

23 files changed

+652
-445
lines changed

.babelrc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"plugins": [
3+
[
4+
"@babel/plugin-transform-runtime",
5+
{
6+
"regenerator": true,
7+
}
8+
]
9+
],
10+
"presets": ["@babel/preset-env", "@babel/preset-react"]
11+
}

.eslintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
"version": "detect"
1717
}
1818
}
19-
}
19+
}

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ dist/
77
example/js/build.js
88

99
# coverage
10-
.nyc_output/
10+
.nyc_output/

example/css/default.css

-29
This file was deleted.

example/index.html

+26-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,32 @@
66

77
<meta name="viewport" content="width=device-width, initial-scale=1" />
88
<script type="text/javascript" src="js/build.js"></script>
9-
<link rel="stylesheet" type="text/css" href="css/default.css" />
9+
10+
<style type="text/css">
11+
* {
12+
margin: 0;
13+
padding: 0;
14+
overflow: hidden;
15+
}
16+
17+
body {
18+
background-color: rgba(0, 0, 0, 0.05);
19+
}
20+
21+
section.container {
22+
width: 100%;
23+
height: 100%;
24+
position: absolute;
25+
display: flex;
26+
align-items: center;
27+
justify-content: center;
28+
}
29+
30+
section.weather {
31+
transition: all 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
32+
}
33+
</style>
34+
1035
<link
1136
href="https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900,100italic,300italic,400italic,700italic,900italic"
1237
rel="stylesheet"

example/js/actions.js

-29
This file was deleted.
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { NavLink, withRouter } from 'react-router-dom';
4+
import * as utils from '../../utils';
5+
6+
function Countries({ list }) {
7+
return (
8+
<ul>
9+
<li className="title">Weather for:</li>
10+
11+
{list.map(name => {
12+
return (
13+
<li key={name}>
14+
<NavLink
15+
to={`/${utils.toSlug(name)}.html`}
16+
activeClassName="active"
17+
>
18+
{name}
19+
</NavLink>
20+
</li>
21+
);
22+
})}
23+
</ul>
24+
);
25+
}
26+
27+
Countries.propTypes = {
28+
list: PropTypes.arrayOf(PropTypes.string.isRequired).isRequired,
29+
};
30+
31+
export default withRouter(Countries);
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React, { useEffect } from 'react';
2+
import { bindActionCreators } from 'redux';
3+
import { connect } from 'react-redux';
4+
import PropTypes from 'prop-types';
5+
import DocumentTitle from 'react-document-title';
6+
import * as duck from '../../duck';
7+
import * as utils from '../../utils';
8+
import Countries from '../Countries';
9+
10+
function Country({ weather, country, countries, fetch }) {
11+
const { title, label, fahrenheit } = utils.getWeather(weather, country);
12+
useEffect(() => void fetch(country), [country]);
13+
14+
return (
15+
<DocumentTitle title={`Weather for ${country}`}>
16+
<span>
17+
<main>
18+
<img src={utils.getFilename(country)} alt={country} />
19+
<h1>{title}</h1>
20+
<h2 title={fahrenheit}>{label}</h2>
21+
<Countries list={countries} />
22+
</main>
23+
</span>
24+
</DocumentTitle>
25+
);
26+
}
27+
28+
Country.propTypes = {
29+
weather: PropTypes.array.isRequired,
30+
country: PropTypes.string.isRequired,
31+
countries: PropTypes.array.isRequired,
32+
fetch: PropTypes.func.isRequired,
33+
};
34+
35+
Country.defaultProps = { weather: null };
36+
37+
function mapStateToProps(state) {
38+
return state;
39+
}
40+
41+
function mapDispatchToProps(dispatch) {
42+
return bindActionCreators(duck.actions, dispatch);
43+
}
44+
45+
export default connect(
46+
mapStateToProps,
47+
mapDispatchToProps,
48+
)(Country);

example/js/components/Layout/index.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { connect } from 'react-redux';
4+
import { BrowserRouter, Route } from 'react-router-dom';
5+
import root from 'react-shadow';
6+
import * as utils from '../../utils';
7+
import Country from '../Country';
8+
import styles from './styles.css';
9+
10+
function Layout(props) {
11+
return (
12+
<BrowserRouter>
13+
<root.section className="weather">
14+
<style tyle="text/css">{styles}</style>
15+
<Route
16+
exact
17+
path="/"
18+
render={() => (
19+
<Country country={utils.pickRandom(props.countries)} />
20+
)}
21+
/>
22+
<Route
23+
exact
24+
path="/:country.html"
25+
render={({ match }) => (
26+
<Country country={match.params.country} />
27+
)}
28+
/>
29+
</root.section>
30+
</BrowserRouter>
31+
);
32+
}
33+
34+
Layout.propTypes = {
35+
countries: PropTypes.array.isRequired,
36+
};
37+
38+
function mapStateToProps(state) {
39+
return state;
40+
}
41+
42+
export default connect(mapStateToProps)(Layout);
File renamed without changes.

example/js/components/countries.js

-41
This file was deleted.

example/js/components/country.js

-97
This file was deleted.

0 commit comments

Comments
 (0)