Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refs #11 Show ancestors and descendants in status detail #186

Merged
merged 1 commit into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 52 additions & 14 deletions src/components/detail/Status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Icon } from '@rsuite/icons'
import { Entity, MegalodonInterface } from 'megalodon'
import { useCallback, useEffect, useState } from 'react'
import { BsX } from 'react-icons/bs'
import { Button, Container, Content, Header } from 'rsuite'
import { Button, Container, Content, Header, List } from 'rsuite'
import { Server } from 'src/entities/server'
import Status from '../timelines/status/Status'

Expand All @@ -17,12 +17,19 @@ type Props = {

const StatusDetail: React.FC<Props> = props => {
const [status, setStatus] = useState(props.status)
const [ancestors, setAncestors] = useState<Array<Entity.Status>>([])
const [descendants, setDescendants] = useState<Array<Entity.Status>>([])

useEffect(() => {
setAncestors([])
setDescendants([])
setStatus(props.status)
const f = async () => {
const res = await props.client.getStatus(props.status.id)
setStatus(res.data)
const s = await props.client.getStatus(props.status.id)
setStatus(s.data)
const c = await props.client.getStatusContext(props.status.id)
setAncestors(c.data.ancestors)
setDescendants(c.data.descendants)
}
f()
}, [props.status, props.client])
Expand All @@ -33,11 +40,36 @@ const StatusDetail: React.FC<Props> = props => {
setStatus(updated)
} else if (status.reblog && status.reblog.id === updated.id) {
setStatus(Object.assign({}, status, { reblog: updated }))
} else if (updated.reblog && updated.reblog && status.reblog.id === updated.reblog.id) {
} else if (status.reblog && updated.reblog && status.reblog.id === updated.reblog.id) {
setStatus(Object.assign({}, status, { reblog: updated.reblog }))
}
setAncestors(last =>
last.map(status => {
if (status.id === updated.id) {
return updated
} else if (status.reblog && status.reblog.id === updated.id) {
return Object.assign({}, status, { reblog: updated })
} else if (status.reblog && updated.reblog && status.reblog.id === updated.reblog.id) {
return Object.assign({}, status, { reblog: updated.reblog })
}
return status
})
)

setDescendants(last =>
last.map(status => {
if (status.id === updated.id) {
return updated
} else if (status.reblog && status.reblog.id === updated.id) {
return Object.assign({}, status, { reblog: updated })
} else if (status.reblog && updated.reblog && status.reblog.id === updated.reblog.id) {
return Object.assign({}, status, { reblog: updated.reblog })
}
return status
})
)
},
[status, setStatus]
[status, setStatus, ancestors, setAncestors, descendants, setDescendants]
)

return (
Expand All @@ -48,15 +80,21 @@ const StatusDetail: React.FC<Props> = props => {
</Button>
</Header>
<Content style={{ height: '100%' }}>
<Status
status={status}
client={props.client}
server={props.server}
updateStatus={updateStatus}
openMedia={props.openMedia}
setReplyOpened={() => null}
setStatusDetail={props.setStatusDetail}
/>
<List hover style={{ width: '340px', height: '100%' }}>
{[...ancestors, status, ...descendants].map(status => (
<div key={status.id}>
<Status
status={status}
client={props.client}
server={props.server}
updateStatus={updateStatus}
openMedia={props.openMedia}
setReplyOpened={() => null}
setStatusDetail={props.setStatusDetail}
/>
</div>
))}
</List>
</Content>
</Container>
)
Expand Down
2 changes: 1 addition & 1 deletion src/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const TIMELINE_STATUSES_COUNT = 40
export const TIMELINE_STATUSES_COUNT = 20
export const TIMELINE_MAX_STATUSES = 2147483647
export const USER_AGENT = 'Fedistar'