mirror of
https://github.com/wassname/talk.git
synced 2026-07-15 11:26:58 +08:00
update state correctly. save to server correctly
This commit is contained in:
@@ -49,12 +49,11 @@ export const fetchSettings = () => dispatch => {
|
||||
}
|
||||
|
||||
export const updateSettings = settings => {
|
||||
console.log('updated settings', settings)
|
||||
return {type: SETTINGS_UPDATED, settings}
|
||||
}
|
||||
|
||||
export const saveSettingsToServer = (dispatch, getState) => {
|
||||
const settings = getState().settings.settings
|
||||
export const saveSettingsToServer = () => (dispatch, getState) => {
|
||||
const settings = getState().settings.toJS().settings
|
||||
dispatch({type: SAVE_SETTINGS_LOADING})
|
||||
fetch(`${base}/settings`, getInit('PUT', settings))
|
||||
.then(handleResp)
|
||||
|
||||
@@ -113,10 +113,6 @@ class Configure extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
settings: state.settings.toJS()
|
||||
}
|
||||
}
|
||||
const mapStateToProps = state => state.settings.toJS()
|
||||
|
||||
export default connect(mapStateToProps)(Configure)
|
||||
|
||||
@@ -12,9 +12,9 @@ const initialState = Map({
|
||||
export default (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case types.SETTINGS_LOADING: return state.set('fetchingSettings', true).set('fetchSettingsError', null)
|
||||
case types.SETTINGS_RECEIVED: return receivedSettings(state, action)
|
||||
case types.SETTINGS_RECEIVED: return updateSettings(state, action)
|
||||
case types.SETTINGS_FETCH_ERROR: return settingsFetchFailed(state, action)
|
||||
case types.SETTINGS_UPDAETD: return state.get('settings').merge(action.settings)
|
||||
case types.SETTINGS_UPDATED: return updateSettings(state, action)
|
||||
case types.SAVE_SETTINGS_LOADING: return state.set('fetchingSettings', true).set('saveSettingsError', null)
|
||||
case types.SAVE_SETTINGS_SUCCESS: return saveComplete(state, action)
|
||||
case types.SAVE_SETTINGS_FAILED: return settingsSaveFailed(state, action)
|
||||
@@ -22,15 +22,16 @@ export default (state = initialState, action) => {
|
||||
}
|
||||
}
|
||||
|
||||
const receivedSettings = (state, action) => {
|
||||
state.set('fetchingSettings', false).set('fetchSettingsError', null)
|
||||
return state.get('settings').merge(action.settings)
|
||||
const updateSettings = (state, action) => {
|
||||
const s = state.set('fetchingSettings', false).set('fetchSettingsError', null)
|
||||
const settings = s.get('settings').merge(action.settings)
|
||||
return s.set('settings', settings)
|
||||
}
|
||||
|
||||
const saveComplete = (state, action) => {
|
||||
state.set('fetchingSettings', false).set('saveSettingsError', null)
|
||||
console.log('saveComplete', action.settings)
|
||||
return state.get('settings').merge(action.settings)
|
||||
const s = state.set('fetchingSettings', false).set('saveSettingsError', null)
|
||||
const settings = s.get('settings').merge(action.settings)
|
||||
return s.set('settings', settings)
|
||||
}
|
||||
|
||||
const settingsFetchFailed = (state, action) => {
|
||||
|
||||
Reference in New Issue
Block a user