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-02-05 19:17:19 +03:00
|
|
|
import { api } from '../utils/api';
|
2023-02-04 08:18:23 +03:00
|
|
|
import emojifyText from '../utils/emojify-text';
|
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-02-06 11:35:03 +03:00
|
|
|
const { id, ...params } = useParams();
|
|
|
|
const { masto, instance } = api({ instance: params.instance });
|
2023-01-29 18:37:13 +03:00
|
|
|
const accountStatusesIterator = useRef();
|
|
|
|
async function fetchAccountStatuses(firstLoad) {
|
2023-02-17 05:12:59 +03:00
|
|
|
const results = [];
|
|
|
|
if (firstLoad) {
|
|
|
|
const { value: pinnedStatuses } = await masto.v1.accounts
|
|
|
|
.listStatuses(id, {
|
|
|
|
pinned: true,
|
|
|
|
})
|
|
|
|
.next();
|
|
|
|
if (pinnedStatuses?.length) {
|
|
|
|
pinnedStatuses.forEach((status) => {
|
|
|
|
status._pinned = true;
|
|
|
|
});
|
2023-02-17 05:55:16 +03:00
|
|
|
if (pinnedStatuses.length > 1) {
|
|
|
|
const pinnedStatusesIds = pinnedStatuses.map((status) => status.id);
|
|
|
|
results.push({
|
|
|
|
id: pinnedStatusesIds,
|
|
|
|
items: pinnedStatuses,
|
|
|
|
type: 'pinned',
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
results.push(...pinnedStatuses);
|
|
|
|
}
|
2023-02-17 05:12:59 +03:00
|
|
|
}
|
|
|
|
}
|
2023-01-29 18:37:13 +03:00
|
|
|
if (firstLoad || !accountStatusesIterator.current) {
|
|
|
|
accountStatusesIterator.current = masto.v1.accounts.listStatuses(id, {
|
|
|
|
limit: LIMIT,
|
|
|
|
});
|
|
|
|
}
|
2023-02-17 05:12:59 +03:00
|
|
|
const { value, done } = await accountStatusesIterator.current.next();
|
|
|
|
if (value?.length) {
|
|
|
|
results.push(...value);
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
value: results,
|
|
|
|
done,
|
|
|
|
};
|
2023-01-29 18:37:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const [account, setAccount] = useState({});
|
2023-02-06 11:35:03 +03:00
|
|
|
useTitle(
|
|
|
|
`${account?.acct ? '@' + account.acct : 'Posts'}`,
|
2023-02-11 11:27:40 +03:00
|
|
|
'/:instance?/a/:id',
|
2023-02-06 11:35:03 +03:00
|
|
|
);
|
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]);
|
|
|
|
|
2023-02-04 08:18:23 +03:00
|
|
|
const { displayName, acct, emojis } = account;
|
|
|
|
|
2023-01-29 18:37:13 +03:00
|
|
|
return (
|
|
|
|
<Timeline
|
|
|
|
key={id}
|
|
|
|
title={`${account?.acct ? '@' + account.acct : 'Posts'}`}
|
2023-01-31 14:08:10 +03:00
|
|
|
titleComponent={
|
|
|
|
<h1
|
|
|
|
class="header-account"
|
2023-02-17 05:14:44 +03:00
|
|
|
// onClick={() => {
|
|
|
|
// states.showAccount = {
|
|
|
|
// account,
|
|
|
|
// instance,
|
|
|
|
// };
|
|
|
|
// }}
|
2023-01-31 14:08:10 +03:00
|
|
|
>
|
2023-02-04 08:18:23 +03:00
|
|
|
<b
|
|
|
|
dangerouslySetInnerHTML={{
|
|
|
|
__html: emojifyText(displayName, emojis),
|
|
|
|
}}
|
|
|
|
/>
|
2023-01-31 14:08:10 +03:00
|
|
|
<div>
|
2023-02-04 08:18:23 +03:00
|
|
|
<span>@{acct}</span>
|
2023-01-31 14:08:10 +03:00
|
|
|
</div>
|
|
|
|
</h1>
|
|
|
|
}
|
2023-01-29 18:37:13 +03:00
|
|
|
id="account_statuses"
|
2023-02-06 11:35:03 +03:00
|
|
|
instance={instance}
|
2023-01-29 18:37:13 +03:00
|
|
|
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;
|