2023-12-02 05:30:01 +01:00
|
|
|
import Status from '@/components/timelines/status/Status'
|
2023-12-11 16:00:44 +01:00
|
|
|
import { Account } from '@/db'
|
2023-12-02 05:30:01 +01:00
|
|
|
import { Entity, MegalodonInterface } from 'megalodon'
|
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
client: MegalodonInterface
|
2023-12-11 16:00:44 +01:00
|
|
|
account: Account
|
2023-12-02 05:30:01 +01:00
|
|
|
user_id: string
|
2023-12-02 11:26:45 +01:00
|
|
|
openMedia: (media: Entity.Attachment) => void
|
2023-12-02 05:30:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function Timeline(props: Props) {
|
|
|
|
const [statuses, setStatuses] = useState<Array<Entity.Status>>([])
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (props.user_id) {
|
|
|
|
const f = async () => {
|
|
|
|
const res = await props.client.getAccountStatuses(props.user_id)
|
|
|
|
setStatuses(res.data)
|
|
|
|
}
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
}, [props.user_id, props.client])
|
|
|
|
|
|
|
|
const updateStatus = (current: Array<Entity.Status>, status: Entity.Status) => {
|
|
|
|
const renew = current.map(s => {
|
|
|
|
if (s.id === status.id) {
|
|
|
|
return status
|
|
|
|
} else if (s.reblog && s.reblog.id === status.id) {
|
|
|
|
return Object.assign({}, s, { reblog: status })
|
|
|
|
} else if (status.reblog && s.id === status.reblog.id) {
|
|
|
|
return status.reblog
|
|
|
|
} else if (status.reblog && s.reblog && s.reblog.id === status.reblog.id) {
|
|
|
|
return Object.assign({}, s, { reblog: status.reblog })
|
|
|
|
} else {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return renew
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{statuses.map((status, index) => (
|
|
|
|
<Status
|
|
|
|
client={props.client}
|
2023-12-11 16:00:44 +01:00
|
|
|
account={props.account}
|
2023-12-02 05:30:01 +01:00
|
|
|
status={status}
|
|
|
|
key={index}
|
|
|
|
onRefresh={status => setStatuses(current => updateStatus(current, status))}
|
2023-12-02 11:26:45 +01:00
|
|
|
openMedia={props.openMedia}
|
2024-02-27 12:49:27 +01:00
|
|
|
filters={[]}
|
2023-12-02 05:30:01 +01:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|