Skip to content

Commit

Permalink
Move page/screen components to src/routes along with the routing info
Browse files Browse the repository at this point in the history
  • Loading branch information
koistya committed Mar 2, 2016
1 parent b1309b9 commit 6553936
Show file tree
Hide file tree
Showing 24 changed files with 328 additions and 153 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ visit our sponsors:
│ ├── /data/ # GraphQL server schema
│ ├── /decorators/ # Higher-order React components
│ ├── /public/ # Static files which are copied into the /build/public folder
│ ├── /routes/ # Page/screen components along with the routing information
│ ├── /stores/ # Stores contain the application state and logic
│ ├── /views/ # Express.js views for index and error pages
│ ├── /client.js # Client-side startup script
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@
"glob": "^7.0.0",
"jade-loader": "^0.8.0",
"jest-cli": "^0.8.2",
"jscs": "^2.10.1",
"jscs": "^2.11.0",
"json-loader": "^0.5.4",
"mkdirp": "^0.5.1",
"ncp": "^2.0.0",
"postcss": "^5.0.18",
"postcss": "^5.0.19",
"postcss-import": "^8.0.2",
"postcss-loader": "^0.8.1",
"postcss-scss": "^0.1.6",
Expand All @@ -80,8 +80,8 @@
"replace": "^0.3.0",
"url-loader": "^0.5.7",
"webpack": "^1.12.14",
"webpack-hot-middleware": "^2.8.1",
"webpack-middleware": "^1.4.0"
"webpack-hot-middleware": "^2.9.0",
"webpack-middleware": "^1.5.1"
},
"jest": {
"rootDir": "./src",
Expand Down
39 changes: 0 additions & 39 deletions src/components/ContactPage/ContactPage.js

This file was deleted.

6 changes: 0 additions & 6 deletions src/components/ContactPage/package.json

This file was deleted.

39 changes: 0 additions & 39 deletions src/components/LoginPage/LoginPage.js

This file was deleted.

6 changes: 0 additions & 6 deletions src/components/LoginPage/package.json

This file was deleted.

39 changes: 0 additions & 39 deletions src/components/RegisterPage/RegisterPage.js

This file was deleted.

6 changes: 0 additions & 6 deletions src/components/RegisterPage/package.json

This file was deleted.

39 changes: 39 additions & 0 deletions src/data/queries/news.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* React Starter Kit (https://www.reactstarterkit.com/)
*
* Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/

import { GraphQLList as List } from 'graphql';
import fetch from '../../core/fetch';
import NewsItemType from '../types/NewsItemType';

// React.js News Feed (RSS)
const url = 'http://ajax.googleapis.com/ajax/services/feed/load' +
'?v=1.0&num=10&q=https://reactjsnews.com/feed.xml';

let items = [];
let lastFetchTime = new Date(1970, 0, 1);

const news = {
type: new List(NewsItemType),
resolve() {
if ((new Date() - lastFetchTime) > 1000 * 60 * 10 /* 10 mins */) {
lastFetchTime = new Date();
fetch(url)
.then(response => response.json())
.then(data => {
if (data.responseStatus === 200) {
items = data.responseData.feed.entries;
}
});
}

return items;
},
};

export default news;
2 changes: 2 additions & 0 deletions src/data/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import {

import me from './queries/me';
import content from './queries/content';
import news from './queries/news';

const schema = new Schema({
query: new ObjectType({
name: 'Query',
fields: {
me,
content,
news,
},
}),
});
Expand Down
27 changes: 27 additions & 0 deletions src/data/types/NewsItemType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* React Starter Kit (https://www.reactstarterkit.com/)
*
* Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/

import {
GraphQLObjectType as ObjectType,
GraphQLString as StringType,
GraphQLNonNull as NonNull,
} from 'graphql';

const NewsItemType = new ObjectType({
name: 'NewsItem',
fields: {
title: { type: new NonNull(StringType) },
link: { type: new NonNull(StringType) },
author: { type: StringType },
publishedDate: { type: new NonNull(StringType) },
contentSnippet: { type: StringType },
},
});

export default NewsItemType;
18 changes: 10 additions & 8 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,25 @@ import Router from 'react-routing/src/Router';
import fetch from './core/fetch';
import App from './components/App';
import ContentPage from './components/ContentPage';
import ContactPage from './components/ContactPage';
import LoginPage from './components/LoginPage';
import RegisterPage from './components/RegisterPage';
import NotFoundPage from './components/NotFoundPage';
import ErrorPage from './components/ErrorPage';

const routes = [
require('./routes/home'),
require('./routes/contact'),
require('./routes/login'),
require('./routes/register'),
];

const router = new Router(on => {
on('*', async (state, next) => {
const component = await next();
return component && <App context={state.context}>{component}</App>;
});

on('/contact', async () => <ContactPage />);

on('/login', async () => <LoginPage />);

on('/register', async () => <RegisterPage />);
routes.forEach(route => {
on(route.path, route.action);
});

on('*', async (state) => {
const query = `/graphql?query={content(path:"${state.path}"){path,title,content,component}}`;
Expand Down
18 changes: 18 additions & 0 deletions src/routes/Contact/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* React Starter Kit (https://www.reactstarterkit.com/)
*
* Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/

import React from 'react';
import Contact from './Contact';

export const path = '/contact';
export const action = async (state) => {
const title = 'Contact Us';
state.context.onSetTitle(title);
return <Contact title={title} />;
};
43 changes: 43 additions & 0 deletions src/routes/Home/Home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* React Starter Kit (https://www.reactstarterkit.com/)
*
* Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/

import React, { PropTypes } from 'react';
import withStyles from 'isomorphic-style-loader/lib/withStyles';
import s from './Home.scss';

function Home({ news }) {
return (
<div className={s.root}>
<div className={s.container}>
<h1 className={s.title}>React.js News</h1>
<ul className={s.news}>
{news.map((item, index) => (
<li key={index} className={s.newsItem}>
<a href={item.link} className={s.newsTitle}>{item.title}</a>
<span
className={s.newsDesc}
dangerouslySetInnerHTML={{ __html: item.contentSnippet }}
/>
</li>
))}
</ul>
</div>
</div>
);
}

Home.propTypes = {
news: PropTypes.arrayOf(PropTypes.shape({
title: PropTypes.string.isRequired,
link: PropTypes.string.isRequired,
contentSnippet: PropTypes.string,
})).isRequired,
};

export default withStyles(Home, s);
38 changes: 38 additions & 0 deletions src/routes/Home/Home.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* React Starter Kit (https://www.reactstarterkit.com/)
*
* Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/

@import '../../components/variables.scss';

.root {
padding-left: 20px;
padding-right: 20px;
}

.container {
margin: 0 auto;
padding: 0 0 40px;
max-width: $max-content-width;
}

.news {
padding: 0;
}

.newsItem {
list-style-type: none;
padding-bottom: 6px;
}

.newsTitle {
font-size: 1.125em;
}

.newsTitle, .newsDesc {
display: block;
}
Loading

2 comments on commit 6553936

@rdewolff
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's so awkward to have components in your routes folder.

@koistya
Copy link
Member Author

@koistya koistya commented on 6553936 Jul 21, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.