Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edit mode redux conversion #91

Merged
merged 1 commit into from
Mar 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/actions/actionTypes.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
// stuff
export const RECEIVE_STUFF = 'RECEIVE_STUFF'

// edit
export const EDIT_MODE_ENABLED = 'EDIT_MODE_ENABLED'
export const EDIT_MODE_DISABLED = 'EDIT_MODE_DISABLED'
17 changes: 17 additions & 0 deletions src/actions/edit.action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as actionTypes from './actionTypes'

function editModeEnabled() {
return { type: actionTypes.EDIT_MODE_ENABLED, payload: true }
}

function editModeDisabled() {
return { type: actionTypes.EDIT_MODE_DISABLED, payload: false }
}

export function enableEditMode() {
return dispatch => dispatch(editModeEnabled())
}

export function disableEditMode() {
return dispatch => dispatch(editModeDisabled())
}
3 changes: 2 additions & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { fetchStuff } from './stuff.action'
import { enableEditMode, disableEditMode } from './edit.action'

export { fetchStuff }
export { fetchStuff, enableEditMode, disableEditMode }
4 changes: 3 additions & 1 deletion src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
MapTimeline,
NavBar,
Login,
StuffList
StuffList,
Edit
} from './'
import { Api, storage } from './../utils'
import './../styles/App.css'
Expand Down Expand Up @@ -259,6 +260,7 @@ class App extends Component {
toggleSidebar={this.toggleSidebar}
/>
<StuffList />
<Edit />
{showLogin && (
<Login setLogin={this.setLogin} setShowLogin={this.setShowLogin} />
)}
Expand Down
14 changes: 14 additions & 0 deletions src/components/Edit.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React, { Component } from 'react'

export default class Edit extends Component {
render() {
const { isEditing, enableEditMode, disableEditMode } = this.props
return (
<div>
<button onClick={isEditing ? disableEditMode : enableEditMode}>
{isEditing ? 'disableEditMode' : 'enableEditMode'}
</button>
</div>
)
}
}
22 changes: 22 additions & 0 deletions src/components/Edit.container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { enableEditMode, disableEditMode } from './../actions'
import Edit from './Edit.component'

function mapStateToProps(state) {
return {
isEditing: state.edit.isEditing
}
}

function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
enableEditMode,
disableEditMode
},
dispatch
)
}

export default connect(mapStateToProps, mapDispatchToProps)(Edit)
4 changes: 3 additions & 1 deletion src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Interval from './Interval.component'
import Icon from './Icon.component'
import Login from './Login.component'
import StuffList from './StuffList.container'
import Edit from './Edit.container'

export {
App,
Expand All @@ -33,5 +34,6 @@ export {
Interval,
Icon,
Login,
StuffList
StuffList,
Edit
}
15 changes: 15 additions & 0 deletions src/reducers/edit.reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import initialState from './initialState'
import { EDIT_MODE_ENABLED, EDIT_MODE_DISABLED } from '../actions/actionTypes'

export default function edit(state = initialState.edit, action) {
switch (action.type) {
case EDIT_MODE_ENABLED:
case EDIT_MODE_DISABLED:
return {
...state,
isEditing: action.payload
}
default:
return state
}
}
5 changes: 4 additions & 1 deletion src/reducers/initialState.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const initialState = {
stuff: []
stuff: [],
edit: {
isEditing: false
}
}

export default initialState
2 changes: 2 additions & 0 deletions src/reducers/rootReducer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { combineReducers } from 'redux'
import { routerReducer } from 'react-router-redux'
import stuff from './stuff.reducer'
import edit from './edit.reducer'

const rootReducer = combineReducers({
stuff,
edit,
router: routerReducer
})

Expand Down