Skip to content

Commit 6553936

Browse files
committed
Move page/screen components to src/routes along with the routing info
1 parent b1309b9 commit 6553936

24 files changed

+328
-153
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ visit our sponsors:
4242
│ ├── /data/ # GraphQL server schema
4343
│ ├── /decorators/ # Higher-order React components
4444
│ ├── /public/ # Static files which are copied into the /build/public folder
45+
│ ├── /routes/ # Page/screen components along with the routing information
4546
│ ├── /stores/ # Stores contain the application state and logic
4647
│ ├── /views/ # Express.js views for index and error pages
4748
│ ├── /client.js # Client-side startup script

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@
6464
"glob": "^7.0.0",
6565
"jade-loader": "^0.8.0",
6666
"jest-cli": "^0.8.2",
67-
"jscs": "^2.10.1",
67+
"jscs": "^2.11.0",
6868
"json-loader": "^0.5.4",
6969
"mkdirp": "^0.5.1",
7070
"ncp": "^2.0.0",
71-
"postcss": "^5.0.18",
71+
"postcss": "^5.0.19",
7272
"postcss-import": "^8.0.2",
7373
"postcss-loader": "^0.8.1",
7474
"postcss-scss": "^0.1.6",
@@ -80,8 +80,8 @@
8080
"replace": "^0.3.0",
8181
"url-loader": "^0.5.7",
8282
"webpack": "^1.12.14",
83-
"webpack-hot-middleware": "^2.8.1",
84-
"webpack-middleware": "^1.4.0"
83+
"webpack-hot-middleware": "^2.9.0",
84+
"webpack-middleware": "^1.5.1"
8585
},
8686
"jest": {
8787
"rootDir": "./src",

src/components/ContactPage/ContactPage.js

-39
This file was deleted.

src/components/ContactPage/package.json

-6
This file was deleted.

src/components/LoginPage/LoginPage.js

-39
This file was deleted.

src/components/LoginPage/package.json

-6
This file was deleted.

src/components/RegisterPage/RegisterPage.js

-39
This file was deleted.

src/components/RegisterPage/package.json

-6
This file was deleted.

src/data/queries/news.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* React Starter Kit (https://www.reactstarterkit.com/)
3+
*
4+
* Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE.txt file in the root directory of this source tree.
8+
*/
9+
10+
import { GraphQLList as List } from 'graphql';
11+
import fetch from '../../core/fetch';
12+
import NewsItemType from '../types/NewsItemType';
13+
14+
// React.js News Feed (RSS)
15+
const url = 'http://ajax.googleapis.com/ajax/services/feed/load' +
16+
'?v=1.0&num=10&q=https://reactjsnews.com/feed.xml';
17+
18+
let items = [];
19+
let lastFetchTime = new Date(1970, 0, 1);
20+
21+
const news = {
22+
type: new List(NewsItemType),
23+
resolve() {
24+
if ((new Date() - lastFetchTime) > 1000 * 60 * 10 /* 10 mins */) {
25+
lastFetchTime = new Date();
26+
fetch(url)
27+
.then(response => response.json())
28+
.then(data => {
29+
if (data.responseStatus === 200) {
30+
items = data.responseData.feed.entries;
31+
}
32+
});
33+
}
34+
35+
return items;
36+
},
37+
};
38+
39+
export default news;

src/data/schema.js

+2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ import {
1414

1515
import me from './queries/me';
1616
import content from './queries/content';
17+
import news from './queries/news';
1718

1819
const schema = new Schema({
1920
query: new ObjectType({
2021
name: 'Query',
2122
fields: {
2223
me,
2324
content,
25+
news,
2426
},
2527
}),
2628
});

src/data/types/NewsItemType.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* React Starter Kit (https://www.reactstarterkit.com/)
3+
*
4+
* Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE.txt file in the root directory of this source tree.
8+
*/
9+
10+
import {
11+
GraphQLObjectType as ObjectType,
12+
GraphQLString as StringType,
13+
GraphQLNonNull as NonNull,
14+
} from 'graphql';
15+
16+
const NewsItemType = new ObjectType({
17+
name: 'NewsItem',
18+
fields: {
19+
title: { type: new NonNull(StringType) },
20+
link: { type: new NonNull(StringType) },
21+
author: { type: StringType },
22+
publishedDate: { type: new NonNull(StringType) },
23+
contentSnippet: { type: StringType },
24+
},
25+
});
26+
27+
export default NewsItemType;

src/routes.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@ import Router from 'react-routing/src/Router';
1212
import fetch from './core/fetch';
1313
import App from './components/App';
1414
import ContentPage from './components/ContentPage';
15-
import ContactPage from './components/ContactPage';
16-
import LoginPage from './components/LoginPage';
17-
import RegisterPage from './components/RegisterPage';
1815
import NotFoundPage from './components/NotFoundPage';
1916
import ErrorPage from './components/ErrorPage';
2017

18+
const routes = [
19+
require('./routes/home'),
20+
require('./routes/contact'),
21+
require('./routes/login'),
22+
require('./routes/register'),
23+
];
24+
2125
const router = new Router(on => {
2226
on('*', async (state, next) => {
2327
const component = await next();
2428
return component && <App context={state.context}>{component}</App>;
2529
});
2630

27-
on('/contact', async () => <ContactPage />);
28-
29-
on('/login', async () => <LoginPage />);
30-
31-
on('/register', async () => <RegisterPage />);
31+
routes.forEach(route => {
32+
on(route.path, route.action);
33+
});
3234

3335
on('*', async (state) => {
3436
const query = `/graphql?query={content(path:"${state.path}"){path,title,content,component}}`;

src/routes/Contact/index.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* React Starter Kit (https://www.reactstarterkit.com/)
3+
*
4+
* Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE.txt file in the root directory of this source tree.
8+
*/
9+
10+
import React from 'react';
11+
import Contact from './Contact';
12+
13+
export const path = '/contact';
14+
export const action = async (state) => {
15+
const title = 'Contact Us';
16+
state.context.onSetTitle(title);
17+
return <Contact title={title} />;
18+
};

src/routes/Home/Home.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* React Starter Kit (https://www.reactstarterkit.com/)
3+
*
4+
* Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE.txt file in the root directory of this source tree.
8+
*/
9+
10+
import React, { PropTypes } from 'react';
11+
import withStyles from 'isomorphic-style-loader/lib/withStyles';
12+
import s from './Home.scss';
13+
14+
function Home({ news }) {
15+
return (
16+
<div className={s.root}>
17+
<div className={s.container}>
18+
<h1 className={s.title}>React.js News</h1>
19+
<ul className={s.news}>
20+
{news.map((item, index) => (
21+
<li key={index} className={s.newsItem}>
22+
<a href={item.link} className={s.newsTitle}>{item.title}</a>
23+
<span
24+
className={s.newsDesc}
25+
dangerouslySetInnerHTML={{ __html: item.contentSnippet }}
26+
/>
27+
</li>
28+
))}
29+
</ul>
30+
</div>
31+
</div>
32+
);
33+
}
34+
35+
Home.propTypes = {
36+
news: PropTypes.arrayOf(PropTypes.shape({
37+
title: PropTypes.string.isRequired,
38+
link: PropTypes.string.isRequired,
39+
contentSnippet: PropTypes.string,
40+
})).isRequired,
41+
};
42+
43+
export default withStyles(Home, s);

src/routes/Home/Home.scss

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* React Starter Kit (https://www.reactstarterkit.com/)
3+
*
4+
* Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE.txt file in the root directory of this source tree.
8+
*/
9+
10+
@import '../../components/variables.scss';
11+
12+
.root {
13+
padding-left: 20px;
14+
padding-right: 20px;
15+
}
16+
17+
.container {
18+
margin: 0 auto;
19+
padding: 0 0 40px;
20+
max-width: $max-content-width;
21+
}
22+
23+
.news {
24+
padding: 0;
25+
}
26+
27+
.newsItem {
28+
list-style-type: none;
29+
padding-bottom: 6px;
30+
}
31+
32+
.newsTitle {
33+
font-size: 1.125em;
34+
}
35+
36+
.newsTitle, .newsDesc {
37+
display: block;
38+
}

0 commit comments

Comments
 (0)