2023-01-28 13:52:18 +03:00
|
|
|
// EXPERIMENTAL: This is a work in progress and may not work as expected.
|
2023-02-05 19:17:19 +03:00
|
|
|
import { useRef } from 'preact/hooks';
|
2023-01-28 13:52:18 +03:00
|
|
|
import { useMatch, useParams } from 'react-router-dom';
|
|
|
|
|
|
|
|
import Timeline from '../components/timeline';
|
2023-02-05 19:17:19 +03:00
|
|
|
import { api } from '../utils/api';
|
2023-02-03 16:08:08 +03:00
|
|
|
import useTitle from '../utils/useTitle';
|
2023-01-28 13:52:18 +03:00
|
|
|
|
|
|
|
const LIMIT = 20;
|
|
|
|
|
|
|
|
function Public() {
|
2023-02-06 15:01:56 +03:00
|
|
|
const isLocal = !!useMatch('/:instance/p/l');
|
2023-02-06 11:35:03 +03:00
|
|
|
const params = useParams();
|
|
|
|
const { masto, instance } = api({ instance: params.instance });
|
2023-02-03 16:08:08 +03:00
|
|
|
const title = `${instance} (${isLocal ? 'local' : 'federated'})`;
|
2023-02-06 11:35:03 +03:00
|
|
|
useTitle(title, `/p/l?/:instance`);
|
2023-02-05 19:17:19 +03:00
|
|
|
|
|
|
|
const publicIterator = useRef();
|
2023-01-28 13:52:18 +03:00
|
|
|
async function fetchPublic(firstLoad) {
|
2023-02-05 19:17:19 +03:00
|
|
|
if (firstLoad || !publicIterator.current) {
|
|
|
|
publicIterator.current = masto.v1.timelines.listPublic({
|
|
|
|
limit: LIMIT,
|
|
|
|
local: isLocal,
|
|
|
|
});
|
2023-01-28 13:52:18 +03:00
|
|
|
}
|
2023-02-05 19:17:19 +03:00
|
|
|
return await publicIterator.current.next();
|
2023-01-28 13:52:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Timeline
|
|
|
|
key={instance + isLocal}
|
2023-02-03 16:08:08 +03:00
|
|
|
title={title}
|
2023-02-05 19:17:19 +03:00
|
|
|
titleComponent={
|
|
|
|
<h1 class="header-account">
|
|
|
|
<b>{instance}</b>
|
|
|
|
<div>{isLocal ? 'local' : 'federated'}</div>
|
|
|
|
</h1>
|
|
|
|
}
|
2023-01-28 13:52:18 +03:00
|
|
|
id="public"
|
2023-02-05 19:17:19 +03:00
|
|
|
instance={instance}
|
2023-01-28 13:52:18 +03:00
|
|
|
emptyText="No one has posted anything yet."
|
|
|
|
errorText="Unable to load posts"
|
|
|
|
fetchItems={fetchPublic}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Public;
|