From c4c99a1c1b33453f2cf46c43eb743ecfe0e33ad3 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 28 May 2020 15:09:59 -0500 Subject: [PATCH] EditProfile: refactor initialState --- app/gabsocial/features/edit_profile/index.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/gabsocial/features/edit_profile/index.js b/app/gabsocial/features/edit_profile/index.js index a57da8b36..eea420962 100644 --- a/app/gabsocial/features/edit_profile/index.js +++ b/app/gabsocial/features/edit_profile/index.js @@ -115,18 +115,20 @@ class EditProfile extends ImmutablePureComponent { event.preventDefault(); } - componentWillMount() { - const { account } = this.props; - const sourceData = account.get('source'); - const accountData = account.merge(sourceData).delete('source'); - const fields = normalizeFields(accountData.get('fields')); - const initialState = unescapeParams( - accountData.set('fields', fields), - ['display_name', 'note'] - ); + setInitialState = () => { + const initialState = this.props.account.withMutations(map => { + map.merge(map.get('source')); + map.delete('source'); + map.set('fields', normalizeFields(map.get('fields'))); + unescapeParams(map, ['display_name', 'note']); + }); this.setState(initialState.toObject()); } + componentWillMount() { + this.setInitialState(); + } + handleCheckboxChange = e => { this.setState({ [e.target.name]: e.target.checked }); }