Skip to content
Snippets Groups Projects
Commit 94f72f60 authored by Jure's avatar Jure
Browse files

Split initial state into two reducers, collections and fragments.

parent ea5a2867
No related branches found
No related tags found
No related merge requests found
...@@ -24,5 +24,5 @@ export default class BlogpostCreator extends React.Component { ...@@ -24,5 +24,5 @@ export default class BlogpostCreator extends React.Component {
} }
BlogpostCreator.propTypes = { BlogpostCreator.propTypes = {
create: React.PropTypes.function create: React.PropTypes.func
} }
import React from 'react' import React from 'react'
import Immutable from 'immutable'
import Blogpost from './Blogpost' import Blogpost from './Blogpost'
import styles from '../scss/components/_blogpostList' import styles from '../scss/components/_blogpostList'
export default class BlogpostList extends React.Component { export default class BlogpostList extends React.Component {
render () { render () {
const blogposts = this.props.manages.toKeyedSeq().map((manage, key) => { const blogposts = this.props.blogposts.map((blogpost, key) => {
return (<Blogpost key={manage.get('id')} id={manage.get('id')} title={manage.getIn(['data', 'title'])} status={manage.getIn(['data', 'status'])}/>) return (<Blogpost key={blogpost.id} id={blogpost.id} title={blogpost.title} status={blogpost.status}/>)
}).toArray() })
return ( return (
<div className={styles['main-section']}> <div className={styles['list']}>
<h3 className={styles['main-section__header']}>Blog posts</h3> <h3 className={styles['header']}>Blog posts</h3>
{blogposts} {blogposts}
</div> </div>
) )
} }
} }
BlogpostList.propTypes = { manages: React.PropTypes.instanceOf(Immutable.OrderedMap) } BlogpostList.propTypes = {
blogposts: React.PropTypes.array
}
...@@ -7,20 +7,6 @@ import '../scss/main' ...@@ -7,20 +7,6 @@ import '../scss/main'
class App extends Component { class App extends Component {
constructor (props) { constructor (props) {
super(props) super(props)
this.handleDismissClick = this.handleDismissClick.bind(this)
}
renderErrorMessage () {
const { errorMessage } = this.props
if (!errorMessage) {
return null
}
return (
<p>
<b>{errorMessage}</b>
</p>
)
} }
render () { render () {
...@@ -30,7 +16,6 @@ class App extends Component { ...@@ -30,7 +16,6 @@ class App extends Component {
<p>{collection.title}</p> <p>{collection.title}</p>
<Navigation /> <Navigation />
<hr /> <hr />
{this.renderErrorMessage()}
{children} {children}
</div> </div>
) )
...@@ -42,7 +27,6 @@ App.propTypes = { ...@@ -42,7 +27,6 @@ App.propTypes = {
collection: PropTypes.object, collection: PropTypes.object,
// Injected by React Redux // Injected by React Redux
errorMessage: PropTypes.string, errorMessage: PropTypes.string,
resetErrorMessage: PropTypes.func.isRequired,
pushState: PropTypes.func.isRequired, pushState: PropTypes.func.isRequired,
inputValue: PropTypes.string.isRequired, inputValue: PropTypes.string.isRequired,
// Injected by React Router // Injected by React Router
...@@ -51,7 +35,7 @@ App.propTypes = { ...@@ -51,7 +35,7 @@ App.propTypes = {
function mapStateToProps (state) { function mapStateToProps (state) {
return { return {
collection: state.collection[0], collection: state.collections[0],
errorMessage: state.errorMessage, errorMessage: state.errorMessage,
inputValue: state.router.location.pathname.substring(1) inputValue: state.router.location.pathname.substring(1)
} }
......
...@@ -29,7 +29,7 @@ BlogManager.propTypes = { ...@@ -29,7 +29,7 @@ BlogManager.propTypes = {
function mapStateToProps (state) { function mapStateToProps (state) {
return { return {
blog: state.collection[0], blog: state.collections[0],
blogposts: state.fragments blogposts: state.fragments
} }
} }
......
...@@ -2,30 +2,32 @@ import { routerStateReducer as router } from 'redux-router' ...@@ -2,30 +2,32 @@ import { routerStateReducer as router } from 'redux-router'
import { combineReducers } from 'redux' import { combineReducers } from 'redux'
import * as ActionTypes from '../actions' import * as ActionTypes from '../actions'
const initialState = { const initialCollections = [{
collections: [{ title: 'Something',
title: 'Something', author: 'Jure',
author: 'Jure', fragments: [1, 2, 3]
fragments: [1, 2, 3] }]
}],
fragments: [ const initialFragments = [
{ {
id: 1, id: 1,
title: 'one', title: 'one',
source: 'hello' source: 'hello',
}, status: 'published'
{ },
id: 2, {
title: 'two', id: 2,
source: 'hellohi' title: 'two',
}, source: 'hellohi',
{ status: 'unpublished'
id: 3, },
title: 'three', {
source: 'hellothere' id: 3,
} title: 'three',
] source: 'hellothere',
} status: 'published'
}
]
// Updates error message to notify about the failed fetches. // Updates error message to notify about the failed fetches.
function errorMessage (state = null, action) { function errorMessage (state = null, action) {
...@@ -40,14 +42,17 @@ function errorMessage (state = null, action) { ...@@ -40,14 +42,17 @@ function errorMessage (state = null, action) {
return state return state
} }
function reducer (state = initialState, action) { function collections (state = initialCollections, action) {
// For now, don’t handle any actions return state
// and just return the state given to us. }
function fragments (state = initialFragments, action) {
return state return state
} }
const rootReducer = combineReducers({ const rootReducer = combineReducers({
reducer, collections,
fragments,
errorMessage, errorMessage,
router router
}) })
......
...@@ -14,7 +14,7 @@ import Create from './components/Create' ...@@ -14,7 +14,7 @@ import Create from './components/Create'
import Share from './components/Share' import Share from './components/Share'
export default ( export default (
<Route path='/' component={App}> <Route component={App}>
<Route path='/' component={Share}/> <Route path='/' component={Share}/>
<Route path='/admin'> <Route path='/admin'>
<Route path='manages' component={Manage} /> <Route path='manages' component={Manage} />
......
.list {
background: red;
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment