mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
use ReactRouter
This commit is contained in:
@@ -35,8 +35,18 @@ class SideNav extends React.Component {
|
|||||||
openModal(Preferences)
|
openModal(Preferences)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleHomeButtonClick (e) {
|
||||||
|
let { router } = this.context
|
||||||
|
router.push('/repositories')
|
||||||
|
}
|
||||||
|
|
||||||
|
handleStarredButtonClick (e) {
|
||||||
|
let { router } = this.context
|
||||||
|
router.push('/starred')
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
let { repositories, dispatch } = this.props
|
let { repositories, dispatch, location } = this.props
|
||||||
let repositorieElements = repositories.map((repo) => {
|
let repositorieElements = repositories.map((repo) => {
|
||||||
return <RepositorySection
|
return <RepositorySection
|
||||||
key={repo.key}
|
key={repo.key}
|
||||||
@@ -44,6 +54,8 @@ class SideNav extends React.Component {
|
|||||||
dispatch={dispatch}
|
dispatch={dispatch}
|
||||||
/>
|
/>
|
||||||
})
|
})
|
||||||
|
let isHomeActive = location.pathname.match(/^\/home$/)
|
||||||
|
let isStarredActive = location.pathname.match(/^\/starred$/)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -60,13 +72,15 @@ class SideNav extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div styleName='menu'>
|
<div styleName='menu'>
|
||||||
<button styleName='menu-button'
|
<button styleName={isHomeActive ? 'menu-button--active' : 'menu-button'}
|
||||||
|
onClick={(e) => this.handleHomeButtonClick(e)}
|
||||||
>
|
>
|
||||||
<i className='fa fa-home'/> Home
|
<i className='fa fa-home'/> Home
|
||||||
</button>
|
</button>
|
||||||
<button styleName='menu-button'
|
<button styleName={isStarredActive ? 'menu-button--active' : 'menu-button'}
|
||||||
|
onClick={(e) => this.handleStarredButtonClick(e)}
|
||||||
>
|
>
|
||||||
<i className='fa fa-star'/> Favorited
|
<i className='fa fa-star'/> Starred
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -84,6 +98,10 @@ class SideNav extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SideNav.contextTypes = {
|
||||||
|
router: PropTypes.shape({})
|
||||||
|
}
|
||||||
|
|
||||||
SideNav.propTypes = {
|
SideNav.propTypes = {
|
||||||
dispatch: PropTypes.func,
|
dispatch: PropTypes.func,
|
||||||
repositories: PropTypes.array
|
repositories: PropTypes.array
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export default class MainContainer extends React.Component {
|
|||||||
{this.state.updateAvailable ? (
|
{this.state.updateAvailable ? (
|
||||||
<button onClick={this.updateApp} className='appUpdateButton'><i className='fa fa-cloud-download'/> Update available!</button>
|
<button onClick={this.updateApp} className='appUpdateButton'><i className='fa fa-cloud-download'/> Update available!</button>
|
||||||
) : null}
|
) : null}
|
||||||
<HomePage/>
|
<HomePage {...this.props}/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ import ReactDOM from 'react-dom'
|
|||||||
require('!!style!css!stylus?sourceMap!../styles/main/index.styl')
|
require('!!style!css!stylus?sourceMap!../styles/main/index.styl')
|
||||||
import activityRecord from 'browser/lib/activityRecord'
|
import activityRecord from 'browser/lib/activityRecord'
|
||||||
import fetchConfig from '../lib/fetchConfig'
|
import fetchConfig from '../lib/fetchConfig'
|
||||||
|
import { Router, Route, IndexRoute, IndexRedirect, hashHistory } from 'react-router'
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const ipc = electron.ipcRenderer
|
const ipc = electron.ipcRenderer
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
import { syncHistoryWithStore } from 'react-router-redux'
|
||||||
|
|
||||||
const remote = electron.remote
|
const remote = electron.remote
|
||||||
|
|
||||||
@@ -73,12 +75,26 @@ ipc.on('open-finder', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
let el = document.getElementById('content')
|
let el = document.getElementById('content')
|
||||||
|
const history = syncHistoryWithStore(hashHistory, store)
|
||||||
|
history.listen((location) => console.info(location))
|
||||||
ReactDOM.render((
|
ReactDOM.render((
|
||||||
<div>
|
<Provider store={store}>
|
||||||
<Provider store={store}>
|
<Router history={history}>
|
||||||
<Main/>
|
<Route path='/' component={Main}>
|
||||||
</Provider>
|
<IndexRedirect to='/home'/>
|
||||||
</div>
|
<Route path='home'/>
|
||||||
|
<Route path='starred'/>
|
||||||
|
<Route path='repositories'>
|
||||||
|
<IndexRedirect to='/home'/>
|
||||||
|
<Route path=':repositoryKey'>
|
||||||
|
<IndexRoute/>
|
||||||
|
<Route path='settings'/>
|
||||||
|
<Route path='folders/:folderKey'/>
|
||||||
|
</Route>
|
||||||
|
</Route>
|
||||||
|
</Route>
|
||||||
|
</Router>
|
||||||
|
</Provider>
|
||||||
), el, function () {
|
), el, function () {
|
||||||
let loadingCover = document.getElementById('loadingCover')
|
let loadingCover = document.getElementById('loadingCover')
|
||||||
loadingCover.parentNode.removeChild(loadingCover)
|
loadingCover.parentNode.removeChild(loadingCover)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { combineReducers, createStore } from 'redux'
|
import { combineReducers, createStore } from 'redux'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
import { syncHistoryWithStore, routerReducer } from 'react-router-redux'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Repositories
|
* Repositories
|
||||||
@@ -110,7 +111,8 @@ function repositories (state = initialRepositories, action) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let reducer = combineReducers({
|
let reducer = combineReducers({
|
||||||
repositories
|
repositories,
|
||||||
|
routing: routerReducer
|
||||||
})
|
})
|
||||||
|
|
||||||
let store = createStore(reducer)
|
let store = createStore(reducer)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
"font-awesome": "^4.3.0",
|
"font-awesome": "^4.3.0",
|
||||||
"fs-jetpack": "^0.7.0",
|
"fs-jetpack": "^0.7.0",
|
||||||
"highlight.js": "^9.3.0",
|
"highlight.js": "^9.3.0",
|
||||||
"lodash": "^3.10.1",
|
"lodash": "^4.11.1",
|
||||||
"markdown-it": "^6.0.1",
|
"markdown-it": "^6.0.1",
|
||||||
"markdown-it-checkbox": "^1.1.0",
|
"markdown-it-checkbox": "^1.1.0",
|
||||||
"markdown-it-emoji": "^1.1.1",
|
"markdown-it-emoji": "^1.1.1",
|
||||||
@@ -73,6 +73,8 @@
|
|||||||
"nib": "^1.1.0",
|
"nib": "^1.1.0",
|
||||||
"oh-my-cdn": "^0.1.1",
|
"oh-my-cdn": "^0.1.1",
|
||||||
"react-css-modules": "^3.7.6",
|
"react-css-modules": "^3.7.6",
|
||||||
|
"react-router": "^2.4.0",
|
||||||
|
"react-router-redux": "^4.0.4",
|
||||||
"standard": "^6.0.8",
|
"standard": "^6.0.8",
|
||||||
"style-loader": "^0.12.4",
|
"style-loader": "^0.12.4",
|
||||||
"stylus": "^0.52.4",
|
"stylus": "^0.52.4",
|
||||||
|
|||||||
Reference in New Issue
Block a user