Merge branch 'decode_uri_on_profile_edit'
This commit is contained in:
commit
786f6feacc
1 changed files with 20 additions and 7 deletions
|
@ -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
|
||||
|
||||
|
@ -35,10 +36,17 @@ 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: '' })
|
||||
)
|
||||
);
|
||||
|
||||
// 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)
|
||||
@injectIntl
|
||||
class EditProfile extends ImmutablePureComponent {
|
||||
|
@ -107,15 +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 = accountData.set('fields', fields);
|
||||
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 });
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue