Add update checking to these pages
This commit is contained in:
parent
ee5ab3f22c
commit
ffc8d88f82
3 changed files with 85 additions and 3 deletions
|
@ -12,6 +12,8 @@ function Hashtags() {
|
||||||
const { masto, instance } = api({ instance: params.instance });
|
const { masto, instance } = api({ instance: params.instance });
|
||||||
const title = instance ? `#${hashtag} on ${instance}` : `#${hashtag}`;
|
const title = instance ? `#${hashtag} on ${instance}` : `#${hashtag}`;
|
||||||
useTitle(title, `/:instance?/t/:hashtag`);
|
useTitle(title, `/:instance?/t/:hashtag`);
|
||||||
|
const latestItem = useRef();
|
||||||
|
|
||||||
const hashtagsIterator = useRef();
|
const hashtagsIterator = useRef();
|
||||||
async function fetchHashtags(firstLoad) {
|
async function fetchHashtags(firstLoad) {
|
||||||
if (firstLoad || !hashtagsIterator.current) {
|
if (firstLoad || !hashtagsIterator.current) {
|
||||||
|
@ -19,7 +21,32 @@ function Hashtags() {
|
||||||
limit: LIMIT,
|
limit: LIMIT,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return await hashtagsIterator.current.next();
|
const results = await hashtagsIterator.current.next();
|
||||||
|
const { value } = results;
|
||||||
|
if (value?.length) {
|
||||||
|
if (firstLoad) {
|
||||||
|
latestItem.current = value[0].id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkForUpdates() {
|
||||||
|
try {
|
||||||
|
const results = await masto.v1.timelines
|
||||||
|
.listHashtag(hashtag, {
|
||||||
|
limit: 1,
|
||||||
|
since_id: latestItem.current,
|
||||||
|
})
|
||||||
|
.next();
|
||||||
|
const { value } = results;
|
||||||
|
if (value?.length) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -39,6 +66,7 @@ function Hashtags() {
|
||||||
emptyText="No one has posted anything with this tag yet."
|
emptyText="No one has posted anything with this tag yet."
|
||||||
errorText="Unable to load posts with this tag"
|
errorText="Unable to load posts with this tag"
|
||||||
fetchItems={fetchHashtags}
|
fetchItems={fetchHashtags}
|
||||||
|
checkForUpdates={checkForUpdates}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ const LIMIT = 20;
|
||||||
function List() {
|
function List() {
|
||||||
const { masto } = api();
|
const { masto } = api();
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
const latestItem = useRef();
|
||||||
|
|
||||||
const listIterator = useRef();
|
const listIterator = useRef();
|
||||||
async function fetchList(firstLoad) {
|
async function fetchList(firstLoad) {
|
||||||
if (firstLoad || !listIterator.current) {
|
if (firstLoad || !listIterator.current) {
|
||||||
|
@ -19,7 +21,30 @@ function List() {
|
||||||
limit: LIMIT,
|
limit: LIMIT,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return await listIterator.current.next();
|
const results = await listIterator.current.next();
|
||||||
|
const { value } = results;
|
||||||
|
if (value?.length) {
|
||||||
|
if (firstLoad) {
|
||||||
|
latestItem.current = value[0].id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkForUpdates() {
|
||||||
|
try {
|
||||||
|
const results = await masto.v1.timelines.listList(id, {
|
||||||
|
limit: 1,
|
||||||
|
since_id: latestItem.current,
|
||||||
|
});
|
||||||
|
const { value } = results;
|
||||||
|
if (value?.length) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const [title, setTitle] = useState(`List`);
|
const [title, setTitle] = useState(`List`);
|
||||||
|
@ -42,6 +67,7 @@ function List() {
|
||||||
emptyText="Nothing yet."
|
emptyText="Nothing yet."
|
||||||
errorText="Unable to load posts."
|
errorText="Unable to load posts."
|
||||||
fetchItems={fetchList}
|
fetchItems={fetchList}
|
||||||
|
checkForUpdates={checkForUpdates}
|
||||||
boostsCarousel
|
boostsCarousel
|
||||||
headerStart={
|
headerStart={
|
||||||
<Link to="/l" class="button plain">
|
<Link to="/l" class="button plain">
|
||||||
|
|
|
@ -14,6 +14,7 @@ function Public({ local }) {
|
||||||
const { masto, instance } = api({ instance: params.instance });
|
const { masto, instance } = api({ instance: params.instance });
|
||||||
const title = `${instance} (${isLocal ? 'local' : 'federated'})`;
|
const title = `${instance} (${isLocal ? 'local' : 'federated'})`;
|
||||||
useTitle(title, `:instance?/p/l?`);
|
useTitle(title, `:instance?/p/l?`);
|
||||||
|
const latestItem = useRef();
|
||||||
|
|
||||||
const publicIterator = useRef();
|
const publicIterator = useRef();
|
||||||
async function fetchPublic(firstLoad) {
|
async function fetchPublic(firstLoad) {
|
||||||
|
@ -23,7 +24,33 @@ function Public({ local }) {
|
||||||
local: isLocal,
|
local: isLocal,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return await publicIterator.current.next();
|
const results = await publicIterator.current.next();
|
||||||
|
const { value } = results;
|
||||||
|
if (value?.length) {
|
||||||
|
if (firstLoad) {
|
||||||
|
latestItem.current = value[0].id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkForUpdates() {
|
||||||
|
try {
|
||||||
|
const results = await masto.v1.timelines
|
||||||
|
.listPublic({
|
||||||
|
limit: 1,
|
||||||
|
local: isLocal,
|
||||||
|
since_id: latestItem.current,
|
||||||
|
})
|
||||||
|
.next();
|
||||||
|
const { value } = results;
|
||||||
|
if (value?.length) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -41,6 +68,7 @@ function Public({ local }) {
|
||||||
emptyText="No one has posted anything yet."
|
emptyText="No one has posted anything yet."
|
||||||
errorText="Unable to load posts"
|
errorText="Unable to load posts"
|
||||||
fetchItems={fetchPublic}
|
fetchItems={fetchPublic}
|
||||||
|
checkForUpdates={checkForUpdates}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue