fix: make proper use of type predicates and minor cleanup to avoid double ternary and reduce computation

This commit is contained in:
Christian Andolf
2025-04-28 14:57:59 +02:00
parent 265cecc22a
commit 8ed74f08a4
2 changed files with 16 additions and 18 deletions

View File

@@ -36,22 +36,21 @@ export default function ClientPreviousStays({
}
)
if (isLoading) {
return <LoadingSpinner />
}
function loadMoreData() {
if (hasNextPage) {
fetchNextPage()
}
}
// TS having a hard time with the filtered type.
// This is only temporary as we will not return null
// later on when we handle errors appropriately.
const filteredStays = (data?.pages.filter((page) => page?.data) ??
[]) as unknown as PreviousStaysNonNullResponseObject[]
const stays = filteredStays.flatMap((page) => page.data)
const stays = data.pages
.filter((page): page is PreviousStaysNonNullResponseObject => !!page?.data)
.flatMap((page) => page.data)
return isLoading ? (
<LoadingSpinner />
) : (
return (
<ListContainer>
<Grids.Stackable>
{stays.map((stay) => (

View File

@@ -36,22 +36,21 @@ export default function ClientUpcomingStays({
}
)
if (isLoading) {
return <LoadingSpinner />
}
function loadMoreData() {
if (hasNextPage) {
fetchNextPage()
}
}
// TS having a hard time with the filtered type.
// This is only temporary as we will not return null
// later on when we handle errors appropriately.
const filteredStays = (data?.pages.filter((page) => page && page.data) ??
[]) as unknown as UpcomingStaysNonNullResponseObject[]
const stays = filteredStays.flatMap((page) => page.data)
const stays = data.pages
.filter((page): page is UpcomingStaysNonNullResponseObject => !!page?.data)
.flatMap((page) => page.data)
return isLoading ? (
<LoadingSpinner />
) : stays.length ? (
return stays.length ? (
<ListContainer>
<Grids.Stackable>
{stays.map((stay) => (