Load more statuses

This commit is contained in:
AkiraFukushima 2023-11-04 23:03:47 +09:00
parent ac047034fa
commit f829339d7b
No known key found for this signature in database
GPG Key ID: B6E51BAC4DE1A957
2 changed files with 22 additions and 2 deletions

View File

@ -1,7 +1,7 @@
import { Account } from '@/db'
import { TextInput } from 'flowbite-react'
import { Entity, MegalodonInterface } from 'megalodon'
import { useEffect, useState } from 'react'
import { useEffect, useState, useCallback } from 'react'
import { FormattedMessage, useIntl } from 'react-intl'
import { Virtuoso } from 'react-virtuoso'
import Notification from './notification/Notification'
@ -48,6 +48,16 @@ export default function Notifications(props: Props) {
setNotifications(renew)
}
const loadMore = useCallback(async () => {
console.debug('appending')
try {
const append = await loadNotifications(props.client, notifications[notifications.length - 1].id)
setNotifications(last => [...last, ...append])
} catch (err) {
console.error(err)
}
}, [props.client, notifications, setNotifications])
return (
<section className="h-full w-full">
<div className="w-full bg-blue-950 text-blue-100 p-2 flex justify-between">
@ -64,6 +74,7 @@ export default function Notifications(props: Props) {
<Virtuoso
style={{ height: '100%' }}
data={notifications}
endReached={loadMore}
itemContent={(_, notification) => (
<Notification client={props.client} notification={notification} onRefresh={updateStatus} key={notification.id} />
)}

View File

@ -1,7 +1,7 @@
import { Account } from '@/db'
import { TextInput } from 'flowbite-react'
import { Entity, MegalodonInterface } from 'megalodon'
import { useEffect, useState } from 'react'
import { useEffect, useState, useCallback } from 'react'
import { Virtuoso } from 'react-virtuoso'
import Status from './status/Status'
import { FormattedMessage, useIntl } from 'react-intl'
@ -64,6 +64,14 @@ export default function Timeline(props: Props) {
return renew
}
const loadMore = useCallback(async () => {
console.debug('appending')
const maxId = statuses[statuses.length - 1].id
const append = await loadTimeline(props.timeline, props.client, maxId)
setStatuses(last => [...last, ...append])
}, [props.client, statuses, setStatuses])
return (
<section className="h-full w-full">
<div className="w-full bg-blue-950 text-blue-100 p-2 flex justify-between">
@ -80,6 +88,7 @@ export default function Timeline(props: Props) {
<Virtuoso
style={{ height: '100%' }}
data={statuses}
endReached={loadMore}
itemContent={(_, status) => (
<Status
client={props.client}