Skip to content

Commit

Permalink
Simplify ListItems header rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
pfrazee committed Nov 1, 2023
1 parent 4ce013b commit 0525ce0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
9 changes: 3 additions & 6 deletions src/view/com/lists/ListItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
import {s} from 'lib/styles'
import {OnScrollCb} from 'lib/hooks/useOnMainScroll'

const HEADER_ITEM = {_reactKey: '__header__'}
const LOADING_ITEM = {_reactKey: '__loading__'}
const EMPTY_ITEM = {_reactKey: '__empty__'}
const ERROR_ITEM = {_reactKey: '__error__'}
Expand Down Expand Up @@ -60,7 +59,7 @@ export const ListItems = observer(function ListItemsImpl({
const {isMobile} = useWebMediaQueries()

const data = React.useMemo(() => {
let items: any[] = [HEADER_ITEM]
let items: any[] = []
if (list.hasLoaded) {
if (list.hasError) {
items = items.concat([ERROR_ITEM])
Expand Down Expand Up @@ -156,9 +155,7 @@ export const ListItems = observer(function ListItemsImpl({

const renderItem = React.useCallback(
({item}: {item: any}) => {
if (item === HEADER_ITEM) {
return renderHeader()
} else if (item === EMPTY_ITEM) {
if (item === EMPTY_ITEM) {
return renderEmptyState()
} else if (item === ERROR_ITEM) {
return (
Expand Down Expand Up @@ -190,7 +187,6 @@ export const ListItems = observer(function ListItemsImpl({
},
[
renderMemberButton,
renderHeader,
renderEmptyState,
list.error,
onPressTryAgain,
Expand All @@ -216,6 +212,7 @@ export const ListItems = observer(function ListItemsImpl({
data={data}
keyExtractor={(item: any) => item._reactKey}
renderItem={renderItem}
ListHeaderComponent={renderHeader}
ListFooterComponent={Footer}
refreshControl={
<RefreshControl
Expand Down
2 changes: 1 addition & 1 deletion src/view/com/profile/ProfileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const ProfileCard = observer(function ProfileCardImpl({
{profile.description as string}
</Text>
</View>
) : undefined}
) : null}
<FollowersList followers={followers} />
</Link>
)
Expand Down
2 changes: 1 addition & 1 deletion src/view/screens/ProfileList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ const AboutSection = React.forwardRef<SectionRef, AboutSectionProps>(

const renderHeader = React.useCallback(() => {
if (!list.data) {
return null
return <View />
}
return (
<View>
Expand Down

0 comments on commit 0525ce0

Please sign in to comment.