Skip to content

Commit

Permalink
fix: renaming children to items
Browse files Browse the repository at this point in the history
  • Loading branch information
thoreyjona committed Sep 6, 2024
1 parent ccf0cd9 commit 50df0df
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 29 deletions.
6 changes: 3 additions & 3 deletions apps/native/app/src/screens/home/air-discount-module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const AirDiscountModule = React.memo(

const count = discounts?.length ?? 0

const children = discounts?.slice(0, 3).map(({ discountCode, user }) => (
const items = discounts?.slice(0, 3).map(({ discountCode, user }) => (
<AirDiscountCard
key={`loftbru-item-${discountCode}`}
name={user.name}
Expand Down Expand Up @@ -150,8 +150,8 @@ const AirDiscountModule = React.memo(
link={null}
/>
)}
{count === 1 && children?.slice(0, 1)}
{count >= 2 && <ViewPager>{children}</ViewPager>}
{count === 1 && items}
{count >= 2 && <ViewPager>{items}</ViewPager>}
</>
)}
</Host>
Expand Down
6 changes: 3 additions & 3 deletions apps/native/app/src/screens/home/applications-module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const ApplicationsModule = React.memo(
return null
}

const children = applications.slice(0, 3).map((application) => (
const items = applications.slice(0, 3).map((application) => (
<StatusCard
key={application.id}
title={application.name ?? ''}
Expand Down Expand Up @@ -168,8 +168,8 @@ const ApplicationsModule = React.memo(
}
/>
)}
{count === 1 && children.slice(0, 1)}
{count >= 2 && <ViewPager>{children}</ViewPager>}
{count === 1 && items}
{count >= 2 && <ViewPager>{items}</ViewPager>}
</>
)}
</SafeAreaView>
Expand Down
6 changes: 3 additions & 3 deletions apps/native/app/src/screens/home/licenses-module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const LicensesModule = React.memo(

const allLicenses = [...(licenses ?? []), ...(passport ?? [])]

const children = allLicenses
const items = allLicenses
.filter(
(license) =>
license.__typename === 'GenericUserLicense' ||
Expand Down Expand Up @@ -200,8 +200,8 @@ const LicensesModule = React.memo(
link={null}
/>
)}
{count === 1 && children?.slice(0, 1)}
{count >= 2 && <ViewPager>{children}</ViewPager>}
{count === 1 && items}
{count >= 2 && <ViewPager>{items}</ViewPager>}
</>
)}
</Host>
Expand Down
47 changes: 27 additions & 20 deletions apps/native/app/src/screens/home/vehicles-module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
GeneralCardSkeleton,
} from '@ui'

import React from 'react'
import React, { useMemo } from 'react'
import { FormattedMessage, useIntl } from 'react-intl'
import { Image, SafeAreaView, TouchableOpacity } from 'react-native'
import styled, { useTheme } from 'styled-components/native'
Expand Down Expand Up @@ -58,30 +58,37 @@ const VehiclesModule = React.memo(
({ data, loading, error }: VehiclesModuleProps) => {
const theme = useTheme()
const intl = useIntl()
if (error && !data) {
return null
}

const vehicles = data?.vehiclesList?.vehicleList

// Reorder vehicles so vehicles that require mileage registration are shown first
const reorderedVehicles = vehicles
? [...vehicles]?.sort((a, b) => {
if (a.requiresMileageRegistration && !b.requiresMileageRegistration) {
return -1
} else if (
!a.requiresMileageRegistration &&
b.requiresMileageRegistration
) {
return 1
}
return 0
})
: vehicles
const reorderedVehicles = useMemo(
() =>
vehicles
? [...vehicles]?.sort((a, b) => {
if (
a.requiresMileageRegistration &&
!b.requiresMileageRegistration
) {
return -1
} else if (
!a.requiresMileageRegistration &&
b.requiresMileageRegistration
) {
return 1
}
return 0
})
: vehicles,
[vehicles],
)
if (error && !data) {
return null
}

const count = reorderedVehicles?.length ?? 0

const children = reorderedVehicles?.slice(0, 3).map((vehicle, index) => (
const items = reorderedVehicles?.slice(0, 3).map((vehicle, index) => (
<VehicleItem
key={vehicle.permno}
item={vehicle}
Expand Down Expand Up @@ -150,8 +157,8 @@ const VehiclesModule = React.memo(
link={null}
/>
)}
{count === 1 && children?.slice(0, 1)}
{count >= 2 && <ViewPager>{children}</ViewPager>}
{count === 1 && items}
{count >= 2 && <ViewPager>{items}</ViewPager>}
</>
)}
</Host>
Expand Down

0 comments on commit 50df0df

Please sign in to comment.