Skip to content

Commit 330ea98

Browse files
committed
use ReactRouter
1 parent 652c1aa commit 330ea98

5 files changed

Lines changed: 50 additions & 12 deletions

File tree

browser/main/HomePage/SideNav/index.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,27 @@ class SideNav extends React.Component {
3535
openModal(Preferences)
3636
}
3737

38+
handleHomeButtonClick (e) {
39+
let { router } = this.context
40+
router.push('/repositories')
41+
}
42+
43+
handleStarredButtonClick (e) {
44+
let { router } = this.context
45+
router.push('/starred')
46+
}
47+
3848
render () {
39-
let { repositories, dispatch } = this.props
49+
let { repositories, dispatch, location } = this.props
4050
let repositorieElements = repositories.map((repo) => {
4151
return <RepositorySection
4252
key={repo.key}
4353
repository={repo}
4454
dispatch={dispatch}
4555
/>
4656
})
57+
let isHomeActive = location.pathname.match(/^\/home$/)
58+
let isStarredActive = location.pathname.match(/^\/starred$/)
4759

4860
return (
4961
<div
@@ -60,13 +72,15 @@ class SideNav extends React.Component {
6072
</div>
6173

6274
<div styleName='menu'>
63-
<button styleName='menu-button'
75+
<button styleName={isHomeActive ? 'menu-button--active' : 'menu-button'}
76+
onClick={(e) => this.handleHomeButtonClick(e)}
6477
>
6578
<i className='fa fa-home'/> Home
6679
</button>
67-
<button styleName='menu-button'
80+
<button styleName={isStarredActive ? 'menu-button--active' : 'menu-button'}
81+
onClick={(e) => this.handleStarredButtonClick(e)}
6882
>
69-
<i className='fa fa-star'/> Favorited
83+
<i className='fa fa-star'/> Starred
7084
</button>
7185
</div>
7286

@@ -84,6 +98,10 @@ class SideNav extends React.Component {
8498
}
8599
}
86100

101+
SideNav.contextTypes = {
102+
router: PropTypes.shape({})
103+
}
104+
87105
SideNav.propTypes = {
88106
dispatch: PropTypes.func,
89107
repositories: PropTypes.array

browser/main/Main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default class MainContainer extends React.Component {
2727
{this.state.updateAvailable ? (
2828
<button onClick={this.updateApp} className='appUpdateButton'><i className='fa fa-cloud-download'/> Update available!</button>
2929
) : null}
30-
<HomePage/>
30+
<HomePage {...this.props}/>
3131
</div>
3232
)
3333
}

browser/main/index.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import ReactDOM from 'react-dom'
66
require('!!style!css!stylus?sourceMap!../styles/main/index.styl')
77
import activityRecord from 'browser/lib/activityRecord'
88
import fetchConfig from '../lib/fetchConfig'
9+
import { Router, Route, IndexRoute, IndexRedirect, hashHistory } from 'react-router'
910
const electron = require('electron')
1011
const ipc = electron.ipcRenderer
1112
const path = require('path')
13+
import { syncHistoryWithStore } from 'react-router-redux'
1214

1315
const remote = electron.remote
1416

@@ -73,12 +75,26 @@ ipc.on('open-finder', function () {
7375
})
7476

7577
let el = document.getElementById('content')
78+
const history = syncHistoryWithStore(hashHistory, store)
79+
history.listen((location) => console.info(location))
7680
ReactDOM.render((
77-
<div>
78-
<Provider store={store}>
79-
<Main/>
80-
</Provider>
81-
</div>
81+
<Provider store={store}>
82+
<Router history={history}>
83+
<Route path='/' component={Main}>
84+
<IndexRedirect to='/home'/>
85+
<Route path='home'/>
86+
<Route path='starred'/>
87+
<Route path='repositories'>
88+
<IndexRedirect to='/home'/>
89+
<Route path=':repositoryKey'>
90+
<IndexRoute/>
91+
<Route path='settings'/>
92+
<Route path='folders/:folderKey'/>
93+
</Route>
94+
</Route>
95+
</Route>
96+
</Router>
97+
</Provider>
8298
), el, function () {
8399
let loadingCover = document.getElementById('loadingCover')
84100
loadingCover.parentNode.removeChild(loadingCover)

browser/main/store.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { combineReducers, createStore } from 'redux'
22
import _ from 'lodash'
3+
import { syncHistoryWithStore, routerReducer } from 'react-router-redux'
34

45
/**
56
* Repositories
@@ -110,7 +111,8 @@ function repositories (state = initialRepositories, action) {
110111
}
111112

112113
let reducer = combineReducers({
113-
repositories
114+
repositories,
115+
routing: routerReducer
114116
})
115117

116118
let store = createStore(reducer)

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"font-awesome": "^4.3.0",
4646
"fs-jetpack": "^0.7.0",
4747
"highlight.js": "^9.3.0",
48-
"lodash": "^3.10.1",
48+
"lodash": "^4.11.1",
4949
"markdown-it": "^6.0.1",
5050
"markdown-it-checkbox": "^1.1.0",
5151
"markdown-it-emoji": "^1.1.1",
@@ -73,6 +73,8 @@
7373
"nib": "^1.1.0",
7474
"oh-my-cdn": "^0.1.1",
7575
"react-css-modules": "^3.7.6",
76+
"react-router": "^2.4.0",
77+
"react-router-redux": "^4.0.4",
7678
"standard": "^6.0.8",
7779
"style-loader": "^0.12.4",
7880
"stylus": "^0.52.4",

0 commit comments

Comments
 (0)