2023-01-29 18:37:13 +03:00
|
|
|
import { useEffect, useRef, useState } from 'preact/hooks';
|
|
|
|
import { useParams } from 'react-router-dom';
|
2023-02-03 16:08:08 +03:00
|
|
|
import { useSnapshot } from 'valtio';
|
2023-01-29 18:37:13 +03:00
|
|
|
|
|
|
|
import Timeline from '../components/timeline';
|
2023-01-31 14:08:10 +03:00
|
|
|
import states from '../utils/states';
|
2023-02-03 16:08:08 +03:00
|
|
|
import useTitle from '../utils/useTitle';
|
2023-01-29 18:37:13 +03:00
|
|
|
|
|
|
|
const LIMIT = 20;
|
|
|
|
|
|
|
|
function AccountStatuses() {
|
2023-02-03 16:08:08 +03:00
|
|
|
const snapStates = useSnapshot(states);
|
2023-01-29 18:37:13 +03:00
|
|
|
const { id } = useParams();
|
|
|
|
const accountStatusesIterator = useRef();
|
|
|
|
async function fetchAccountStatuses(firstLoad) {
|
|
|
|
if (firstLoad || !accountStatusesIterator.current) {
|
|
|
|
accountStatusesIterator.current = masto.v1.accounts.listStatuses(id, {
|
|
|
|
limit: LIMIT,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return await accountStatusesIterator.current.next();
|
|
|
|
}
|
|
|
|
|
|
|
|
const [account, setAccount] = useState({});
|
2023-02-03 16:08:08 +03:00
|
|
|
useTitle(`${account?.acct ? '@' + account.acct : 'Posts'}`, '/a/:id');
|
2023-01-29 18:37:13 +03:00
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
try {
|
|
|
|
const acc = await masto.v1.accounts.fetch(id);
|
|
|
|
console.log(acc);
|
|
|
|
setAccount(acc);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
}, [id]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Timeline
|
|
|
|
key={id}
|
|
|
|
title={`${account?.acct ? '@' + account.acct : 'Posts'}`}
|
2023-01-31 14:08:10 +03:00
|
|
|
titleComponent={
|
|
|
|
<h1
|
|
|
|
class="header-account"
|
|
|
|
onClick={() => {
|
|
|
|
states.showAccount = account;
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{account?.displayName}
|
|
|
|
<div>
|
|
|
|
<span>@{account?.acct}</span>
|
|
|
|
</div>
|
|
|
|
</h1>
|
|
|
|
}
|
2023-01-29 18:37:13 +03:00
|
|
|
id="account_statuses"
|
|
|
|
emptyText="Nothing to see here yet."
|
|
|
|
errorText="Unable to load statuses"
|
|
|
|
fetchItems={fetchAccountStatuses}
|
2023-02-03 16:08:08 +03:00
|
|
|
boostsCarousel={snapStates.settings.boostsCarousel}
|
2023-01-29 18:37:13 +03:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AccountStatuses;
|