From 59cf1ff4512c162ee0ebee917427a694459540ec Mon Sep 17 00:00:00 2001 From: natjms Date: Wed, 17 Mar 2021 15:14:14 -0300 Subject: [PATCH] Display only mutual followers on profiles --- src/components/pages/profile.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/components/pages/profile.js b/src/components/pages/profile.js index adf8179..2d7a4ae 100644 --- a/src/components/pages/profile.js +++ b/src/components/pages/profile.js @@ -69,10 +69,34 @@ const TEST_PROFILE = { ] }; +const TEST_YOUR_FOLLOWERS = [ + { id: 1 }, + { id: 2 }, + { id: 3 }, + { id: 4 }, + { id: 5 }, +]; + +const TEST_THEIR_FOLLOWERS = [ + { id: 2 }, + { id: 3 }, + { id: 4 }, + { id: 6 }, +]; + function withoutHTML(string) { return string.replaceAll(/<[^>]*>/ig, ""); } +function getMutuals(yours, theirs) { + // Where yours and theirs are arrays of followers, as returned by the oAPI + + const idify = ({id}) => id; + const asIDs = new Set(theirs.map(idify)); + + return yours.filter(x => asIDs.has(idify(x))); +} + const HTMLLink = ({link}) => { let url = link.match(/https?:\/\/\w+\.\w+/); @@ -129,6 +153,7 @@ const ProfileDisplayJsx = ({navigation}) => { // do something to get the profile based on given account name setState({ profile: TEST_PROFILE, + mutuals: getMutuals(TEST_YOUR_FOLLOWERS, TEST_THEIR_FOLLOWERS), loaded: true }); }, []); @@ -178,8 +203,7 @@ const ProfileDisplayJsx = ({navigation}) => { { state.profile.statuses_count } posts •  - { state.profile.followers_count } followers •  - { state.profile.following_count } following + { state.mutuals.length } mutuals {state.profile.note}