Merge branch 'decode_uri_on_profile_edit'

This commit is contained in:
Alex Gleason 2020-05-28 15:29:54 -05:00
commit 786f6feacc
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -18,6 +18,7 @@ import {
List as ImmutableList, List as ImmutableList,
} from 'immutable'; } from 'immutable';
import { patchMe } from 'gabsocial/actions/me'; import { patchMe } from 'gabsocial/actions/me';
import { unescape } from 'lodash';
const MAX_FIELDS = 4; // TODO: Make this dynamic by the instance const MAX_FIELDS = 4; // TODO: Make this dynamic by the instance
@ -35,10 +36,17 @@ const mapStateToProps = state => {
// Forces fields to be MAX_SIZE, filling empty values // Forces fields to be MAX_SIZE, filling empty values
const normalizeFields = fields => ( const normalizeFields = fields => (
ImmutableList(fields).setSize(MAX_FIELDS).map(field => ImmutableList(fields).setSize(MAX_FIELDS).map(field =>
field ? field : ImmutableMap({ name: undefined, value: undefined }) field ? field : ImmutableMap({ name: '', value: '' })
) )
); );
// HTML unescape for special chars, eg <br>
const unescapeParams = (map, params) => (
params.reduce((map, param) => (
map.set(param, unescape(map.get(param)))
), map)
);
export default @connect(mapStateToProps) export default @connect(mapStateToProps)
@injectIntl @injectIntl
class EditProfile extends ImmutablePureComponent { class EditProfile extends ImmutablePureComponent {
@ -107,15 +115,20 @@ class EditProfile extends ImmutablePureComponent {
event.preventDefault(); event.preventDefault();
} }
componentWillMount() { setInitialState = () => {
const { account } = this.props; const initialState = this.props.account.withMutations(map => {
const sourceData = account.get('source'); map.merge(map.get('source'));
const accountData = account.merge(sourceData).delete('source'); map.delete('source');
const fields = normalizeFields(accountData.get('fields')); map.set('fields', normalizeFields(map.get('fields')));
const initialState = accountData.set('fields', fields); unescapeParams(map, ['display_name', 'note']);
});
this.setState(initialState.toObject()); this.setState(initialState.toObject());
} }
componentWillMount() {
this.setInitialState();
}
handleCheckboxChange = e => { handleCheckboxChange = e => {
this.setState({ [e.target.name]: e.target.checked }); this.setState({ [e.target.name]: e.target.checked });
} }