-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP for moving header to React with shared store
Bugs and TODOs: 1. Turbolinks is preventing the proper header link changes. If you open links in different tabs, you get mostly correct behavior. 2. When you open the /simple in a different tab, the header is not highlighted.
- Loading branch information
Showing
29 changed files
with
605 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
5.0.0 | ||
5.10.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
// All webpack assets in development will be loaded via webpack dev server | ||
|
||
// turbolinks comes from npm and is listed in webpack.client.base.config.js | ||
|
||
//= require rails_startup |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
client/app/bundles/comments/components/Navigationbar/CommentsCount.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React, {PropTypes} from 'react'; | ||
|
||
const CommentsCount = (props) => ( | ||
<li> | ||
<a id='js-comment-count' | ||
href='https://github.com/shakacode/react_on_rails/blob/master/README.md#multiple-react-components-on-a-page-with-one-store'> | ||
Comments: {props.commentsCount} | ||
</a> | ||
</li> | ||
); | ||
|
||
CommentsCount.propTypes = { | ||
commentsCount: PropTypes.number.isRequired, | ||
}; | ||
|
||
export default CommentsCount; |
72 changes: 72 additions & 0 deletions
72
client/app/bundles/comments/components/Navigationbar/Navigationbar.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React, {PropTypes} from 'react'; | ||
import ReactOnRails from 'react-on-rails'; | ||
import classNames from 'classnames'; | ||
import CommentsCount from './CommentsCount'; | ||
|
||
const NavigationBar = (props) => { | ||
console.log("ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"); | ||
console.log("NavigationBar, props = ", props); | ||
console.log("ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"); | ||
|
||
const {commentsCount, pathname} = props; | ||
|
||
return ( | ||
<nav className="navbar navbar-default" role="navigation"> | ||
<div className="container"> | ||
<div className="navbar-header"> | ||
<button | ||
type="button" | ||
className="navbar-toggle" | ||
data-toggle="collapse" | ||
data-target="#bs-example-navbar-collapse-1" | ||
> | ||
<span className="sr-only">Toggle navigation</span> | ||
<span className="icon-bar"/> | ||
<span className="icon-bar"/> | ||
<span className="icon-bar"/> | ||
</button> | ||
<a className="navbar-brand" href="http://www.shakacode.com">ShakaCode</a> | ||
</div> | ||
<div className="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> | ||
<ul className="nav navbar-nav"> | ||
<li className={classNames({ active: (pathname === '/') })}><a href="/">React Router Demo</a></li> | ||
<li className={classNames({ active: (pathname === '/no-router') })}><a href="/no-router">React Demo</a></li> | ||
<li className={classNames({ active: (pathname === '/simple') })}><a href="/simple">Simple React</a></li> | ||
<li className={classNames({ active: (pathname === '/comments') })}><a href="/comments">Classic Rails</a></li> | ||
<li> | ||
<a href={ | ||
'https://github.com/' + | ||
'shakacode/react-webpack-rails-tutorial' | ||
}> | ||
Source on Github | ||
</a> | ||
</li> | ||
<li> | ||
<a href={ | ||
'http://www.railsonmaui.com/' + | ||
'blog/2014/10/03/integrating' + | ||
'-webpack-and-the-es6-transpiler' + | ||
'-into-an-existing-rails-project/' | ||
}>Tutorials</a> | ||
</li> | ||
<li> | ||
<a href={ | ||
'http://forum.shakacode.com/' + | ||
't/fast-rich-client-rails-development' + | ||
'-with-webpack-and-the-es6-transpiler/82/22' | ||
}>Forum</a> | ||
</li> | ||
{commentsCount && CommentsCount({ commentsCount })} | ||
</ul> | ||
</div> | ||
</div> | ||
</nav> | ||
); | ||
} | ||
|
||
NavigationBar.propTypes = { | ||
commentsCount: PropTypes.number.isRequired, | ||
pathname: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default NavigationBar; |
37 changes: 37 additions & 0 deletions
37
client/app/bundles/comments/containers/NavigationBarContainer.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { PropTypes } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { bindActionCreators } from 'redux'; | ||
|
||
import NavigationBar from '../components/NavigationBar/NavigationBar'; | ||
import * as commentsActionCreators from '../actions/commentsActionCreators'; | ||
import BaseComponent from 'libs/components/BaseComponent'; | ||
|
||
function stateToProps(state) { | ||
// Which part of the Redux global state does our component want to receive as props? | ||
if (state.$$commentsStore) { | ||
return { | ||
commentsCount: state.$$commentsStore.get('$$comments').size, | ||
pathname: state.railsContext.pathname, | ||
}; | ||
} else { | ||
return { }; | ||
} | ||
} | ||
|
||
class NavigationBarContainer extends BaseComponent { | ||
static propTypes = { | ||
commentsCount: PropTypes.number.isRequired, | ||
pathname: PropTypes.string.isRequired, | ||
}; | ||
|
||
render() { | ||
const { commentsCount, pathname } = this.props; | ||
|
||
return ( | ||
<NavigationBar {...{commentsCount, pathname}} /> | ||
); | ||
} | ||
} | ||
|
||
// Don't forget to actually use connect! | ||
export default connect(stateToProps)(NavigationBarContainer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import commentsReducer from './commentsReducer'; | ||
import railsContextReducer from './railsContextReducer'; | ||
import { $$initialState as $$commentsState } from './commentsReducer'; | ||
import { initialState as railsContextState } from './railsContextReducer'; | ||
|
||
export default { | ||
$$commentsStore: commentsReducer, | ||
railsContext: railsContextReducer, | ||
}; | ||
|
||
export const initalStates = { | ||
$$commentsState, | ||
railsContextState, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const initialState = {} | ||
|
||
export default function railsContextReducer(state = initialState, action = null) { | ||
return state; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Top level component for client side. | ||
// Compare this to the ./ServerApp.jsx file which is used for server side rendering. | ||
|
||
import React from 'react'; | ||
import ReactOnRails from 'react-on-rails'; | ||
import NavigationBar from '../components/NavigationBar/NavigationBar'; | ||
import NavigationBarContainer from '../containers/NavigationBarContainer'; | ||
import { Provider } from 'react-redux'; | ||
|
||
/* | ||
* Export a function that returns a ReactComponent, depending on a store named SharedReduxStore. | ||
* This is used for the client rendering hook after the page html is rendered. | ||
* React will see that the state is the same and not do anything. | ||
*/ | ||
export default (_props, _railsContext) => { | ||
// This is where we get the existing store. | ||
const stores = ReactOnRails.stores(); | ||
let store; | ||
store = ReactOnRails.getStore('routerCommentsStore', false); | ||
if (!store) { | ||
store = ReactOnRails.getStore('commentsStore', false); | ||
} | ||
|
||
if (!store) { | ||
return ( | ||
<NavigationBar /> | ||
); | ||
} | ||
|
||
return ( | ||
<Provider store={store}> | ||
<NavigationBarContainer /> | ||
</Provider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
|
||
import createStore from '../store/commentsStore'; | ||
import NonRouterCommentsContainer from '../containers/NonRouterCommentsContainer'; | ||
import NavigationBarContainer from '../containers/NavigationBarContainer'; | ||
|
||
export default props => { | ||
const store = createStore(props); | ||
export default (_props, _rails_context) => { | ||
const store = ReactOnRails.getStore('commentsStore'); | ||
return ( | ||
<Provider store={store}> | ||
<NonRouterCommentsContainer /> | ||
<NavigationBarContainer /> | ||
</Provider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.