From 9a2fba1ef5a5340ce122ee951e9015d27ac52d1d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 8 Aug 2020 20:32:39 -0500 Subject: [PATCH 1/2] Revert "Revert "Store fieldsLimits in instance/pleroma/metadata of the Redux store. Render fields to maxFields value in features/edit_profile, using maxFields value"" This reverts commit b3a6c395dffb9147ebe7b9d530bf8d22e1b2914d. --- app/soapbox/features/edit_profile/index.js | 17 ++++++++--------- app/soapbox/reducers/instance.js | 1 + 2 files changed, 9 insertions(+), 9 deletions(-) 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']), }), }), }); From 95fb1b7900b77c987df5c66d493f99452a92d408 Mon Sep 17 00:00:00 2001 From: Sean King Date: Sun, 9 Aug 2020 01:40:35 +0000 Subject: [PATCH 2/2] Update index.js --- app/soapbox/features/edit_profile/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/soapbox/features/edit_profile/index.js b/app/soapbox/features/edit_profile/index.js index 5445ff30a..e8dc8b9fb 100644 --- a/app/soapbox/features/edit_profile/index.js +++ b/app/soapbox/features/edit_profile/index.js @@ -31,7 +31,7 @@ const mapStateToProps = state => { const me = state.get('me'); return { account: state.getIn(['accounts', me]), - maxFields: state.getIn(['instance', 'pleroma', 'metadata', 'fieldsLimits', 'maxFields']), + maxFields: state.getIn(['instance', 'pleroma', 'metadata', 'fields_limits', 'max_fields']), }; };