2023-03-11 09:05:56 +03:00
|
|
|
import { useEffect, useMemo, useRef, useState } from 'preact/hooks';
|
2023-04-03 05:36:31 +03:00
|
|
|
import { useParams, useSearchParams } from 'react-router-dom';
|
2023-02-03 16:08:08 +03:00
|
|
|
import { useSnapshot } from 'valtio';
|
2023-01-29 18:37:13 +03:00
|
|
|
|
2023-03-11 09:05:56 +03:00
|
|
|
import AccountInfo from '../components/account-info';
|
2023-04-03 05:36:31 +03:00
|
|
|
import Icon from '../components/icon';
|
|
|
|
import Link from '../components/link';
|
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-03-18 15:20:48 +03:00
|
|
|
import { saveStatus } 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();
|
2023-04-03 05:36:31 +03:00
|
|
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
|
|
const excludeReplies = !searchParams.get('replies');
|
|
|
|
const tagged = searchParams.get('tagged');
|
|
|
|
const media = !!searchParams.get('media');
|
|
|
|
console.log({ excludeReplies });
|
2023-03-11 09:05:56 +03:00
|
|
|
const { masto, instance, authenticated } = 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();
|
2023-04-03 05:36:31 +03:00
|
|
|
if (pinnedStatuses?.length && !tagged && !media) {
|
2023-02-17 05:12:59 +03:00
|
|
|
pinnedStatuses.forEach((status) => {
|
|
|
|
status._pinned = true;
|
2023-03-18 17:25:02 +03:00
|
|
|
saveStatus(status, instance);
|
2023-02-17 05:12:59 +03:00
|
|
|
});
|
2023-03-11 09:05:56 +03:00
|
|
|
if (pinnedStatuses.length >= 3) {
|
2023-02-17 05:55:16 +03:00
|
|
|
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-04-03 05:36:31 +03:00
|
|
|
exclude_replies: excludeReplies,
|
|
|
|
only_media: media,
|
|
|
|
tagged,
|
2023-01-29 18:37:13 +03:00
|
|
|
});
|
|
|
|
}
|
2023-02-17 05:12:59 +03:00
|
|
|
const { value, done } = await accountStatusesIterator.current.next();
|
|
|
|
if (value?.length) {
|
|
|
|
results.push(...value);
|
2023-03-18 15:20:48 +03:00
|
|
|
|
|
|
|
value.forEach((item) => {
|
|
|
|
saveStatus(item, instance);
|
|
|
|
});
|
2023-02-17 05:12:59 +03:00
|
|
|
}
|
|
|
|
return {
|
|
|
|
value: results,
|
|
|
|
done,
|
|
|
|
};
|
2023-01-29 18:37:13 +03:00
|
|
|
}
|
|
|
|
|
2023-03-11 09:05:56 +03:00
|
|
|
const [account, setAccount] = useState();
|
2023-04-03 05:36:31 +03:00
|
|
|
const [featuredTags, setFeaturedTags] = useState([]);
|
2023-02-06 11:35:03 +03:00
|
|
|
useTitle(
|
2023-03-13 05:07:22 +03:00
|
|
|
`${account?.displayName ? account.displayName + ' ' : ''}@${
|
|
|
|
account?.acct ? account.acct : 'Account 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);
|
|
|
|
}
|
2023-04-03 05:36:31 +03:00
|
|
|
try {
|
|
|
|
const featuredTags = await masto.v1.accounts.listFeaturedTags(id);
|
|
|
|
console.log({ featuredTags });
|
|
|
|
setFeaturedTags(featuredTags);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
2023-01-29 18:37:13 +03:00
|
|
|
})();
|
|
|
|
}, [id]);
|
|
|
|
|
2023-03-11 09:05:56 +03:00
|
|
|
const { displayName, acct, emojis } = account || {};
|
|
|
|
|
2023-03-11 16:33:55 +03:00
|
|
|
const TimelineStart = useMemo(() => {
|
|
|
|
const cachedAccount = snapStates.accounts[`${id}@${instance}`];
|
|
|
|
return (
|
2023-04-03 05:36:31 +03:00
|
|
|
<>
|
|
|
|
<AccountInfo
|
|
|
|
instance={instance}
|
|
|
|
account={cachedAccount || id}
|
|
|
|
fetchAccount={() => masto.v1.accounts.fetch(id)}
|
|
|
|
authenticated={authenticated}
|
|
|
|
standalone
|
|
|
|
/>
|
|
|
|
<div class="filter-bar">
|
|
|
|
<Icon icon="filter" class="insignificant" size="l" />
|
|
|
|
<Link
|
|
|
|
to={`/${instance}/a/${id}${excludeReplies ? '?replies=1' : ''}`}
|
|
|
|
class={excludeReplies ? '' : 'is-active'}
|
|
|
|
>
|
|
|
|
+ Replies
|
|
|
|
</Link>
|
|
|
|
<Link
|
|
|
|
to={`/${instance}/a/${id}${media ? '' : '?media=1'}`}
|
|
|
|
class={media ? 'is-active' : ''}
|
|
|
|
>
|
|
|
|
Media
|
|
|
|
</Link>
|
|
|
|
{featuredTags.map((tag) => (
|
|
|
|
<Link
|
|
|
|
to={`/${instance}/a/${id}${
|
|
|
|
tagged === tag.name
|
|
|
|
? ''
|
|
|
|
: `?tagged=${encodeURIComponent(tag.name)}`
|
|
|
|
}`}
|
|
|
|
class={tagged === tag.name ? 'is-active' : ''}
|
|
|
|
>
|
|
|
|
<span>
|
|
|
|
<span class="more-insignificant">#</span>
|
|
|
|
{tag.name}
|
|
|
|
</span>
|
|
|
|
{
|
|
|
|
// The count differs based on instance 😅
|
|
|
|
}
|
|
|
|
{/* <span class="filter-count">{tag.statusesCount}</span> */}
|
|
|
|
</Link>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</>
|
2023-03-11 16:33:55 +03:00
|
|
|
);
|
2023-04-03 05:36:31 +03:00
|
|
|
}, [
|
|
|
|
id,
|
|
|
|
instance,
|
|
|
|
authenticated,
|
|
|
|
excludeReplies,
|
|
|
|
featuredTags,
|
|
|
|
tagged,
|
|
|
|
media,
|
|
|
|
]);
|
2023-02-04 08:18:23 +03:00
|
|
|
|
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-02-27 18:59:41 +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-03-18 15:20:48 +03:00
|
|
|
useItemID
|
2023-02-03 16:08:08 +03:00
|
|
|
boostsCarousel={snapStates.settings.boostsCarousel}
|
2023-03-11 09:05:56 +03:00
|
|
|
timelineStart={TimelineStart}
|
2023-04-03 05:36:31 +03:00
|
|
|
refresh={excludeReplies + tagged + media}
|
2023-01-29 18:37:13 +03:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AccountStatuses;
|