From 76b3849c935f62e5fbd983cc7821a4b52da6170c Mon Sep 17 00:00:00 2001 From: crockwave Date: Wed, 27 May 2020 19:53:47 -0500 Subject: [PATCH 1/4] Convert HTML to text value in Profile Page for Display name and Bio fields Fixed linter errors * used unescape method from lodash to translate HTML to plain text * Moved translation to the componentDidMount event * Removed decodeHtml method from utils/html --- app/gabsocial/features/edit_profile/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/gabsocial/features/edit_profile/index.js b/app/gabsocial/features/edit_profile/index.js index d09e5bb0e..7ac387310 100644 --- a/app/gabsocial/features/edit_profile/index.js +++ b/app/gabsocial/features/edit_profile/index.js @@ -18,6 +18,7 @@ import { List as ImmutableList, } from 'immutable'; import { patchMe } from 'gabsocial/actions/me'; +import { unescape } from 'lodash'; const MAX_FIELDS = 4; // TODO: Make this dynamic by the instance @@ -116,6 +117,13 @@ class EditProfile extends ImmutablePureComponent { this.setState(initialState.toObject()); } + componentDidMount() { + const display_name = unescape(this.state.display_name); + this.setState({ display_name: display_name }); + const note = unescape(this.state.note); + this.setState({ note: note }); + } + handleCheckboxChange = e => { this.setState({ [e.target.name]: e.target.checked }); } From 1d44de08736747b02da01b57aa7f94541f046d5e Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 28 May 2020 15:04:56 -0500 Subject: [PATCH 2/4] EditProfile: Unescape account params in componentWillMount() --- app/gabsocial/features/edit_profile/index.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/gabsocial/features/edit_profile/index.js b/app/gabsocial/features/edit_profile/index.js index 7ac387310..a57da8b36 100644 --- a/app/gabsocial/features/edit_profile/index.js +++ b/app/gabsocial/features/edit_profile/index.js @@ -40,6 +40,13 @@ const normalizeFields = fields => ( ) ); +// HTML unescape for special chars, eg
+const unescapeParams = (map, params) => ( + params.reduce((map, param) => ( + map.set(param, unescape(map.get(param))) + ), map) +); + export default @connect(mapStateToProps) @injectIntl class EditProfile extends ImmutablePureComponent { @@ -113,17 +120,13 @@ class EditProfile extends ImmutablePureComponent { const sourceData = account.get('source'); const accountData = account.merge(sourceData).delete('source'); const fields = normalizeFields(accountData.get('fields')); - const initialState = accountData.set('fields', fields); + const initialState = unescapeParams( + accountData.set('fields', fields), + ['display_name', 'note'] + ); this.setState(initialState.toObject()); } - componentDidMount() { - const display_name = unescape(this.state.display_name); - this.setState({ display_name: display_name }); - const note = unescape(this.state.note); - this.setState({ note: note }); - } - handleCheckboxChange = e => { this.setState({ [e.target.name]: e.target.checked }); } From c4c99a1c1b33453f2cf46c43eb743ecfe0e33ad3 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 28 May 2020 15:09:59 -0500 Subject: [PATCH 3/4] 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 }); } From e6cff0f83fda7be27202e5d39086f452be1abd4d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 28 May 2020 15:29:32 -0500 Subject: [PATCH 4/4] EditProfile: Fix error about uncontrolled components --- app/gabsocial/features/edit_profile/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/gabsocial/features/edit_profile/index.js b/app/gabsocial/features/edit_profile/index.js index eea420962..d990abbb4 100644 --- a/app/gabsocial/features/edit_profile/index.js +++ b/app/gabsocial/features/edit_profile/index.js @@ -36,7 +36,7 @@ const mapStateToProps = state => { // Forces fields to be MAX_SIZE, filling empty values const normalizeFields = fields => ( ImmutableList(fields).setSize(MAX_FIELDS).map(field => - field ? field : ImmutableMap({ name: undefined, value: undefined }) + field ? field : ImmutableMap({ name: '', value: '' }) ) );