Fix wrong "info", when viewing remote accounts

This commit is contained in:
Lim Chee Aun 2023-03-18 17:04:47 +08:00
parent 24fdaf78d1
commit 94b96bd534

View file

@ -406,6 +406,8 @@ function RelatedActions({ info, instance, authenticated }) {
endorsed, endorsed,
} = relationship || {}; } = relationship || {};
const [currentInfo, setCurrentInfo] = useState(null);
useEffect(() => { useEffect(() => {
if (info) { if (info) {
const currentAccount = store.session.get('currentAccount'); const currentAccount = store.session.get('currentAccount');
@ -424,7 +426,10 @@ function RelatedActions({ info, instance, authenticated }) {
resolve: true, resolve: true,
}); });
console.log('🥏 Fetched account from logged-in instance', results); console.log('🥏 Fetched account from logged-in instance', results);
currentID = results.accounts[0].id; if (results.accounts.length) {
currentID = results.accounts[0].id;
setCurrentInfo(results.accounts[0]);
}
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
@ -544,7 +549,7 @@ function RelatedActions({ info, instance, authenticated }) {
onClick={() => { onClick={() => {
states.showCompose = { states.showCompose = {
draftStatus: { draftStatus: {
status: `@${acct} `, status: `@${currentInfo?.acct || acct} `,
}, },
}; };
}} }}
@ -606,7 +611,9 @@ function RelatedActions({ info, instance, authenticated }) {
(async () => { (async () => {
try { try {
const newRelationship = const newRelationship =
await currentMasto.v1.accounts.unmute(id); await currentMasto.v1.accounts.unmute(
currentInfo?.id || id,
);
console.log('unmuting', newRelationship); console.log('unmuting', newRelationship);
setRelationship(newRelationship); setRelationship(newRelationship);
setRelationshipUIState('default'); setRelationshipUIState('default');
@ -646,9 +653,12 @@ function RelatedActions({ info, instance, authenticated }) {
(async () => { (async () => {
try { try {
const newRelationship = const newRelationship =
await currentMasto.v1.accounts.mute(id, { await currentMasto.v1.accounts.mute(
duration, currentInfo?.id || id,
}); {
duration,
},
);
console.log('muting', newRelationship); console.log('muting', newRelationship);
setRelationship(newRelationship); setRelationship(newRelationship);
setRelationshipUIState('default'); setRelationshipUIState('default');
@ -679,14 +689,18 @@ function RelatedActions({ info, instance, authenticated }) {
try { try {
if (blocking) { if (blocking) {
const newRelationship = const newRelationship =
await currentMasto.v1.accounts.unblock(id); await currentMasto.v1.accounts.unblock(
currentInfo?.id || id,
);
console.log('unblocking', newRelationship); console.log('unblocking', newRelationship);
setRelationship(newRelationship); setRelationship(newRelationship);
setRelationshipUIState('default'); setRelationshipUIState('default');
showToast(`Unblocked @${username}`); showToast(`Unblocked @${username}`);
} else { } else {
const newRelationship = const newRelationship =
await currentMasto.v1.accounts.block(id); await currentMasto.v1.accounts.block(
currentInfo?.id || id,
);
console.log('blocking', newRelationship); console.log('blocking', newRelationship);
setRelationship(newRelationship); setRelationship(newRelationship);
setRelationshipUIState('default'); setRelationshipUIState('default');