diff options
Diffstat (limited to 'src/view/com')
-rw-r--r-- | src/view/com/composer/Prompt.tsx | 63 | ||||
-rw-r--r-- | src/view/com/posts/Feed.tsx | 15 |
2 files changed, 76 insertions, 2 deletions
diff --git a/src/view/com/composer/Prompt.tsx b/src/view/com/composer/Prompt.tsx new file mode 100644 index 000000000..4a84c7160 --- /dev/null +++ b/src/view/com/composer/Prompt.tsx @@ -0,0 +1,63 @@ +import React from 'react' +import {StyleSheet, Text, TouchableOpacity, View} from 'react-native' +import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' +import {colors} from '../../lib/styles' +import {useStores} from '../../../state' +import {UserAvatar} from '../util/UserAvatar' + +export function ComposePrompt({onPressCompose}: {onPressCompose: () => void}) { + const store = useStores() + const onPressAvatar = () => { + store.nav.navigate(`/profile/${store.me.handle}`) + } + return ( + <TouchableOpacity style={styles.container} onPress={onPressCompose}> + <TouchableOpacity style={styles.avatar} onPress={onPressAvatar}> + <UserAvatar + size={50} + handle={store.me.handle || ''} + displayName={store.me.displayName} + /> + </TouchableOpacity> + <View style={styles.textContainer}> + <Text style={styles.text}>What's happening?</Text> + </View> + <View style={styles.btn}> + <Text style={styles.btnText}>Post</Text> + </View> + </TouchableOpacity> + ) +} + +const styles = StyleSheet.create({ + container: { + borderRadius: 6, + margin: 2, + marginBottom: 0, + paddingHorizontal: 10, + paddingVertical: 10, + flexDirection: 'row', + alignItems: 'center', + backgroundColor: colors.white, + }, + avatar: { + width: 50, + }, + textContainer: { + marginLeft: 10, + flex: 1, + }, + text: { + color: colors.gray4, + fontSize: 17, + }, + btn: { + backgroundColor: colors.gray1, + paddingVertical: 6, + paddingHorizontal: 14, + borderRadius: 30, + }, + btnText: { + color: colors.gray5, + }, +}) diff --git a/src/view/com/posts/Feed.tsx b/src/view/com/posts/Feed.tsx index d10be821f..3a2bc6189 100644 --- a/src/view/com/posts/Feed.tsx +++ b/src/view/com/posts/Feed.tsx @@ -6,23 +6,34 @@ import {EmptyState} from '../util/EmptyState' import {ErrorMessage} from '../util/ErrorMessage' import {FeedModel, FeedItemModel} from '../../../state/models/feed-view' import {FeedItem} from './FeedItem' +import {ComposePrompt} from '../composer/Prompt' + +const COMPOSE_PROMPT_ITEM = {_reactKey: '__prompt__'} export const Feed = observer(function Feed({ feed, style, scrollElRef, + onPressCompose, onPressTryAgain, }: { feed: FeedModel style?: StyleProp<ViewStyle> scrollElRef?: MutableRefObject<FlatList<any> | null> + onPressCompose?: () => void onPressTryAgain?: () => void }) { // TODO optimize renderItem or FeedItem, we're getting this notice from RN: -prf // VirtualizedList: You have a large list that is slow to update - make sure your // renderItem function renders components that follow React performance best practices // like PureComponent, shouldComponentUpdate, etc - const renderItem = ({item}: {item: FeedItemModel}) => <FeedItem item={item} /> + const renderItem = ({item}: {item: FeedItemModel}) => { + if (item === COMPOSE_PROMPT_ITEM) { + return <ComposePrompt onPressCompose={onPressCompose} /> + } else { + return <FeedItem item={item} /> + } + } const onRefresh = () => { feed.refresh().catch(err => console.error('Failed to refresh', err)) } @@ -45,7 +56,7 @@ export const Feed = observer(function Feed({ {feed.hasContent && ( <FlatList ref={scrollElRef} - data={feed.feed.slice()} + data={[COMPOSE_PROMPT_ITEM].concat(feed.feed.slice())} keyExtractor={item => item._reactKey} renderItem={renderItem} refreshing={feed.isRefreshing} |