Treeview: more UI tweaks (#2125)
* Treeview: more UI tweaks * Only show treeview when there are branching replies * Fix typeszio/stable
parent
818c6ae879
commit
00e1e56a7d
|
@ -141,6 +141,10 @@ function PostThreadLoaded({
|
||||||
)
|
)
|
||||||
const [maxVisible, setMaxVisible] = React.useState(100)
|
const [maxVisible, setMaxVisible] = React.useState(100)
|
||||||
const [isPTRing, setIsPTRing] = React.useState(false)
|
const [isPTRing, setIsPTRing] = React.useState(false)
|
||||||
|
const treeView = React.useMemo(
|
||||||
|
() => !!threadViewPrefs.lab_treeViewEnabled && hasBranchingReplies(thread),
|
||||||
|
[threadViewPrefs, thread],
|
||||||
|
)
|
||||||
|
|
||||||
// construct content
|
// construct content
|
||||||
const posts = React.useMemo(() => {
|
const posts = React.useMemo(() => {
|
||||||
|
@ -289,7 +293,7 @@ function PostThreadLoaded({
|
||||||
<PostThreadItem
|
<PostThreadItem
|
||||||
post={item.post}
|
post={item.post}
|
||||||
record={item.record}
|
record={item.record}
|
||||||
treeView={threadViewPrefs.lab_treeViewEnabled || false}
|
treeView={treeView}
|
||||||
depth={item.ctx.depth}
|
depth={item.ctx.depth}
|
||||||
prevPost={prev}
|
prevPost={prev}
|
||||||
nextPost={next}
|
nextPost={next}
|
||||||
|
@ -318,7 +322,7 @@ function PostThreadLoaded({
|
||||||
pal.colors.border,
|
pal.colors.border,
|
||||||
posts,
|
posts,
|
||||||
onRefresh,
|
onRefresh,
|
||||||
threadViewPrefs.lab_treeViewEnabled,
|
treeView,
|
||||||
_,
|
_,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -481,6 +485,19 @@ function* flattenThreadSkeleton(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasBranchingReplies(node: ThreadNode) {
|
||||||
|
if (node.type !== 'post') {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (!node.replies) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (node.replies.length === 1) {
|
||||||
|
return hasBranchingReplies(node.replies[0])
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
notFoundContainer: {
|
notFoundContainer: {
|
||||||
margin: 10,
|
margin: 10,
|
||||||
|
|
|
@ -436,13 +436,12 @@ let PostThreadItemLoaded = ({
|
||||||
} else {
|
} else {
|
||||||
const isThreadedChild = treeView && depth > 0
|
const isThreadedChild = treeView && depth > 0
|
||||||
const isThreadedChildAdjacentTop =
|
const isThreadedChildAdjacentTop =
|
||||||
isThreadedChild && prevPost?.ctx.depth === depth
|
isThreadedChild && prevPost?.ctx.depth === depth && depth !== 1
|
||||||
const isThreadedChildAdjacentBot =
|
const isThreadedChildAdjacentBot =
|
||||||
isThreadedChild && nextPost?.ctx.depth === depth
|
isThreadedChild && nextPost?.ctx.depth === depth
|
||||||
return (
|
return (
|
||||||
<PostOuterWrapper
|
<PostOuterWrapper
|
||||||
post={post}
|
post={post}
|
||||||
prevPost={prevPost}
|
|
||||||
depth={depth}
|
depth={depth}
|
||||||
showParentReplyLine={!!showParentReplyLine}
|
showParentReplyLine={!!showParentReplyLine}
|
||||||
treeView={treeView}
|
treeView={treeView}
|
||||||
|
@ -525,7 +524,7 @@ let PostThreadItemLoaded = ({
|
||||||
timestamp={post.indexedAt}
|
timestamp={post.indexedAt}
|
||||||
postHref={postHref}
|
postHref={postHref}
|
||||||
showAvatar={isThreadedChild}
|
showAvatar={isThreadedChild}
|
||||||
avatarSize={20}
|
avatarSize={28}
|
||||||
displayNameType="md-bold"
|
displayNameType="md-bold"
|
||||||
displayNameStyle={isThreadedChild && s.ml2}
|
displayNameStyle={isThreadedChild && s.ml2}
|
||||||
style={isThreadedChild && s.mb2}
|
style={isThreadedChild && s.mb2}
|
||||||
|
@ -606,7 +605,6 @@ PostThreadItemLoaded = memo(PostThreadItemLoaded)
|
||||||
|
|
||||||
function PostOuterWrapper({
|
function PostOuterWrapper({
|
||||||
post,
|
post,
|
||||||
prevPost,
|
|
||||||
treeView,
|
treeView,
|
||||||
depth,
|
depth,
|
||||||
showParentReplyLine,
|
showParentReplyLine,
|
||||||
|
@ -614,7 +612,6 @@ function PostOuterWrapper({
|
||||||
children,
|
children,
|
||||||
}: React.PropsWithChildren<{
|
}: React.PropsWithChildren<{
|
||||||
post: AppBskyFeedDefs.PostView
|
post: AppBskyFeedDefs.PostView
|
||||||
prevPost: ThreadPost | undefined
|
|
||||||
treeView: boolean
|
treeView: boolean
|
||||||
depth: number
|
depth: number
|
||||||
showParentReplyLine: boolean
|
showParentReplyLine: boolean
|
||||||
|
@ -632,18 +629,18 @@ function PostOuterWrapper({
|
||||||
styles.cursor,
|
styles.cursor,
|
||||||
{
|
{
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
paddingLeft: isMobile ? 10 : 6,
|
paddingHorizontal: isMobile ? 10 : 6,
|
||||||
borderTopWidth: !prevPost ? 1 : 0,
|
borderTopWidth: depth === 1 ? 1 : 0,
|
||||||
},
|
},
|
||||||
]}>
|
]}>
|
||||||
{Array.from(Array(depth)).map((_, n: number) => (
|
{Array.from(Array(depth - 1)).map((_, n: number) => (
|
||||||
<View
|
<View
|
||||||
key={`${post.uri}-padding-${n}`}
|
key={`${post.uri}-padding-${n}`}
|
||||||
style={{
|
style={{
|
||||||
borderLeftWidth: 2,
|
borderLeftWidth: 2,
|
||||||
borderLeftColor: pal.colors.border,
|
borderLeftColor: pal.colors.border,
|
||||||
marginLeft: isMobile ? 6 : 14,
|
marginLeft: isMobile ? 6 : 12,
|
||||||
paddingLeft: isMobile ? 6 : 12,
|
paddingLeft: isMobile ? 6 : 8,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
Loading…
Reference in New Issue