Add profile view
This commit is contained in:
parent
29ed3d2ecf
commit
cc8a170204
14 changed files with 319 additions and 27 deletions
|
@ -17,6 +17,7 @@ export const FeedItem = observer(function FeedItem({
|
|||
onNavigateContent: OnNavigateContent
|
||||
}) {
|
||||
const record = item.record as unknown as bsky.Post.Record
|
||||
|
||||
const onPressOuter = () => {
|
||||
const urip = new AdxUri(item.uri)
|
||||
onNavigateContent('PostThread', {
|
||||
|
@ -24,6 +25,12 @@ export const FeedItem = observer(function FeedItem({
|
|||
recordKey: urip.recordKey,
|
||||
})
|
||||
}
|
||||
const onPressAuthor = () => {
|
||||
onNavigateContent('Profile', {
|
||||
name: item.author.name,
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<TouchableOpacity style={styles.outer} onPress={onPressOuter}>
|
||||
{item.repostedBy && (
|
||||
|
@ -35,18 +42,22 @@ export const FeedItem = observer(function FeedItem({
|
|||
</View>
|
||||
)}
|
||||
<View style={styles.layout}>
|
||||
<View style={styles.layoutAvi}>
|
||||
<TouchableOpacity style={styles.layoutAvi} onPress={onPressAuthor}>
|
||||
<Image
|
||||
style={styles.avi}
|
||||
source={AVIS[item.author.name] || AVIS['alice.com']}
|
||||
/>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
<View style={styles.layoutContent}>
|
||||
<View style={styles.meta}>
|
||||
<Text style={[styles.metaItem, s.f15, s.bold]}>
|
||||
<Text
|
||||
style={[styles.metaItem, s.f15, s.bold]}
|
||||
onPress={onPressAuthor}>
|
||||
{item.author.displayName}
|
||||
</Text>
|
||||
<Text style={[styles.metaItem, s.f14, s.gray]}>
|
||||
<Text
|
||||
style={[styles.metaItem, s.f14, s.gray]}
|
||||
onPress={onPressAuthor}>
|
||||
@{item.author.name}
|
||||
</Text>
|
||||
<Text style={[styles.metaItem, s.f14, s.gray]}>
|
||||
|
|
|
@ -30,7 +30,8 @@ export const PostThread = observer(function PostThread({
|
|||
newView.setup().catch(err => console.error('Failed to fetch thread', err))
|
||||
}, [uri, view?.params.uri, store])
|
||||
|
||||
// not yet setup
|
||||
// loading
|
||||
// =
|
||||
if (
|
||||
!view ||
|
||||
(view.isLoading && !view.isRefreshing) ||
|
||||
|
@ -44,6 +45,7 @@ export const PostThread = observer(function PostThread({
|
|||
}
|
||||
|
||||
// error
|
||||
// =
|
||||
if (view.hasError) {
|
||||
return (
|
||||
<View>
|
||||
|
@ -52,7 +54,8 @@ export const PostThread = observer(function PostThread({
|
|||
)
|
||||
}
|
||||
|
||||
// rendering
|
||||
// loaded
|
||||
// =
|
||||
const posts = Array.from(flattenThread(view.thread))
|
||||
const renderItem = ({item}: {item: PostThreadViewPostModel}) => (
|
||||
<PostThreadItem item={item} onNavigateContent={onNavigateContent} />
|
||||
|
|
|
@ -27,6 +27,7 @@ export const PostThreadItem = observer(function PostThreadItem({
|
|||
}) {
|
||||
const record = item.record as unknown as bsky.Post.Record
|
||||
const hasEngagement = item.likeCount || item.repostCount
|
||||
|
||||
const onPressOuter = () => {
|
||||
const urip = new AdxUri(item.uri)
|
||||
onNavigateContent('PostThread', {
|
||||
|
@ -34,24 +35,34 @@ export const PostThreadItem = observer(function PostThreadItem({
|
|||
recordKey: urip.recordKey,
|
||||
})
|
||||
}
|
||||
const onPressAuthor = () => {
|
||||
onNavigateContent('Profile', {
|
||||
name: item.author.name,
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<TouchableOpacity style={styles.outer} onPress={onPressOuter}>
|
||||
<View style={styles.layout}>
|
||||
{iter(Math.abs(item._depth), (i: number) => (
|
||||
<View key={i} style={styles.replyBar} />
|
||||
))}
|
||||
<View style={styles.layoutAvi}>
|
||||
<TouchableOpacity style={styles.layoutAvi} onPress={onPressAuthor}>
|
||||
<Image
|
||||
style={styles.avi}
|
||||
source={AVIS[item.author.name] || AVIS['alice.com']}
|
||||
/>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
<View style={styles.layoutContent}>
|
||||
<View style={styles.meta}>
|
||||
<Text style={[styles.metaItem, s.f15, s.bold]}>
|
||||
<Text
|
||||
style={[styles.metaItem, s.f15, s.bold]}
|
||||
onPress={onPressAuthor}>
|
||||
{item.author.displayName}
|
||||
</Text>
|
||||
<Text style={[styles.metaItem, s.f14, s.gray]}>
|
||||
<Text
|
||||
style={[styles.metaItem, s.f14, s.gray]}
|
||||
onPress={onPressAuthor}>
|
||||
@{item.author.name}
|
||||
</Text>
|
||||
<Text style={[styles.metaItem, s.f14, s.gray]}>
|
||||
|
|
105
src/view/com/profile/ProfileHeader.tsx
Normal file
105
src/view/com/profile/ProfileHeader.tsx
Normal file
|
@ -0,0 +1,105 @@
|
|||
import React, {useState, useEffect} from 'react'
|
||||
import {observer} from 'mobx-react-lite'
|
||||
import {ActivityIndicator, Image, StyleSheet, Text, View} from 'react-native'
|
||||
import {OnNavigateContent} from '../../routes/types'
|
||||
import {ProfileViewModel} from '../../../state/models/profile-view'
|
||||
import {useStores} from '../../../state'
|
||||
import {pluralize} from '../../lib/strings'
|
||||
import {s} from '../../lib/styles'
|
||||
import {AVIS} from '../../lib/assets'
|
||||
|
||||
export const ProfileHeader = observer(function ProfileHeader({
|
||||
user,
|
||||
}: // onNavigateContent,
|
||||
{
|
||||
user: string
|
||||
onNavigateContent: OnNavigateContent
|
||||
}) {
|
||||
const store = useStores()
|
||||
const [view, setView] = useState<ProfileViewModel | undefined>()
|
||||
|
||||
useEffect(() => {
|
||||
if (view?.params.user === user) {
|
||||
console.log('Profile header doing nothing')
|
||||
return // no change needed? or trigger refresh?
|
||||
}
|
||||
console.log('Fetching profile', user)
|
||||
const newView = new ProfileViewModel(store, {user: user})
|
||||
setView(newView)
|
||||
newView.setup().catch(err => console.error('Failed to fetch profile', err))
|
||||
}, [user, view?.params.user, store])
|
||||
|
||||
// loading
|
||||
// =
|
||||
if (
|
||||
!view ||
|
||||
(view.isLoading && !view.isRefreshing) ||
|
||||
view.params.user !== user
|
||||
) {
|
||||
return (
|
||||
<View>
|
||||
<ActivityIndicator />
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
// error
|
||||
// =
|
||||
if (view.hasError) {
|
||||
return (
|
||||
<View>
|
||||
<Text>{view.error}</Text>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
// loaded
|
||||
// =
|
||||
return (
|
||||
<View style={styles.outer}>
|
||||
<Image style={styles.avi} source={AVIS[view.name] || AVIS['alice.com']} />
|
||||
<View style={[styles.nameLine, s.mb2]}>
|
||||
<Text style={[s.bold, s.f18, s.mr2]}>{view.displayName}</Text>
|
||||
<Text style={[s.gray]}>@{view.name}</Text>
|
||||
</View>
|
||||
{view.description && (
|
||||
<Text style={[s.mb5, s.f15, s['lh15-1.3']]}>{view.description}</Text>
|
||||
)}
|
||||
<View style={s.flexRow}>
|
||||
<View style={[s.flexRow, s.mr10]}>
|
||||
<Text style={[s.bold, s.mr2]}>{view.followersCount}</Text>
|
||||
<Text style={s.gray}>
|
||||
{pluralize(view.followersCount, 'follower')}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={[s.flexRow, s.mr10]}>
|
||||
<Text style={[s.bold, s.mr2]}>{view.followsCount}</Text>
|
||||
<Text style={s.gray}>following</Text>
|
||||
</View>
|
||||
<View style={[s.flexRow, s.mr10]}>
|
||||
<Text style={[s.bold, s.mr2]}>{view.postsCount}</Text>
|
||||
<Text style={s.gray}>{pluralize(view.postsCount, 'post')}</Text>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
})
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
outer: {
|
||||
backgroundColor: '#fff',
|
||||
padding: 10,
|
||||
borderBottomWidth: 1,
|
||||
borderColor: '#eee',
|
||||
},
|
||||
avi: {
|
||||
width: 60,
|
||||
height: 60,
|
||||
borderRadius: 30,
|
||||
resizeMode: 'cover',
|
||||
},
|
||||
nameLine: {
|
||||
flexDirection: 'row',
|
||||
alignItems: 'flex-end',
|
||||
},
|
||||
})
|
|
@ -34,4 +34,21 @@ export const s = StyleSheet.create({
|
|||
// colors
|
||||
black: {color: 'black'},
|
||||
gray: {color: 'gray'},
|
||||
|
||||
// margins
|
||||
mr2: {marginRight: 2},
|
||||
mr5: {marginRight: 5},
|
||||
mr10: {marginRight: 10},
|
||||
ml2: {marginLeft: 2},
|
||||
ml5: {marginLeft: 5},
|
||||
ml10: {marginLeft: 10},
|
||||
mt2: {marginTop: 2},
|
||||
mt5: {marginTop: 5},
|
||||
mt10: {marginTop: 10},
|
||||
mb2: {marginBottom: 2},
|
||||
mb5: {marginBottom: 5},
|
||||
mb10: {marginBottom: 10},
|
||||
|
||||
// flex
|
||||
flexRow: {flexDirection: 'row'},
|
||||
})
|
||||
|
|
|
@ -56,6 +56,7 @@ const tabBarScreenOptions = ({
|
|||
route: RouteProp<ParamListBase, string>
|
||||
}) => ({
|
||||
headerShown: false,
|
||||
tabBarShowLabel: false,
|
||||
tabBarIcon: (state: {focused: boolean; color: string; size: number}) => {
|
||||
switch (route.name) {
|
||||
case 'HomeTab':
|
||||
|
|
|
@ -34,6 +34,7 @@ export const PostThread = ({
|
|||
// @ts-ignore it's up to the callers to supply correct params -prf
|
||||
navigation.push(screen, props)
|
||||
}
|
||||
|
||||
return (
|
||||
<Shell>
|
||||
<PostThreadComponent uri={uri} onNavigateContent={onNavigateContent} />
|
||||
|
|
|
@ -1,16 +1,43 @@
|
|||
import React from 'react'
|
||||
import React, {useState, useEffect} from 'react'
|
||||
import {Shell} from '../../shell'
|
||||
import {View, Text} from 'react-native'
|
||||
import type {RootTabsScreenProps} from '../../routes/types'
|
||||
import {FeedViewModel} from '../../../state/models/feed-view'
|
||||
import {useStores} from '../../../state'
|
||||
import {ProfileHeader} from '../../com/profile/ProfileHeader'
|
||||
import {Feed} from '../../com/feed/Feed'
|
||||
|
||||
export const Profile = ({
|
||||
navigation,
|
||||
route,
|
||||
}: RootTabsScreenProps<'Profile'>) => {
|
||||
const store = useStores()
|
||||
const [feedView, setFeedView] = useState<FeedViewModel | undefined>()
|
||||
|
||||
useEffect(() => {
|
||||
if (feedView?.params.author === route.params.name) {
|
||||
console.log('Profile feed view')
|
||||
return // no change needed? or trigger refresh?
|
||||
}
|
||||
console.log('Fetching profile feed view', route.params.name)
|
||||
const newFeedView = new FeedViewModel(store, {author: route.params.name})
|
||||
setFeedView(newFeedView)
|
||||
newFeedView.setup().catch(err => console.error('Failed to fetch feed', err))
|
||||
}, [route.params.name, feedView?.params.author, store])
|
||||
|
||||
const onNavigateContent = (screen: string, props: Record<string, string>) => {
|
||||
// @ts-ignore it's up to the callers to supply correct params -prf
|
||||
navigation.push(screen, props)
|
||||
}
|
||||
|
||||
export const Profile = ({route}: RootTabsScreenProps<'Profile'>) => {
|
||||
return (
|
||||
<Shell>
|
||||
<View style={{justifyContent: 'center', alignItems: 'center'}}>
|
||||
<Text style={{fontSize: 20, fontWeight: 'bold'}}>
|
||||
{route.params?.name}'s profile
|
||||
</Text>
|
||||
</View>
|
||||
<ProfileHeader
|
||||
user={route.params.name}
|
||||
onNavigateContent={onNavigateContent}
|
||||
/>
|
||||
{feedView && (
|
||||
<Feed feed={feedView} onNavigateContent={onNavigateContent} />
|
||||
)}
|
||||
</Shell>
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue