diff --git a/src/components/account.jsx b/src/components/account.jsx index e24d0958..ea6ab6e1 100644 --- a/src/components/account.jsx +++ b/src/components/account.jsx @@ -1,6 +1,6 @@ import './account.css'; -import { useEffect, useState } from 'preact/hooks'; +import { useEffect, useRef, useState } from 'preact/hooks'; import { api } from '../utils/api'; import emojifyText from '../utils/emojify-text'; @@ -17,12 +17,6 @@ import Link from './link'; function Account({ account, instance: propInstance, onClose }) { const { masto, instance, authenticated } = api({ instance: propInstance }); - const { - masto: currentMasto, - instance: currentInstance, - authenticated: currentAuthenticated, - } = api(); - const sameInstance = instance === currentInstance; const [uiState, setUIState] = useState('default'); const isString = typeof account === 'string'; const [info, setInfo] = useState(isString ? null : account); @@ -88,89 +82,6 @@ function Account({ account, instance: propInstance, onClose }) { username, } = info || {}; - const [relationshipUIState, setRelationshipUIState] = useState('default'); - const [relationship, setRelationship] = useState(null); - const [familiarFollowers, setFamiliarFollowers] = useState([]); - useEffect(() => { - if (info) { - const currentAccount = store.session.get('currentAccount'); - let accountID; - (async () => { - if (sameInstance && authenticated) { - accountID = id; - } else if (!sameInstance && currentAuthenticated) { - // Grab this account from my logged-in instance - const acctHasInstance = info.acct.includes('@'); - try { - const results = await currentMasto.v2.search({ - q: acctHasInstance ? info.acct : `${info.username}@${instance}`, - type: 'accounts', - limit: 1, - resolve: true, - }); - console.log('š„ Fetched account from logged-in instance', results); - accountID = results.accounts[0].id; - } catch (e) { - console.error(e); - } - } - - if (!accountID) return; - - if (currentAccount === accountID) { - // It's myself! - return; - } - - setRelationshipUIState('loading'); - setFamiliarFollowers([]); - - const fetchRelationships = currentMasto.v1.accounts.fetchRelationships([ - accountID, - ]); - const fetchFamiliarFollowers = - currentMasto.v1.accounts.fetchFamiliarFollowers(accountID); - - try { - const relationships = await fetchRelationships; - console.log('fetched relationship', relationships); - if (relationships.length) { - 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'); - } catch (e) { - console.error(e); - setRelationshipUIState('error'); - } - })(); - } - }, [info, authenticated]); - - const { - following, - showingReblogs, - notifying, - followedBy, - blocking, - blockedBy, - muting, - mutingNotifications, - requested, - domainBlocking, - endorsed, - } = relationship || {}; - return (
- Common followers{' '}
-
- {familiarFollowers.map((follower) => (
- {
- e.preventDefault();
- states.showAccount = {
- account: follower,
- instance,
- };
- }}
- >
-
- {followedBy ? Following you : }{' '} - {relationshipUIState !== 'loading' && relationship && ( - - )} -
+
+ Common followers{' '}
+
+ {familiarFollowers.map((follower) => (
+ {
+ e.preventDefault();
+ states.showAccount = {
+ account: follower,
+ instance,
+ };
+ }}
+ >
+
+ {followedBy ? Following you : }{' '} + {relationshipUIState !== 'loading' && relationship && ( + + )} +
+ > + ); +} + export default Account;