Add the ability to navigate to posts within a thread

This commit is contained in:
Paul Frazee 2022-07-21 13:07:24 -05:00
parent 139c9deb75
commit 28dbc5f5e6
7 changed files with 46 additions and 20 deletions

View file

@ -78,6 +78,9 @@ export const PostThread = observer(function PostThread({
function* flattenThread(
post: PostThreadViewPostModel,
): Generator<PostThreadViewPostModel, void> {
if (post.parent) {
yield* flattenThread(post.parent)
}
yield post
if (post.replies?.length) {
for (const reply of post.replies) {

View file

@ -8,7 +8,7 @@ import {
TouchableOpacity,
View,
} from 'react-native'
import {bsky} from '@adxp/mock-api'
import {bsky, AdxUri} from '@adxp/mock-api'
import moment from 'moment'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {OnNavigateContent} from '../../routes/types'
@ -31,7 +31,8 @@ function iter<T>(n: number, fn: (i: number) => T): Array<T> {
}
export const PostThreadItem = observer(function PostThreadItem({
item, // onNavigateContent,
item,
onNavigateContent,
}: {
item: PostThreadViewPostModel
onNavigateContent: OnNavigateContent
@ -39,12 +40,16 @@ export const PostThreadItem = observer(function PostThreadItem({
const record = item.record as unknown as bsky.Post.Record
const hasEngagement = item.likeCount || item.repostCount
const onPressOuter = () => {
// TODO onNavigateContent
const urip = new AdxUri(item.uri)
onNavigateContent('PostThread', {
name: item.author.name,
recordKey: urip.recordKey,
})
}
return (
<TouchableOpacity style={styles.outer} onPress={onPressOuter}>
<View style={styles.layout}>
{iter(item._depth, () => (
{iter(Math.abs(item._depth), () => (
<View style={styles.replyBar} />
))}
<View style={styles.layoutAvi}>
@ -143,7 +148,7 @@ const styles = StyleSheet.create({
},
replyBar: {
width: 5,
backgroundColor: '#d4f0ff',
backgroundColor: 'gray',
marginRight: 2,
},
layoutAvi: {

View file

@ -54,20 +54,24 @@ const tabBarScreenOptions = ({
route: RouteProp<ParamListBase, string>
}) => ({
headerShown: false,
tabBarIcon: (_state: {focused: boolean; color: string; size: number}) => {
tabBarIcon: (state: {focused: boolean; color: string; size: number}) => {
switch (route.name) {
case 'Home':
return <FontAwesomeIcon icon="house" />
return <FontAwesomeIcon icon="house" style={{color: state.color}} />
case 'Search':
return <FontAwesomeIcon icon="magnifying-glass" />
return (
<FontAwesomeIcon
icon="magnifying-glass"
style={{color: state.color}}
/>
)
case 'Notifications':
return <FontAwesomeIcon icon="bell" />
return <FontAwesomeIcon icon="bell" style={{color: state.color}} />
case 'Menu':
return <FontAwesomeIcon icon="bars" />
return <FontAwesomeIcon icon="bars" style={{color: state.color}} />
default:
return <FontAwesomeIcon icon="bars" />
return <FontAwesomeIcon icon="bars" style={{color: state.color}} />
}
// return <Text>{route.name?.[0] || ''}</Text>
},
})