Add post composer

This commit is contained in:
Paul Frazee 2022-07-22 16:06:51 -05:00
parent ce83648f9d
commit 7f04ac172e
24 changed files with 312 additions and 62 deletions

View file

@ -1,27 +0,0 @@
import React, {useEffect} from 'react'
import {View} from 'react-native'
import {Shell} from '../shell'
import {Feed} from '../com/feed/Feed'
import type {RootTabsScreenProps} from '../routes/types'
import {useStores} from '../../state'
export function Home({navigation}: RootTabsScreenProps<'HomeTab'>) {
const store = useStores()
useEffect(() => {
console.log('Fetching home feed')
store.homeFeed.setup()
}, [store.homeFeed])
const onNavigateContent = (screen: string, props: Record<string, string>) => {
// @ts-ignore it's up to the callers to supply correct params -prf
navigation.navigate(screen, props)
}
return (
<Shell>
<View>
<Feed feed={store.homeFeed} onNavigateContent={onNavigateContent} />
</View>
</Shell>
)
}

View file

@ -0,0 +1,50 @@
import React, {useLayoutEffect, useRef} from 'react'
import {Text, TouchableOpacity} from 'react-native'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {Shell} from '../../shell'
import type {RootTabsScreenProps} from '../../routes/types'
import {Composer as ComposerComponent} from '../../com/composer/Composer'
export const Composer = ({
navigation,
route,
}: RootTabsScreenProps<'Composer'>) => {
const {replyTo} = route.params
const ref = useRef<{publish: () => Promise<boolean>}>()
useLayoutEffect(() => {
navigation.setOptions({
headerShown: true,
headerTitle: replyTo ? 'Reply' : 'New Post',
headerLeft: () => (
<TouchableOpacity onPress={() => navigation.goBack()}>
<FontAwesomeIcon icon="x" />
</TouchableOpacity>
),
headerRight: () => (
<TouchableOpacity
onPress={() => {
if (!ref.current) {
return
}
ref.current.publish().then(
posted => {
if (posted) {
navigation.goBack()
}
},
err => console.error('Failed to create post', err),
)
}}>
<Text>Post</Text>
</TouchableOpacity>
),
})
}, [navigation, replyTo, ref])
return (
<Shell>
<ComposerComponent ref={ref} replyTo={replyTo} />
</Shell>
)
}

View file

@ -0,0 +1,59 @@
import React, {useEffect, useLayoutEffect} from 'react'
import {Image, StyleSheet, TouchableOpacity, View} from 'react-native'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {Shell} from '../../shell'
import {Feed} from '../../com/feed/Feed'
import type {RootTabsScreenProps} from '../../routes/types'
import {useStores} from '../../../state'
import {AVIS} from '../../lib/assets'
export function Home({navigation}: RootTabsScreenProps<'HomeTab'>) {
const store = useStores()
useEffect(() => {
console.log('Fetching home feed')
store.homeFeed.setup()
}, [store.homeFeed])
const onNavigateContent = (screen: string, props: Record<string, string>) => {
// @ts-ignore it's up to the callers to supply correct params -prf
navigation.navigate(screen, props)
}
useLayoutEffect(() => {
navigation.setOptions({
headerShown: true,
headerTitle: 'V I B E',
headerLeft: () => (
<TouchableOpacity
onPress={() => navigation.push('Profile', {name: 'alice.com'})}>
<Image source={AVIS['alice.com']} style={styles.avi} />
</TouchableOpacity>
),
headerRight: () => (
<TouchableOpacity
onPress={() => {
navigation.push('Composer', {})
}}>
<FontAwesomeIcon icon="plus" style={{color: '#006bf7'}} />
</TouchableOpacity>
),
})
}, [navigation])
return (
<Shell>
<View>
<Feed feed={store.homeFeed} onNavigateContent={onNavigateContent} />
</View>
</Shell>
)
}
const styles = StyleSheet.create({
avi: {
width: 20,
height: 20,
borderRadius: 10,
resizeMode: 'cover',
},
})

View file

@ -1,7 +1,7 @@
import React from 'react'
import {Text, View} from 'react-native'
import {observer} from 'mobx-react-lite'
import {Shell} from '../shell'
import {Shell} from '../../shell'
// import type {RootTabsScreenProps} from '../routes/types'
// import {useStores} from '../../state'

View file

@ -1,7 +1,7 @@
import React from 'react'
import {Shell} from '../shell'
import {Shell} from '../../shell'
import {ScrollView, Text, View} from 'react-native'
import type {RootTabsScreenProps} from '../routes/types'
import type {RootTabsScreenProps} from '../../routes/types'
export const Menu = (_props: RootTabsScreenProps<'MenuTab'>) => {
return (

View file

@ -1,7 +1,7 @@
import React from 'react'
import {Shell} from '../shell'
import {Shell} from '../../shell'
import {Text, Button, View} from 'react-native'
import type {RootTabsScreenProps} from '../routes/types'
import type {RootTabsScreenProps} from '../../routes/types'
export const NotFound = ({navigation}: RootTabsScreenProps<'NotFound'>) => {
return (

View file

@ -1,7 +1,7 @@
import React from 'react'
import {Shell} from '../shell'
import {Shell} from '../../shell'
import {Text, View} from 'react-native'
import type {RootTabsScreenProps} from '../routes/types'
import type {RootTabsScreenProps} from '../../routes/types'
export const Notifications = (
_props: RootTabsScreenProps<'NotificationsTab'>,

View file

@ -1,7 +1,7 @@
import React from 'react'
import {Shell} from '../shell'
import {Shell} from '../../shell'
import {Text, View} from 'react-native'
import type {RootTabsScreenProps} from '../routes/types'
import type {RootTabsScreenProps} from '../../routes/types'
export const Search = (_props: RootTabsScreenProps<'SearchTab'>) => {
return (

View file

@ -1,7 +1,7 @@
import React from 'react'
import {Text, View} from 'react-native'
import {observer} from 'mobx-react-lite'
import {Shell} from '../shell'
import {Shell} from '../../shell'
// import type {RootTabsScreenProps} from '../routes/types'
// import {useStores} from '../../state'