mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-09 01:26:24 +01:00
Show common followers, only when not following
This commit is contained in:
parent
816653e2e6
commit
ce0c0563f3
2 changed files with 55 additions and 4 deletions
|
@ -70,3 +70,12 @@
|
||||||
#account-container .profile-field p {
|
#account-container .profile-field p {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#account-container .common-followers {
|
||||||
|
border-top: 1px solid var(--outline-color);
|
||||||
|
border-bottom: 1px solid var(--outline-color);
|
||||||
|
padding: 8px 0;
|
||||||
|
font-size: 90%;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: var(--text-insignificant-color);
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import emojifyText from '../utils/emojify-text';
|
||||||
import enhanceContent from '../utils/enhance-content';
|
import enhanceContent from '../utils/enhance-content';
|
||||||
import handleAccountLinks from '../utils/handle-account-links';
|
import handleAccountLinks from '../utils/handle-account-links';
|
||||||
import shortenNumber from '../utils/shorten-number';
|
import shortenNumber from '../utils/shorten-number';
|
||||||
|
import states from '../utils/states';
|
||||||
import store from '../utils/store';
|
import store from '../utils/store';
|
||||||
|
|
||||||
import Avatar from './avatar';
|
import Avatar from './avatar';
|
||||||
|
@ -48,6 +49,8 @@ function Account({ account }) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
} else {
|
||||||
|
setInfo(account);
|
||||||
}
|
}
|
||||||
}, [account]);
|
}, [account]);
|
||||||
|
|
||||||
|
@ -76,6 +79,7 @@ function Account({ account }) {
|
||||||
|
|
||||||
const [relationshipUIState, setRelationshipUIState] = useState('default');
|
const [relationshipUIState, setRelationshipUIState] = useState('default');
|
||||||
const [relationship, setRelationship] = useState(null);
|
const [relationship, setRelationship] = useState(null);
|
||||||
|
const [familiarFollowers, setFamiliarFollowers] = useState([]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (info) {
|
if (info) {
|
||||||
const currentAccount = store.session.get('currentAccount');
|
const currentAccount = store.session.get('currentAccount');
|
||||||
|
@ -84,14 +88,29 @@ function Account({ account }) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setRelationshipUIState('loading');
|
setRelationshipUIState('loading');
|
||||||
|
setFamiliarFollowers([]);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
const fetchRelationships = masto.v1.accounts.fetchRelationships([id]);
|
||||||
|
const fetchFamiliarFollowers =
|
||||||
|
masto.v1.accounts.fetchFamiliarFollowers(id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const relationships = await masto.v1.accounts.fetchRelationships([
|
const relationships = await fetchRelationships;
|
||||||
id,
|
|
||||||
]);
|
|
||||||
console.log('fetched relationship', relationships);
|
console.log('fetched relationship', relationships);
|
||||||
if (relationships.length) {
|
if (relationships.length) {
|
||||||
setRelationship(relationships[0]);
|
const relationship = relationships[0];
|
||||||
|
setRelationship(relationship);
|
||||||
|
|
||||||
|
if (!relationship.following) {
|
||||||
|
try {
|
||||||
|
const followers = await fetchFamiliarFollowers;
|
||||||
|
console.log('fetched familiar followers', followers);
|
||||||
|
setFamiliarFollowers(followers[0].accounts.slice(0, 10));
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setRelationshipUIState('default');
|
setRelationshipUIState('default');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -225,6 +244,29 @@ function Account({ account }) {
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
|
{familiarFollowers?.length > 0 && (
|
||||||
|
<p class="common-followers">
|
||||||
|
Common followers{' '}
|
||||||
|
<span class="ib">
|
||||||
|
{familiarFollowers.map((follower) => (
|
||||||
|
<a
|
||||||
|
href={follower.url}
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
states.showAccount = follower;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Avatar
|
||||||
|
url={follower.avatarStatic}
|
||||||
|
size="l"
|
||||||
|
alt={`${follower.displayName} @${follower.acct}`}
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
|
))}
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
<p class="actions">
|
<p class="actions">
|
||||||
{followedBy ? <span class="tag">Following you</span> : <span />}{' '}
|
{followedBy ? <span class="tag">Following you</span> : <span />}{' '}
|
||||||
{relationshipUIState !== 'loading' && relationship && (
|
{relationshipUIState !== 'loading' && relationship && (
|
||||||
|
|
Loading…
Reference in a new issue