Skip to content

Commit

Permalink
Better organize tRPC states
Browse files Browse the repository at this point in the history
  • Loading branch information
timothymiller committed Sep 18, 2023
1 parent e67feca commit 4db8aa3
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions packages/app/features/virtualized-list/screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,27 @@ import { SolitoImage } from 'solito/image'
export const VirtualizedListScreen = (): React.ReactNode => {
const query = trpc.car.all.useQuery()

if (query.isInitialLoading) {
return (
<YStack fullscreen flex={1} justifyContent="center" alignItems="center">
<Paragraph paddingBottom="$3">Loading...</Paragraph>
<Spinner />
</YStack>
)
}

return (
<YStack fullscreen flex={1}>
{query.data?.length ? (
<YStack fullscreen f={1}>
{query.isInitialLoading ? (
// Loading
<YStack fullscreen f={1} jc="center" ai="center">
<Paragraph pb="$3">Loading...</Paragraph>
<Spinner />
</YStack>
) : query.data?.length ? (
// Has Data
<VirtualList data={query.data} renderItem={CarListItem} itemHeight={80} />
) : query.error ? (
// Error
<YStack fullscreen f={1} jc="center" ai="center" p="$6">
<Paragraph>Error fetching cars: {query.error.message}</Paragraph>
</YStack>
) : (
<>
{query.error ? (
<YStack fullscreen flex={1} justifyContent="center" alignItems="center">
<Paragraph>Error fetching cars: {query.error.message}</Paragraph>
</YStack>
) : null}
{!query.isLoading && (
<YStack fullscreen flex={1} justifyContent="center" alignItems="center">
<Paragraph>No cars found.</Paragraph>
</YStack>
)}
</>
// Empty State
<YStack fullscreen f={1} jc="center" ai="center">
<Paragraph>No cars found.</Paragraph>
</YStack>
)}
</YStack>
)
Expand Down

1 comment on commit 4db8aa3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔ EAS production build completed

  • 🤖 Android build failed ❌
  • 🍏 IOS build failed ❌
Android QR IOS QR

Please sign in to comment.