From 2679519d23f153b44ba1fac555b64f40d386d830 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 28 Feb 2022 17:25:20 -0600 Subject: [PATCH] Display account location on profile --- .../__fixtures__/truthsocial-account.json | 26 +++++++++++++++++++ .../ui/components/profile_info_panel.js | 7 +++++ .../normalizers/__tests__/account-test.js | 12 +++++++++ app/soapbox/normalizers/account.js | 11 ++++++++ app/styles/components/profile-info-panel.scss | 1 + 5 files changed, 57 insertions(+) create mode 100644 app/soapbox/__fixtures__/truthsocial-account.json diff --git a/app/soapbox/__fixtures__/truthsocial-account.json b/app/soapbox/__fixtures__/truthsocial-account.json new file mode 100644 index 000000000..6b451ca8b --- /dev/null +++ b/app/soapbox/__fixtures__/truthsocial-account.json @@ -0,0 +1,26 @@ +{ + "id": "107759994408336377", + "username": "alex", + "acct": "alex", + "display_name": "Alex G.", + "locked": false, + "bot": false, + "discoverable": null, + "group": false, + "created_at": "2022-02-08T00:00:00.000Z", + "note": "

Launching Truth Social

", + "url": "https://truthsocial.com/@alex", + "avatar": "https://static-assets.truthsocial.com/tmtg:prime-truth-social-assets/accounts/avatars/107/759/994/408/336/377/original/119cb0dd1fa615b7.png", + "avatar_static": "https://static-assets.truthsocial.com/tmtg:prime-truth-social-assets/accounts/avatars/107/759/994/408/336/377/original/119cb0dd1fa615b7.png", + "header": "https://static-assets.truthsocial.com/tmtg:prime-truth-social-assets/accounts/headers/107/759/994/408/336/377/original/31f62b0453ccf554.png", + "header_static": "https://static-assets.truthsocial.com/tmtg:prime-truth-social-assets/accounts/headers/107/759/994/408/336/377/original/31f62b0453ccf554.png", + "followers_count": 966, + "following_count": 39, + "statuses_count": 4, + "last_status_at": "2022-02-20", + "verified": true, + "location": "Texas", + "website": "https://soapbox.pub", + "emojis": [], + "fields": [] +} diff --git a/app/soapbox/features/ui/components/profile_info_panel.js b/app/soapbox/features/ui/components/profile_info_panel.js index 72e033e1e..1bddee296 100644 --- a/app/soapbox/features/ui/components/profile_info_panel.js +++ b/app/soapbox/features/ui/components/profile_info_panel.js @@ -196,6 +196,13 @@ class ProfileInfoPanel extends ImmutablePureComponent { {this.getBirthday()} + {account.get('location') && ( +
+ + {account.get('location')} +
+ )} + {!!account.getIn(['relationship', 'note']) && ( diff --git a/app/soapbox/normalizers/__tests__/account-test.js b/app/soapbox/normalizers/__tests__/account-test.js index f00dd57c5..5199e3492 100644 --- a/app/soapbox/normalizers/__tests__/account-test.js +++ b/app/soapbox/normalizers/__tests__/account-test.js @@ -54,4 +54,16 @@ describe('normalizeAccount()', () => { const result = normalizeAccount(account); expect(result.get('verified')).toBe(true); }); + + it('normalizes Fedibird location', () => { + const account = fromJS(require('soapbox/__fixtures__/fedibird-account.json')); + const result = normalizeAccount(account); + expect(result.get('location')).toBe('Texas, USA'); + }); + + it('normalizes Truth Social location', () => { + const account = fromJS(require('soapbox/__fixtures__/truthsocial-account.json')); + const result = normalizeAccount(account); + expect(result.get('location')).toBe('Texas'); + }); }); diff --git a/app/soapbox/normalizers/account.js b/app/soapbox/normalizers/account.js index aa49f647f..3b4a7dc02 100644 --- a/app/soapbox/normalizers/account.js +++ b/app/soapbox/normalizers/account.js @@ -38,10 +38,21 @@ const normalizeVerified = account => { }); }; +// Normalize Fedibird/Truth Social location +const normalizeLocation = account => { + return account.update('location', location => { + return [ + location, + account.getIn(['other_settings', 'location']), + ].find(Boolean); + }); +}; + export const normalizeAccount = account => { return account.withMutations(account => { normalizePleromaLegacyFields(account); normalizeVerified(account); normalizeBirthday(account); + normalizeLocation(account); }); }; diff --git a/app/styles/components/profile-info-panel.scss b/app/styles/components/profile-info-panel.scss index 65e70c4bd..3089622fc 100644 --- a/app/styles/components/profile-info-panel.scss +++ b/app/styles/components/profile-info-panel.scss @@ -24,6 +24,7 @@ &__join-date, &__birthday, + &__location, &__note { display: flex; font-size: 14px;