2023-03-11 16:33:55 +03:00
|
|
|
import { useEffect } from 'preact/hooks';
|
2023-03-11 09:05:56 +03:00
|
|
|
import { useHotkeys } from 'react-hotkeys-hook';
|
|
|
|
|
|
|
|
import { api } from '../utils/api';
|
2023-03-11 16:33:55 +03:00
|
|
|
import states from '../utils/states';
|
2023-03-11 09:05:56 +03:00
|
|
|
|
|
|
|
import AccountInfo from './account-info';
|
2023-04-20 11:10:57 +03:00
|
|
|
import Icon from './icon';
|
2023-03-11 09:05:56 +03:00
|
|
|
|
|
|
|
function AccountSheet({ account, instance: propInstance, onClose }) {
|
|
|
|
const { masto, instance, authenticated } = api({ instance: propInstance });
|
|
|
|
const isString = typeof account === 'string';
|
|
|
|
|
|
|
|
const escRef = useHotkeys('esc', onClose, [onClose]);
|
|
|
|
|
2023-03-11 16:33:55 +03:00
|
|
|
useEffect(() => {
|
|
|
|
if (!isString) {
|
|
|
|
states.accounts[`${account.id}@${instance}`] = account;
|
|
|
|
}
|
|
|
|
}, [account]);
|
|
|
|
|
2023-03-11 09:05:56 +03:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
ref={escRef}
|
|
|
|
class="sheet"
|
|
|
|
onClick={(e) => {
|
|
|
|
const accountBlock = e.target.closest('.account-block');
|
|
|
|
if (accountBlock) {
|
2023-03-11 13:13:53 +03:00
|
|
|
onClose({
|
|
|
|
destination: 'account-statuses',
|
|
|
|
});
|
2023-03-11 09:05:56 +03:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2023-04-20 11:10:57 +03:00
|
|
|
{!!onClose && (
|
|
|
|
<button type="button" class="sheet-close outer" onClick={onClose}>
|
|
|
|
<Icon icon="x" />
|
|
|
|
</button>
|
|
|
|
)}
|
2023-03-11 09:05:56 +03:00
|
|
|
<AccountInfo
|
|
|
|
instance={instance}
|
|
|
|
authenticated={authenticated}
|
|
|
|
account={account}
|
|
|
|
fetchAccount={async () => {
|
|
|
|
if (isString) {
|
|
|
|
try {
|
|
|
|
const info = await masto.v1.accounts.lookup({
|
|
|
|
acct: account,
|
|
|
|
skip_webfinger: false,
|
|
|
|
});
|
|
|
|
return info;
|
|
|
|
} catch (e) {
|
|
|
|
const result = await masto.v2.search({
|
|
|
|
q: account,
|
|
|
|
type: 'accounts',
|
|
|
|
limit: 1,
|
|
|
|
resolve: authenticated,
|
|
|
|
});
|
|
|
|
if (result.accounts.length) {
|
|
|
|
return result.accounts[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return account;
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AccountSheet;
|