Skip to content

Commit

Permalink
fix: update inline editor to show new edits on save
Browse files Browse the repository at this point in the history
needed to update redux flow to pass updated json content on successful save

fix #71
  • Loading branch information
erichartline committed Jun 5, 2019
1 parent 47e1172 commit 7e0071f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
9 changes: 5 additions & 4 deletions src/actions/editablePages.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ const savePageRequest = () => ({
},
})

const savePageSuccess = () => ({
const savePageSuccess = (json: Object) => ({
type: SAVE_PAGE_SUCCESS,
payload: {
isFetching: false,
json,
},
})

Expand Down Expand Up @@ -133,7 +134,7 @@ export const saveEditing = (id: string, body: Object, path: string) => async (
if (contentType && contentType.includes("application/vnd.api+json")) {
const json = await res.json()
if (res.ok) {
dispatch(savePageSuccess())
dispatch(savePageSuccess(json))
setTimeout(() => {
dispatch(push(`${path.slice(0, -5)}`))
}, 1000)
Expand Down Expand Up @@ -177,7 +178,7 @@ export const saveInlineEditing = (id: string, body: Object) => async (
if (contentType && contentType.includes("application/vnd.api+json")) {
const json = await res.json()
if (res.ok) {
dispatch(savePageSuccess())
dispatch(savePageSuccess(json))
} else {
if (process.env.NODE_ENV !== "production") {
printError(res, json)
Expand Down Expand Up @@ -218,7 +219,7 @@ export const addEditablePage = (body: Object, url: string) => async (
if (contentType && contentType.includes("application/vnd.api+json")) {
const json = await res.json()
if (res.ok) {
dispatch(savePageSuccess())
dispatch(savePageSuccess(json))
setTimeout(() => {
dispatch(push(url))
}, 1000)
Expand Down
15 changes: 7 additions & 8 deletions src/components/pages/About/SpecialThanks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import InlineEditor from "components/editor/InlineEditor"
import { fetchPage } from "actions/editablePages"
import { NAMESPACE } from "constants/namespace"

const slugName = `${NAMESPACE}-specialthanks`

type Props = {
/** Represents whether component is loading or not */
isFetching: boolean,
Expand All @@ -28,7 +30,7 @@ class SpecialThanks extends Component<Props> {
},
}
componentDidMount() {
this.props.fetchPage(`${NAMESPACE}-specialthanks`)
this.props.fetchPage(slugName)
}
render() {
const { isFetching, page } = this.props
Expand All @@ -47,13 +49,10 @@ class SpecialThanks extends Component<Props> {
}
}

const mapStateToProps = state => {
const slugName = `${NAMESPACE}-specialthanks`
return {
isFetching: state.editablePages.isFetching,
page: state.editablePages[slugName],
}
}
const mapStateToProps = state => ({
isFetching: state.editablePages.isFetching,
page: state.editablePages[slugName],
})

export default connect(
mapStateToProps,
Expand Down
15 changes: 7 additions & 8 deletions src/components/pages/About/TechnicalSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import InlineEditor from "components/editor/InlineEditor"
import { fetchPage } from "actions/editablePages"
import { NAMESPACE } from "constants/namespace"

const slugName = `${NAMESPACE}-technicalsummary`

type Props = {
/** Represents whether component is loading or not */
isFetching: boolean,
Expand All @@ -28,7 +30,7 @@ class TechnicalSummary extends Component<Props> {
},
}
componentDidMount() {
this.props.fetchPage(`${NAMESPACE}-technicalsummary`)
this.props.fetchPage(slugName)
}
render() {
const { isFetching, page } = this.props
Expand All @@ -47,13 +49,10 @@ class TechnicalSummary extends Component<Props> {
}
}

const mapStateToProps = state => {
const slugName = `${NAMESPACE}-technicalsummary`
return {
isFetching: state.editablePages.isFetching,
page: state.editablePages[slugName],
}
}
const mapStateToProps = state => ({
isFetching: state.editablePages.isFetching,
page: state.editablePages[slugName],
})

export default connect(
mapStateToProps,
Expand Down
2 changes: 2 additions & 0 deletions src/reducers/editablePages.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ const editablePagesReducer = (state: Object = initialState, action: Object) => {
isFetching: true,
}
case SAVE_PAGE_SUCCESS:
const slug = action.payload.json.data.attributes.slug
return {
...state,
isFetching: false,
error: null,
[slug]: action.payload.json,
}
case SAVE_PAGE_FAILURE:
return {
Expand Down

0 comments on commit 7e0071f

Please sign in to comment.