diff --git a/app/soapbox/features/edit_profile/index.js b/app/soapbox/features/edit_profile/index.js index d25cc85e3..5445ff30a 100644 --- a/app/soapbox/features/edit_profile/index.js +++ b/app/soapbox/features/edit_profile/index.js @@ -20,8 +20,6 @@ import { import { patchMe } from 'soapbox/actions/me'; import { unescape } from 'lodash'; -const MAX_FIELDS = 4; // TODO: Make this dynamic by the instance - const messages = defineMessages({ heading: { id: 'column.edit_profile', defaultMessage: 'Edit profile' }, metaFieldLabel: { id: 'edit_profile.fields.meta_fields.label_placeholder', defaultMessage: 'Label' }, @@ -33,12 +31,13 @@ const mapStateToProps = state => { const me = state.get('me'); return { account: state.getIn(['accounts', me]), + maxFields: state.getIn(['instance', 'pleroma', 'metadata', 'fieldsLimits', 'maxFields']), }; }; -// Forces fields to be MAX_SIZE, filling empty values -const normalizeFields = fields => ( - ImmutableList(fields).setSize(MAX_FIELDS).map(field => +// Forces fields to be maxFields size, filling empty values +const normalizeFields = (fields, maxFields) => ( + ImmutableList(fields).setSize(maxFields).map(field => field ? field : ImmutableMap({ name: '', value: '' }) ) ); @@ -58,11 +57,11 @@ class EditProfile extends ImmutablePureComponent { dispatch: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, account: ImmutablePropTypes.map, + maxFields: PropTypes.number, }; state = { isLoading: false, - fields: normalizeFields(Array.from({ length: MAX_FIELDS })), } constructor(props) { @@ -70,7 +69,7 @@ class EditProfile extends ImmutablePureComponent { const initialState = props.account.withMutations(map => { map.merge(map.get('source')); map.delete('source'); - map.set('fields', normalizeFields(map.get('fields'))); + map.set('fields', normalizeFields(map.get('fields'), props.maxFields)); unescapeParams(map, ['display_name', 'note']); }); this.state = initialState.toObject(); @@ -157,7 +156,7 @@ class EditProfile extends ImmutablePureComponent { } render() { - const { intl, account } = this.props; + const { intl, maxFields, account } = this.props; const verified = account.get('pleroma').get('tags').includes('verified'); return ( @@ -219,7 +218,7 @@ class EditProfile extends ImmutablePureComponent {
- + { this.state.fields.map((field, i) => ( diff --git a/app/soapbox/reducers/instance.js b/app/soapbox/reducers/instance.js index 980951031..549f95207 100644 --- a/app/soapbox/reducers/instance.js +++ b/app/soapbox/reducers/instance.js @@ -12,6 +12,7 @@ const nodeinfoToInstance = nodeinfo => { account_activation_required: nodeinfo.getIn(['metadata', 'accountActivationRequired']), features: nodeinfo.getIn(['metadata', 'features']), federation: nodeinfo.getIn(['metadata', 'federation']), + fieldsLimits: nodeinfo.getIn(['metadata', 'fieldsLimits']), }), }), });