Handle linear view
This commit is contained in:
@@ -80,6 +80,7 @@ export function usePostThread({
|
|||||||
hasSession,
|
hasSession,
|
||||||
showMuted: state.shownHiddenReplyKinds.has(HiddenReplyKind.Muted),
|
showMuted: state.shownHiddenReplyKinds.has(HiddenReplyKind.Muted),
|
||||||
showHidden: state.shownHiddenReplyKinds.has(HiddenReplyKind.Hidden),
|
showHidden: state.shownHiddenReplyKinds.has(HiddenReplyKind.Hidden),
|
||||||
|
view: params.view,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ import {
|
|||||||
type ModerationOpts,
|
type ModerationOpts,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
|
|
||||||
import {HiddenReplyKind, type Slice} from '#/state/queries/usePostThread/types'
|
import {
|
||||||
|
HiddenReplyKind,
|
||||||
|
type PostThreadParams,
|
||||||
|
type Slice,
|
||||||
|
} from '#/state/queries/usePostThread/types'
|
||||||
import * as views from '#/state/queries/usePostThread/views'
|
import * as views from '#/state/queries/usePostThread/views'
|
||||||
|
|
||||||
export function flatten(
|
export function flatten(
|
||||||
@@ -13,14 +17,16 @@ export function flatten(
|
|||||||
hasSession,
|
hasSession,
|
||||||
showMuted,
|
showMuted,
|
||||||
showHidden,
|
showHidden,
|
||||||
|
view,
|
||||||
}: {
|
}: {
|
||||||
hasSession: boolean
|
hasSession: boolean
|
||||||
showMuted: boolean
|
showMuted: boolean
|
||||||
showHidden: boolean
|
showHidden: boolean
|
||||||
|
view: PostThreadParams['view']
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const flattened: Slice[] = sorted.items
|
const flattened: Slice[] = sorted.items
|
||||||
const parentsWithUnhydratedReplies = []
|
const parents = []
|
||||||
|
|
||||||
for (let i = 0; i < flattened.length; i++) {
|
for (let i = 0; i < flattened.length; i++) {
|
||||||
const item = flattened[i]
|
const item = flattened[i]
|
||||||
@@ -38,25 +44,30 @@ export function flatten(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const deepestParent =
|
const deepestParent = parents[parents.length - 1]
|
||||||
parentsWithUnhydratedReplies[parentsWithUnhydratedReplies.length - 1]
|
|
||||||
|
|
||||||
if (deepestParent) {
|
if (deepestParent) {
|
||||||
// next item is a sibling or an aunt/uncle
|
// next item is a sibling or an aunt/uncle
|
||||||
if (item.depth <= deepestParent.depth) {
|
if (item.depth <= deepestParent.depth) {
|
||||||
for (let pi = parentsWithUnhydratedReplies.length - 1; pi >= 0; pi--) {
|
for (let pi = parents.length - 1; pi >= 0; pi--) {
|
||||||
const parent = parentsWithUnhydratedReplies[pi]
|
const parent = parents[pi]
|
||||||
if (item.depth <= parent.depth) {
|
if (item.depth <= parent.depth) {
|
||||||
flattened.splice(
|
flattened.splice(
|
||||||
i + 1 + (pi - parentsWithUnhydratedReplies.length),
|
i + 1 + (pi - parents.length),
|
||||||
0,
|
0,
|
||||||
views.readMore({
|
views.readMore({
|
||||||
item,
|
item,
|
||||||
parent: parent,
|
parent: parent,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
parentsWithUnhydratedReplies.pop()
|
parents.pop()
|
||||||
|
|
||||||
|
// skip next iteration
|
||||||
i++
|
i++
|
||||||
|
|
||||||
|
if (view === 'linear') {
|
||||||
|
break
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -65,33 +76,36 @@ export function flatten(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (item.value.moreReplies > 0) {
|
if (item.value.moreReplies > 0) {
|
||||||
parentsWithUnhydratedReplies.push(item)
|
parents.push(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
const isLastIteration = i === flattened.length - 1
|
const isLastIteration = i === flattened.length - 1
|
||||||
|
|
||||||
if (isLastIteration) {
|
if (isLastIteration) {
|
||||||
const deepestParent =
|
const deepestParent = parents[parents.length - 1]
|
||||||
parentsWithUnhydratedReplies[parentsWithUnhydratedReplies.length - 1]
|
|
||||||
|
|
||||||
i++
|
|
||||||
|
|
||||||
if (deepestParent) {
|
if (deepestParent) {
|
||||||
// next item is a sibling or an aunt/uncle
|
// next item is a sibling or an aunt/uncle
|
||||||
if (deepestParent.depth <= item.depth) {
|
if (deepestParent.depth <= item.depth) {
|
||||||
for (let pi = parentsWithUnhydratedReplies.length - 1; pi >= 0; pi--) {
|
for (let pi = parents.length - 1; pi >= 0; pi--) {
|
||||||
const parent = parentsWithUnhydratedReplies[pi]
|
const parent = parents[pi]
|
||||||
if (parent.depth <= item.depth) {
|
if (parent.depth <= item.depth) {
|
||||||
flattened.splice(
|
flattened.splice(
|
||||||
i + 1 + (pi - parentsWithUnhydratedReplies.length),
|
i + 2 + (pi - parents.length),
|
||||||
0,
|
0,
|
||||||
views.readMore({
|
views.readMore({
|
||||||
item,
|
item,
|
||||||
parent: parent,
|
parent: parent,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
parentsWithUnhydratedReplies.pop()
|
parents.pop()
|
||||||
|
|
||||||
|
// skip next iteration
|
||||||
i++
|
i++
|
||||||
|
|
||||||
|
if (view === 'linear') {
|
||||||
|
break
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user