Replace the FAB with a compose prompt at the top of the feed

This commit is contained in:
Paul Frazee 2022-11-20 11:20:08 -06:00
parent 39058cd36a
commit 8e3dc52536
5 changed files with 78 additions and 15 deletions

View file

@ -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}