21 | This is an info bar
22 | {' '}
23 | {info ? info.message : 'no info!'}
24 | {info && new Date(info.time).toString()}
25 |
26 |
27 |
28 | );
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/containers/Home/Home.scss:
--------------------------------------------------------------------------------
1 | @import "../../theme/variables.scss";
2 |
3 | .home {
4 | dd {
5 | margin-bottom: 15px;
6 | }
7 | }
8 | .masthead {
9 | background: #2d2d2d;
10 | padding: 40px 20px;
11 | color: white;
12 | text-align: center;
13 | .logo {
14 | $size: 200px;
15 | margin: auto;
16 | height: $size;
17 | width: $size;
18 | border-radius: $size / 2;
19 | border: 1px solid $cyan;
20 | box-shadow: inset 0 0 10px $cyan;
21 | vertical-align: middle;
22 | p {
23 | line-height: $size;
24 | margin: 0px;
25 | }
26 | img {
27 | width: 75%;
28 | margin: auto;
29 | }
30 | }
31 | h1 {
32 | color: $cyan;
33 | font-size: 4em;
34 | }
35 | h2 {
36 | color: #ddd;
37 | font-size: 2em;
38 | margin: 20px;
39 | }
40 | a {
41 | color: #ddd;
42 | }
43 | p {
44 | margin: 10px;
45 | }
46 | .humility {
47 | color: $humility;
48 | a {
49 | color: $humility;
50 | }
51 | }
52 | .github {
53 | font-size: 1.5em;
54 | }
55 | }
56 |
57 | .counterContainer {
58 | text-align: center;
59 | margin: 20px;
60 | }
61 |
--------------------------------------------------------------------------------
/src/components/GithubButton/GithubButton.js:
--------------------------------------------------------------------------------
1 | import React, {Component, PropTypes} from 'react';
2 |
3 | export default class GithubButton extends Component {
4 | static propTypes = {
5 | user: PropTypes.string.isRequired,
6 | repo: PropTypes.string.isRequired,
7 | type: PropTypes.oneOf(['star', 'watch', 'fork', 'follow']).isRequired,
8 | width: PropTypes.number.isRequired,
9 | height: PropTypes.number.isRequired,
10 | count: PropTypes.bool,
11 | large: PropTypes.bool
12 | }
13 |
14 | render() {
15 | const {user, repo, type, width, height, count, large} = this.props;
16 | let src = `https://ghbtns.com/github-btn.html?user=${user}&repo=${repo}&type=${type}`;
17 | if (count) {
18 | src += '&count=true';
19 | }
20 | if (large) {
21 | src += '&size=large';
22 | }
23 | return (
24 |
31 | );
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Erik Rasmussen
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/helpers/makeRouteHooksSafe.js:
--------------------------------------------------------------------------------
1 | import { createRoutes } from 'react-router/lib/RouteUtils';
2 |
3 | // Wrap the hooks so they don't fire if they're called before
4 | // the store is initialised. This only happens when doing the first
5 | // client render of a route that has an onEnter hook
6 | function makeHooksSafe(routes, store) {
7 | if (Array.isArray(routes)) {
8 | return routes.map((route) => makeHooksSafe(route, store));
9 | }
10 |
11 | const onEnter = routes.onEnter;
12 |
13 | if (onEnter) {
14 | routes.onEnter = function safeOnEnter(...args) {
15 | try {
16 | store.getState();
17 | } catch (err) {
18 | if (onEnter.length === 3) {
19 | args[2]();
20 | }
21 |
22 | // There's no store yet so ignore the hook
23 | return;
24 | }
25 |
26 | onEnter.apply(null, args);
27 | };
28 | }
29 |
30 | if (routes.childRoutes) {
31 | makeHooksSafe(routes.childRoutes, store);
32 | }
33 |
34 | if (routes.indexRoute) {
35 | makeHooksSafe(routes.indexRoute, store);
36 | }
37 |
38 | return routes;
39 | }
40 |
41 | export default function makeRouteHooksSafe(_getRoutes) {
42 | return (store) => makeHooksSafe(createRoutes(_getRoutes(store)), store);
43 | }
44 |
--------------------------------------------------------------------------------
/src/containers/LoginSuccess/LoginSuccess.js:
--------------------------------------------------------------------------------
1 | import React, {Component, PropTypes} from 'react';
2 | import {connect} from 'react-redux';
3 | import * as authActions from 'redux/modules/auth';
4 |
5 | @connect(
6 | state => ({user: state.auth.user}),
7 | authActions)
8 | export default
9 | class LoginSuccess extends Component {
10 | static propTypes = {
11 | user: PropTypes.object,
12 | logout: PropTypes.func
13 | }
14 |
15 | render() {
16 | const {user, logout} = this.props;
17 | return (user &&
18 |
19 |
Login Success
20 |
21 |
22 |
Hi, {user.name}. You have just successfully logged in, and were forwarded here
23 | by componentWillReceiveProps() in App.js, which is listening to
24 | the auth reducer via redux @connect. How exciting!
25 |
26 |
27 |
28 | The same function will forward you to / should you chose to log out. The choice is yours...
29 |
This will "log you in" as this user, storing the username in the session of the API server.
38 |
39 | }
40 | {user &&
41 |
42 |
You are currently logged in as {user.name}.
43 |
44 |
45 |
46 |
47 |
48 | }
49 |
50 | );
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/redux/middleware/transitionMiddleware.js:
--------------------------------------------------------------------------------
1 | import {ROUTER_DID_CHANGE} from 'redux-router/lib/constants';
2 | import getDataDependencies from '../../helpers/getDataDependencies';
3 |
4 | const locationsAreEqual = (locA, locB) => (locA.pathname === locB.pathname) && (locA.search === locB.search);
5 |
6 | export default ({getState, dispatch}) => next => action => {
7 | if (action.type === ROUTER_DID_CHANGE) {
8 | if (getState().router && locationsAreEqual(action.payload.location, getState().router.location)) {
9 | return next(action);
10 | }
11 |
12 | const {components, location, params} = action.payload;
13 | const promise = new Promise((resolve) => {
14 |
15 | const doTransition = () => {
16 | next(action);
17 | Promise.all(getDataDependencies(components, getState, dispatch, location, params, true))
18 | .then(resolve)
19 | .catch(error => {
20 | // TODO: You may want to handle errors for fetchDataDeferred here
21 | console.warn('Warning: Error in fetchDataDeferred', error);
22 | return resolve();
23 | });
24 | };
25 |
26 | Promise.all(getDataDependencies(components, getState, dispatch, location, params))
27 | .then(doTransition)
28 | .catch(error => {
29 | // TODO: You may want to handle errors for fetchData here
30 | console.warn('Warning: Error in fetchData', error);
31 | return doTransition();
32 | });
33 | });
34 |
35 | if (__SERVER__) {
36 | // router state is null until ReduxRouter is created so we can use this to store
37 | // our promise to let the server know when it can render
38 | getState().router = promise;
39 | }
40 |
41 | return promise;
42 | }
43 |
44 | return next(action);
45 | };
46 |
--------------------------------------------------------------------------------
/src/components/__tests__/InfoBar-test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import {renderIntoDocument} from 'react-addons-test-utils';
4 | import { expect} from 'chai';
5 | import { InfoBar } from 'components';
6 | import { Provider } from 'react-redux';
7 | import {reduxReactRouter} from 'redux-router';
8 | import createHistory from 'history/lib/createMemoryHistory';
9 | import createStore from 'redux/create';
10 | import ApiClient from 'helpers/ApiClient';
11 | const client = new ApiClient();
12 |
13 | describe('InfoBar', () => {
14 | const mockStore = {
15 | info: {
16 | load: () => {},
17 | loaded: true,
18 | loading: false,
19 | data: {
20 | message: 'This came from the api server',
21 | time: Date.now()
22 | }
23 | }
24 | };
25 |
26 | const store = createStore(reduxReactRouter, null, createHistory, client, mockStore);
27 | const renderer = renderIntoDocument(
28 |
29 |
30 |
31 | );
32 | const dom = ReactDOM.findDOMNode(renderer);
33 |
34 | it('should render correctly', () => {
35 | return expect(renderer).to.be.ok;
36 | });
37 |
38 | it('should render with correct value', () => {
39 | const text = dom.getElementsByTagName('strong')[0].textContent;
40 | expect(text).to.equal(mockStore.info.data.message);
41 | });
42 |
43 | it('should render with a reload button', () => {
44 | const text = dom.getElementsByTagName('button')[0].textContent;
45 | expect(text).to.be.a('string');
46 | });
47 |
48 | it('should render the correct className', () => {
49 | const styles = require('components/InfoBar/InfoBar.scss');
50 | expect(styles.infoBar).to.be.a('string');
51 | expect(dom.className).to.include(styles.infoBar);
52 | });
53 |
54 | });
55 |
--------------------------------------------------------------------------------
/src/containers/About/About.js:
--------------------------------------------------------------------------------
1 | import React, {Component} from 'react';
2 | import DocumentMeta from 'react-document-meta';
3 | import { MiniInfoBar } from 'components';
4 |
5 | export default class About extends Component {
6 | state = {
7 | showKitten: false
8 | }
9 |
10 | handleToggleKitten() {
11 | this.setState({showKitten: !this.state.showKitten});
12 | }
13 |
14 | render() {
15 | const {showKitten} = this.state;
16 | const kitten = require('./kitten.jpg');
17 | return (
18 |
19 |
About Us
20 |
21 |
22 |
This project was orginally created by Erik Rasmussen
23 | (@erikras), but has since seen many contributions
24 | from the open source community. Thank you to all the contributors.
27 |
28 |
29 |
Mini Bar (not that kind)
30 |
31 |
Hey! You found the mini info bar! The following component is display-only. Note that it shows the same
32 | time as the info bar.
33 |
34 |
35 |
36 |
Images
37 |
38 |
39 | Psst! Would you like to see a kitten?
40 |
41 |
45 |
46 |
47 | {showKitten &&
}
48 |
49 | );
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/theme/bootstrap.config.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Bootstrap configuration for bootstrap-sass-loader
3 | *
4 | * Scripts are disabled to not load jQuery.
5 | * If you depend on Bootstrap scripts consider react-bootstrap instead.
6 | * https://github.com/react-bootstrap/react-bootstrap
7 | *
8 | * In order to keep the bundle size low in production
9 | * disable components you don't use.
10 | *
11 | */
12 |
13 | module.exports = {
14 | preBootstrapCustomizations: './src/theme/variables.scss',
15 | mainSass: './src/theme/bootstrap.overrides.scss',
16 | verbose: false,
17 | debug: false,
18 | scripts: {
19 | transition: false,
20 | alert: false,
21 | button: false,
22 | carousel: false,
23 | collapse: false,
24 | dropdown: false,
25 | modal: false,
26 | tooltip: false,
27 | popover: false,
28 | scrollspy: false,
29 | tab: false,
30 | affix: false
31 | },
32 | styles: {
33 | mixins: true,
34 | normalize: true,
35 | print: true,
36 | glyphicons: true,
37 | scaffolding: true,
38 | type: true,
39 | code: true,
40 | grid: true,
41 | tables: true,
42 | forms: true,
43 | buttons: true,
44 | 'component-animations': true,
45 | dropdowns: true,
46 | 'button-groups': true,
47 | 'input-groups': true,
48 | navs: true,
49 | navbar: true,
50 | breadcrumbs: true,
51 | pagination: true,
52 | pager: true,
53 | labels: true,
54 | badges: true,
55 | jumbotron: true,
56 | thumbnails: true,
57 | alerts: true,
58 | 'progress-bars': true,
59 | media: true,
60 | 'list-group': true,
61 | panels: true,
62 | wells: true,
63 | 'responsive-embed': true,
64 | close: true,
65 | modals: true,
66 | tooltip: true,
67 | popovers: true,
68 | carousel: true,
69 | utilities: true,
70 | 'responsive-utilities': true
71 | }
72 | };
73 |
--------------------------------------------------------------------------------
/src/helpers/__tests__/getDataDependencies-test.js:
--------------------------------------------------------------------------------
1 | import { expect } from 'chai';
2 | import React from 'react';
3 | import { div } from 'react-dom';
4 | import getDataDependencies from '../getDataDependencies';
5 |
6 | describe('getDataDependencies', () => {
7 | let getState;
8 | let dispatch;
9 | let location;
10 | let params;
11 | let CompWithFetchData;
12 | let CompWithNoData;
13 | let CompWithFetchDataDeferred;
14 | const NullComponent = null;
15 |
16 | beforeEach(() => {
17 | getState = 'getState';
18 | dispatch = 'dispatch';
19 | location = 'location';
20 | params = 'params';
21 |
22 | CompWithNoData = () =>
23 | ;
24 |
25 | CompWithFetchData = () =>
26 | ;
27 |
28 | CompWithFetchData.fetchData = (_getState, _dispatch, _location, _params) => {
29 | return `fetchData ${_getState} ${_dispatch} ${_location} ${_params}`;
30 | };
31 | CompWithFetchDataDeferred = () =>
32 | ;
33 |
34 | CompWithFetchDataDeferred.fetchDataDeferred = (_getState, _dispatch, _location, _params) => {
35 | return `fetchDataDeferred ${_getState} ${_dispatch} ${_location} ${_params}`;
36 | };
37 | });
38 |
39 | it('should get fetchDatas', () => {
40 | const deps = getDataDependencies([
41 | NullComponent,
42 | CompWithFetchData,
43 | CompWithNoData,
44 | CompWithFetchDataDeferred
45 | ], getState, dispatch, location, params);
46 |
47 | expect(deps).to.deep.equal([
48 | 'fetchData getState dispatch location params'
49 | ]);
50 | });
51 |
52 | it('should get fetchDataDeferreds', () => {
53 | const deps = getDataDependencies([
54 | NullComponent,
55 | CompWithFetchData,
56 | CompWithNoData,
57 | CompWithFetchDataDeferred
58 | ], getState, dispatch, location, params, true);
59 |
60 | expect(deps).to.deep.equal([
61 | 'fetchDataDeferred getState dispatch location params'
62 | ]);
63 | });
64 | });
65 |
--------------------------------------------------------------------------------
/src/utils/validation.js:
--------------------------------------------------------------------------------
1 | const isEmpty = value => value === undefined || value === null || value === '';
2 | const join = (rules) => (value, data) => rules.map(rule => rule(value, data)).filter(error => !!error)[0 /* first error */ ];
3 |
4 | export function email(value) {
5 | // Let's not start a debate on email regex. This is just for an example app!
6 | if (!isEmpty(value) && !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(value)) {
7 | return 'Invalid email address';
8 | }
9 | }
10 |
11 | export function required(value) {
12 | if (isEmpty(value)) {
13 | return 'Required';
14 | }
15 | }
16 |
17 | export function minLength(min) {
18 | return value => {
19 | if (!isEmpty(value) && value.length < min) {
20 | return `Must be at least ${min} characters`;
21 | }
22 | };
23 | }
24 |
25 | export function maxLength(max) {
26 | return value => {
27 | if (!isEmpty(value) && value.length > max) {
28 | return `Must be no more than ${max} characters`;
29 | }
30 | };
31 | }
32 |
33 | export function integer(value) {
34 | if (!Number.isInteger(Number(value))) {
35 | return 'Must be an integer';
36 | }
37 | }
38 |
39 | export function oneOf(enumeration) {
40 | return value => {
41 | if (!~enumeration.indexOf(value)) {
42 | return `Must be one of: ${enumeration.join(', ')}`;
43 | }
44 | };
45 | }
46 |
47 | export function match(field) {
48 | return (value, data) => {
49 | if (data) {
50 | if (value !== data[field]) {
51 | return 'Do not match';
52 | }
53 | }
54 | };
55 | }
56 |
57 | export function createValidator(rules) {
58 | return (data = {}) => {
59 | const errors = {};
60 | Object.keys(rules).forEach((key) => {
61 | const rule = join([].concat(rules[key])); // concat enables both functions and arrays of functions
62 | const error = rule(data[key], data);
63 | if (error) {
64 | errors[key] = error;
65 | }
66 | });
67 | return errors;
68 | };
69 | }
70 |
--------------------------------------------------------------------------------
/karma.conf.js:
--------------------------------------------------------------------------------
1 | var webpack = require('webpack');
2 |
3 | module.exports = function (config) {
4 | config.set({
5 |
6 | browsers: ['PhantomJS'],
7 |
8 | singleRun: !!process.env.CONTINUOUS_INTEGRATION,
9 |
10 | frameworks: [ 'mocha' ],
11 |
12 | files: [
13 | './node_modules/phantomjs-polyfill/bind-polyfill.js',
14 | 'tests.webpack.js'
15 | ],
16 |
17 | preprocessors: {
18 | 'tests.webpack.js': [ 'webpack', 'sourcemap' ]
19 | },
20 |
21 | reporters: [ 'mocha' ],
22 |
23 | plugins: [
24 | require("karma-webpack"),
25 | require("karma-mocha"),
26 | require("karma-mocha-reporter"),
27 | require("karma-phantomjs-launcher"),
28 | require("karma-sourcemap-loader")
29 | ],
30 |
31 | webpack: {
32 | devtool: 'inline-source-map',
33 | module: {
34 | loaders: [
35 | { test: /\.(jpe?g|png|gif|svg)$/, loader: 'url', query: {limit: 10240} },
36 | { test: /\.js$/, exclude: /node_modules/, loaders: ['babel']},
37 | { test: /\.json$/, loader: 'json-loader' },
38 | { test: /\.less$/, loader: 'style!css!less' },
39 | { test: /\.scss$/, loader: 'style!css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!sass?outputStyle=expanded&sourceMap' }
40 | ]
41 | },
42 | resolve: {
43 | modulesDirectories: [
44 | 'src',
45 | 'node_modules'
46 | ],
47 | extensions: ['', '.json', '.js']
48 | },
49 | plugins: [
50 | new webpack.IgnorePlugin(/\.json$/),
51 | new webpack.NoErrorsPlugin(),
52 | new webpack.DefinePlugin({
53 | __CLIENT__: true,
54 | __SERVER__: false,
55 | __DEVELOPMENT__: true,
56 | __DEVTOOLS__: false // <-------- DISABLE redux-devtools HERE
57 | })
58 | ]
59 | },
60 |
61 | webpackServer: {
62 | noInfo: true
63 | }
64 |
65 | });
66 | };
67 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing Guidelines
2 |
3 | Some basic conventions for this project.
4 |
5 | ### General
6 |
7 | Please make sure that there aren't existing pull requests attempting to address the issue mentioned. Likewise, please check for issues related to update, as someone else may be working on the issue in a branch or fork.
8 |
9 | * Non-trivial changes should be discussed in an issue first
10 | * Develop in a topic branch, not master
11 | * Squash your commits
12 |
13 | ### Linting
14 |
15 | Please check your code using `eslint` before submitting your pull requests, as the CI build will fail if `eslint` fails.
16 |
17 | ### Commit Message Format
18 |
19 | Each commit message should include a **type**, a **scope** and a **subject**:
20 |
21 | ```
22 | ():
23 | ```
24 |
25 | Lines should not exceed 100 characters. This allows the message to be easier to read on github as well as in various git tools and produces a nice, neat commit log ie:
26 |
27 | ```
28 | #459 refactor(utils): create url mapper utility function
29 | #463 chore(webpack): update to isomorphic tools v2
30 | #494 fix(babel): correct dependencies and polyfills
31 | #510 feat(app): add react-bootstrap responsive navbar
32 | ```
33 |
34 | #### Type
35 |
36 | Must be one of the following:
37 |
38 | * **feat**: A new feature
39 | * **fix**: A bug fix
40 | * **docs**: Documentation only changes
41 | * **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing
42 | semi-colons, etc)
43 | * **refactor**: A code change that neither fixes a bug or adds a feature
44 | * **test**: Adding missing tests
45 | * **chore**: Changes to the build process or auxiliary tools and libraries such as documentation
46 | generation
47 |
48 | #### Scope
49 |
50 | The scope could be anything specifying place of the commit change. For example `webpack`,
51 | `helpers`, `api` etc...
52 |
53 | #### Subject
54 |
55 | The subject contains succinct description of the change:
56 |
57 | * use the imperative, present tense: "change" not "changed" nor "changes"
58 | * don't capitalize first letter
59 | * no dot (.) at the end
60 |
--------------------------------------------------------------------------------
/src/client.js:
--------------------------------------------------------------------------------
1 | /**
2 | * THIS IS THE ENTRY POINT FOR THE CLIENT, JUST LIKE server.js IS THE ENTRY POINT FOR THE SERVER.
3 | */
4 | import 'babel/polyfill';
5 | import React from 'react';
6 | import ReactDOM from 'react-dom';
7 | import createHistory from 'history/lib/createBrowserHistory';
8 | import createStore from './redux/create';
9 | import ApiClient from './helpers/ApiClient';
10 | import io from 'socket.io-client';
11 | import {Provider} from 'react-redux';
12 | import {reduxReactRouter, ReduxRouter} from 'redux-router';
13 |
14 | import getRoutes from './routes';
15 | import makeRouteHooksSafe from './helpers/makeRouteHooksSafe';
16 |
17 | const client = new ApiClient();
18 |
19 | const dest = document.getElementById('content');
20 | const store = createStore(reduxReactRouter, makeRouteHooksSafe(getRoutes), createHistory, client, window.__data);
21 |
22 | function initSocket() {
23 | const socket = io('', {path: '/api/ws', transports: ['polling']});
24 | socket.on('news', (data) => {
25 | console.log(data);
26 | socket.emit('my other event', { my: 'data from client' });
27 | });
28 | socket.on('msg', (data) => {
29 | console.log(data);
30 | });
31 |
32 | return socket;
33 | }
34 |
35 | global.socket = initSocket();
36 |
37 | const component = (
38 |
39 | );
40 |
41 | ReactDOM.render(
42 |
43 | {component}
44 | ,
45 | dest
46 | );
47 |
48 | if (process.env.NODE_ENV !== 'production') {
49 | window.React = React; // enable debugger
50 |
51 | if (!dest || !dest.firstChild || !dest.firstChild.attributes || !dest.firstChild.attributes['data-react-checksum']) {
52 | console.error('Server-side React render was discarded. Make sure that your initial render does not contain any client-side code.');
53 | }
54 | }
55 |
56 | if (__DEVTOOLS__) {
57 | const DevTools = require('./containers/DevTools/DevTools');
58 | ReactDOM.render(
59 |
60 |