Tree view threads experiment (#1480)
* Add tree-view experiment to threads * Fix typo * Remove extra minimalshellmode call * Fix to parent line rendering * Fix extra border * Some ui cleanup
This commit is contained in:
parent
d2c253a284
commit
1af8e83d53
7 changed files with 178 additions and 53 deletions
|
@ -55,6 +55,7 @@ const LOAD_MORE = {
|
|||
const BOTTOM_COMPONENT = {
|
||||
_reactKey: '__bottom_component__',
|
||||
_isHighlightedPost: false,
|
||||
_showBorder: true,
|
||||
}
|
||||
type YieldedItem =
|
||||
| PostThreadItemModel
|
||||
|
@ -69,10 +70,12 @@ export const PostThread = observer(function PostThread({
|
|||
uri,
|
||||
view,
|
||||
onPressReply,
|
||||
treeView,
|
||||
}: {
|
||||
uri: string
|
||||
view: PostThreadModel
|
||||
onPressReply: () => void
|
||||
treeView: boolean
|
||||
}) {
|
||||
const pal = usePalette('default')
|
||||
const {isTablet} = useWebMediaQueries()
|
||||
|
@ -99,6 +102,13 @@ export const PostThread = observer(function PostThread({
|
|||
}
|
||||
return []
|
||||
}, [view.isLoadingFromCache, view.thread, maxVisible])
|
||||
const highlightedPostIndex = posts.findIndex(post => post._isHighlightedPost)
|
||||
const showBottomBorder =
|
||||
!treeView ||
|
||||
// in the treeview, only show the bottom border
|
||||
// if there are replies under the highlighted posts
|
||||
posts.findLast(v => v instanceof PostThreadItemModel) !==
|
||||
posts[highlightedPostIndex]
|
||||
useSetTitle(
|
||||
view.thread?.postRecord &&
|
||||
`${sanitizeDisplayName(
|
||||
|
@ -135,17 +145,16 @@ export const PostThread = observer(function PostThread({
|
|||
return
|
||||
}
|
||||
|
||||
const index = posts.findIndex(post => post._isHighlightedPost)
|
||||
if (index !== -1) {
|
||||
if (highlightedPostIndex !== -1) {
|
||||
ref.current?.scrollToIndex({
|
||||
index,
|
||||
index: highlightedPostIndex,
|
||||
animated: false,
|
||||
viewPosition: 0,
|
||||
})
|
||||
hasScrolledIntoView.current = true
|
||||
}
|
||||
}, [
|
||||
posts,
|
||||
highlightedPostIndex,
|
||||
view.hasContent,
|
||||
view.isFromCache,
|
||||
view.isLoadingFromCache,
|
||||
|
@ -184,7 +193,14 @@ export const PostThread = observer(function PostThread({
|
|||
</View>
|
||||
)
|
||||
} else if (item === REPLY_PROMPT) {
|
||||
return <ComposePrompt onPressCompose={onPressReply} />
|
||||
return (
|
||||
<View
|
||||
style={
|
||||
treeView && [pal.border, {borderBottomWidth: 1, marginBottom: 6}]
|
||||
}>
|
||||
{isDesktopWeb && <ComposePrompt onPressCompose={onPressReply} />}
|
||||
</View>
|
||||
)
|
||||
} else if (item === DELETED) {
|
||||
return (
|
||||
<View style={[pal.border, pal.viewLight, styles.itemContainer]}>
|
||||
|
@ -224,7 +240,18 @@ export const PostThread = observer(function PostThread({
|
|||
// due to some complexities with how flatlist works, this is the easiest way
|
||||
// I could find to get a border positioned directly under the last item
|
||||
// -prf
|
||||
return <View style={[pal.border, styles.bottomSpacer]} />
|
||||
return (
|
||||
<View
|
||||
style={[
|
||||
{height: 400},
|
||||
showBottomBorder && {
|
||||
borderTopWidth: 1,
|
||||
borderColor: pal.colors.border,
|
||||
},
|
||||
treeView && {marginTop: 10},
|
||||
]}
|
||||
/>
|
||||
)
|
||||
} else if (item === CHILD_SPINNER) {
|
||||
return (
|
||||
<View style={styles.childSpinner}>
|
||||
|
@ -240,12 +267,13 @@ export const PostThread = observer(function PostThread({
|
|||
item={item}
|
||||
onPostReply={onRefresh}
|
||||
hasPrecedingItem={prev?._showChildReplyLine}
|
||||
treeView={treeView}
|
||||
/>
|
||||
)
|
||||
}
|
||||
return <></>
|
||||
},
|
||||
[onRefresh, onPressReply, pal, posts, isTablet],
|
||||
[onRefresh, onPressReply, pal, posts, isTablet, treeView, showBottomBorder],
|
||||
)
|
||||
|
||||
// loading
|
||||
|
@ -377,7 +405,7 @@ function* flattenThread(
|
|||
}
|
||||
}
|
||||
yield post
|
||||
if (isDesktopWeb && post._isHighlightedPost) {
|
||||
if (post._isHighlightedPost) {
|
||||
yield REPLY_PROMPT
|
||||
}
|
||||
if (post.replies?.length) {
|
||||
|
@ -411,8 +439,4 @@ const styles = StyleSheet.create({
|
|||
paddingVertical: 10,
|
||||
},
|
||||
childSpinner: {},
|
||||
bottomSpacer: {
|
||||
height: 400,
|
||||
borderTopWidth: 1,
|
||||
},
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue