Skip to content

Commit 0408b07

Browse files
committed
compute all transports everywhere
1 parent 9f6e14b commit 0408b07

14 files changed

Lines changed: 119 additions & 155 deletions

File tree

src/components/comparateur/overscreens/ComparisonOverscreen.tsx

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,19 @@
11
'use client'
2-
32
import { useTranslations } from 'next-intl'
4-
import React, { useMemo, useState } from 'react'
3+
import { useState } from 'react'
54
import useParamContext from 'src/providers/ParamProvider'
65
import { useSearchEquivalent } from 'src/providers/useSearchEquivalent'
7-
import { deplacements } from 'data/categories/deplacement'
86
import Button from 'components/base/buttons/Button'
97
import HiddenLabel from 'components/form/HiddenLabel'
108
import Input from 'components/form/Input'
119
import ComparisonEquivalents from './ComparisonEquivalents'
1210
import styles from './EquivalentsOverscreen.module.css'
1311

14-
const allEquivalents = deplacements
15-
.filter((equivalent) => equivalent.category === 4)
16-
.flatMap((deplacement) =>
17-
deplacement.withCarpool
18-
? [
19-
...Array.from({ length: 4 }).map((_, index) => ({
20-
...deplacement,
21-
carpool: index + 1,
22-
slug: `${deplacement.slug}+${index + 1}`,
23-
})),
24-
deplacement,
25-
]
26-
: [deplacement]
27-
)
28-
2912
const ComparisonOverscreen = ({ index }: { index: 0 | 1 }) => {
30-
const {
31-
setOverscreen,
32-
transport: { modes },
33-
} = useParamContext()
13+
const { setOverscreen } = useParamContext()
3414
const [search, setSearch] = useState('')
3515
const results = useSearchEquivalent(search, true, 4)
3616

37-
const equivalents = useMemo(
38-
() =>
39-
allEquivalents.filter((equivalent) => {
40-
const [slug, carpool] = equivalent.slug.split('+')
41-
return carpool ? modes.includes(`${slug}+1`) : modes.includes(slug)
42-
}),
43-
[modes]
44-
)
4517
const tSearch = useTranslations('comparateur.overscreen')
4618
const t = useTranslations('overscreen.transport')
4719
const tModal = useTranslations('modal')
@@ -87,7 +59,7 @@ const ComparisonOverscreen = ({ index }: { index: 0 | 1 }) => {
8759
</div>
8860
)
8961
) : (
90-
<ComparisonEquivalents onClose={onClose} equivalents={equivalents} index={index} />
62+
<ComparisonEquivalents onClose={onClose} equivalents={results} index={index} />
9163
)}
9264
</ul>
9365
<div className={styles.footerCenter}>

src/components/outils/CategorySimulator.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ const CategorySimulator = ({
132132

133133
const ref = useRef<HTMLUListElement>(null)
134134
const firstElementRef = useRef<HTMLAnchorElement>(null)
135-
const max = Math.max.apply(null, equivalents?.map((equivalent) => equivalent.value) || [])
135+
const max = Math.max.apply(
136+
null,
137+
equivalents?.filter((equivalent) => !equivalent.ignore).map((equivalent) => equivalent.value) || []
138+
)
136139
const legends = useMemo(() => computeLegends(equivalents), [equivalents])
137140
const [basePercent, setBasePercent] = useState(80)
138141
const [legendRelative, setLegendRelative] = useState(false)

src/components/outils/transport/TransportComparisonEquivalent.tsx

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,19 @@ import styles from './TransportComparisonEquivalent.module.css'
1919
const allEquivalents = computedEquivalents.flatMap(getEquivalentWithCarpool)
2020

2121
const getEquivalent = (language: string, equivalents: ComputedEquivalent[], slug: string) => {
22-
const [name, carpool] = slug.split('+')
23-
const equivalent = equivalents.find(
24-
(equivalent) => isEquivalentInMode(equivalent, name) && (carpool ? equivalent.carpool : !equivalent.carpool)
25-
) as (ComputedEquivalent & { found?: boolean }) | undefined
22+
let equivalent = equivalents.find((equivalent) => isEquivalentInMode(equivalent, slug)) as
23+
| (ComputedEquivalent & { found?: boolean })
24+
| undefined
25+
2626
if (!equivalent) {
27-
return allEquivalents.find((equivalent) => isEquivalentInMode(equivalent, slug)) as
27+
equivalent = allEquivalents.find((equivalent) => isEquivalentInMode(equivalent, slug)) as
2828
| (ComputedEquivalent & { found?: boolean })
2929
| undefined
3030
}
3131

32-
if (carpool) {
33-
if (!equivalent) {
34-
return undefined
35-
}
36-
37-
return {
38-
...equivalent,
39-
name: getName(
40-
language,
41-
{ ...equivalent, slug: carpool ? `${equivalent.slug}+${carpool}` : equivalent.slug, carpool: Number(carpool) },
42-
false,
43-
1,
44-
false,
45-
true
46-
),
47-
found: true,
48-
}
49-
}
50-
51-
return equivalent ? { ...equivalent, found: true } : undefined
32+
return equivalent
33+
? { ...equivalent, name: getName(language, equivalent, false, 1, false, true), found: true }
34+
: undefined
5235
}
5336

5437
const TransportComparisonEquivalent = ({
@@ -94,7 +77,7 @@ const TransportComparisonEquivalent = ({
9477
</Link>
9578
<div className={styles.top}>
9679
<EquivalentIcon equivalent={equivalent} height={4} />
97-
<p>{equivalent.found ? equivalent.name : getName(language, equivalent)}</p>
80+
<p>{equivalent.found ? equivalent.name : getName(language, equivalent, false, 1, false, true)}</p>
9881
</div>
9982
{equivalent.found ? (
10083
<div>

src/components/shareable/overScreens/TransportComparison.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,18 @@ const TransportComparison = ({
4343
() =>
4444
equivalents
4545
.filter((equivalent) => {
46-
if (equivalent.carpool) {
47-
const [slug] = equivalent.slug.split('+')
48-
return modes.includes(`${slug}+1`)
46+
const infos = equivalent.slug.split('+')
47+
let slug = infos[0]
48+
if (equivalent.slug.startsWith('voiture-')) {
49+
if (equivalent.slug.includes('hybride')) {
50+
slug = `voiturehybride`
51+
} else if (equivalent.slug.includes('electrique')) {
52+
slug = `voitureelectrique`
53+
} else {
54+
slug = 'voiturethermique'
55+
}
4956
}
50-
return modes.includes(equivalent.slug)
57+
return infos[1] ? modes.includes(`${slug}+1`) : modes.includes(slug)
5158
})
5259
.sort((a, b) => a.slug.localeCompare(b.slug)),
5360
[modes]

src/data/categories/deplacement.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,11 +997,11 @@ export const deplacements = [
997997
ecv: [
998998
{
999999
id: 6,
1000-
value: 0.0931681350556303,
1000+
value: 0.1134194350556303,
10011001
},
10021002
{
10031003
id: 5,
1004-
value: 0.04073222826086956,
1004+
value: 0.03315991847826087,
10051005
},
10061006
],
10071007
default: false,

src/hooks/useTransportations.tsx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ export default function useTransportations(
2828
const allEquivalents =
2929
values || km
3030
? deplacements
31-
// Carpool is managed after expansion, avion needs to be managed here
32-
.filter((equivalent) => equivalent.withCarpool || params.transport.modes.includes(equivalent.slug))
3331
.filter((equivalent) => (values && equivalent.type ? values[equivalent.type as DeplacementType] : km))
3432
.map((equivalent) => {
3533
if ('ecvs' in equivalent && equivalent.ecvs) {
@@ -75,15 +73,14 @@ export default function useTransportations(
7573
equivalents.find((eq) => eq.slug === `voiture-${carpoolCarInfo.size}-${carpoolCarInfo.engine}`)) ||
7674
equivalent
7775

78-
const carpoolValue = equivalent.withCarpool && carpool[equivalent.slug] ? carpool[equivalent.slug] : 1
79-
return carpoolEquivalent.withCarpool &&
80-
params.transport.modes.find((mode) => mode.startsWith(`${equivalent.slug}+`))
76+
return carpoolEquivalent.withCarpool
8177
? [
82-
{
78+
...Array.from({ length: 4 }, (_, i) => i + 1).map((carpoolValue) => ({
8379
...carpoolEquivalent,
80+
id: carpoolEquivalent.id + carpoolValue,
8481
default: equivalent.default,
85-
ignore: equivalent.ignore,
86-
slug: equivalent.slug,
82+
ignore: equivalent.ignore || carpoolValue !== 1,
83+
slug: `${equivalent.slug}+${carpoolValue}`,
8784
carpool: carpoolValue,
8885
name:
8986
getNameWithoutSuffix(params.language, { ...equivalent, carpool: carpoolValue }) +
@@ -92,8 +89,8 @@ export default function useTransportations(
9289
value: carpoolEquivalent.value / (carpoolValue + 1),
9390
ecv: carpoolEquivalent.ecv.map((ecv) => ({ ...ecv, value: ecv.value / (carpoolValue + 1) })),
9491
usage: carpoolEquivalent.usage / (carpoolValue + 1),
95-
link: `${carpoolEquivalent.link}+${carpoolValue}`,
96-
},
92+
link: `${realEquivalent.link}+${carpoolValue}`,
93+
})),
9794
{
9895
...realEquivalent,
9996
default: equivalent.default,
@@ -115,17 +112,23 @@ export default function useTransportations(
115112
]
116113
})
117114
.filter((equivalent) => {
118-
if (equivalent.withCarpool) {
119-
// Carpool case, check slug+1
120-
if ('carpool' in equivalent && equivalent.carpool) {
121-
const [slug] = equivalent.slug.split('+')
122-
return params.transport.modes.includes(`${slug}+1`)
115+
// Carpool case, check slug+1
116+
const infos = equivalent.slug.split('+')
117+
let slug = infos[0]
118+
if (equivalent.slug.startsWith('voiture-')) {
119+
if (equivalent.slug.includes('hybride')) {
120+
slug = `voiturehybride`
121+
} else if (equivalent.slug.includes('electrique')) {
122+
slug = `voitureelectrique`
123+
} else {
124+
slug = 'voiturethermique'
123125
}
124-
// Without carpool, check slug
125-
return params.transport.modes.includes(equivalent.slug)
126126
}
127-
// Manage on top
128-
return true
127+
if ('carpool' in equivalent && equivalent.carpool) {
128+
return params.transport.modes.includes(`${slug}+1`)
129+
}
130+
// Without carpool, check slug
131+
return params.transport.modes.includes(slug)
129132
})
130133
: []
131134

src/providers/ParamProvider.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,6 @@ export function ParamProvider({ children }: { children: ReactNode }) {
443443
if (searchParams.get('modes')) {
444444
const modes = (searchParams.get('modes') as string).replace(/ /g, '+').split(',')
445445
if (modes.length > 0) {
446-
if (modes.includes('voiturethermique') && modes.includes('voitureelectrique')) {
447-
modes.push('voiturehybride')
448-
}
449-
if (modes.includes('voiturethermique+1') && modes.includes('voitureelectrique+1')) {
450-
modes.push('voiturehybride+1')
451-
}
452446
setModes(modes)
453447
if (!searchParams.get('comparison')) {
454448
if (modes.length === 2) {

src/providers/locales/en.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,10 @@
444444
"avion-pny": "Travel by plane, very long journey. Total distance traveled: 11,600 km.",
445445
"tgv-paris-berlin": "Total distance traveled: 2,478 km.",
446446
"tgv-paris-marseille": "Total distance traveled: 1,504 km.",
447-
"voiture-lille-nimes": "Total distance traveled: 1,882 km.",
447+
"voiture-lille-nimes": "Journey made alone, in an average car running on diesel over a total distance of 1,882 km.",
448448
"ski": "Average value. Study conducted for a day of skiing in La Clusaz, Le Grand Bornand, and Tignes.",
449449
"piscine": "Average size of a private pool: 8 x 4m with a depth ranging from 1.5m to 2.1m.",
450-
"terre-voiture": "Total distance traveled: 40,000 km.",
450+
"terre-voiture": "Journey made alone, in a sedan running on gasoline over a total distance of 40,000 km.",
451451
"harry-potter": "All Harry Potter films last an average of 1,176 minutes = 19.6 hours. The data is calculated based on one hour of HD streaming on a television using Wi-Fi.",
452452
"avion-courtcourrier": "Average occupancy rate: 101-220 passengers.",
453453
"avion-moyencourrier": "Average occupancy rate: 101-220 passengers.",
@@ -530,32 +530,32 @@
530530
"maisonneuve": "Construction of a new conventional house of 130 m² living space - case of housing in Saint-Pierre and Miquelon.",
531531
"voiture-citadine-essence": "Small - Gasoline",
532532
"voiture-citadine-diesel": "Small - Diesel",
533-
"voiture-citadine-electrique": "Small - Electric",
533+
"voiture-citadine-electrique": "Small",
534534
"voiture-citadine-hybride": "Small - Non rechargeable",
535535
"voiture-citadine-hybriderechargeable": "Small - Plug-in",
536536
"voiture-compact-essence": "Medium - Gasoline",
537537
"voiture-compact-diesel": "Medium - Diesel",
538-
"voiture-compact-electrique": "Medium - Electric",
538+
"voiture-compact-electrique": "Medium",
539539
"voiture-compact-hybride": "Medium - Non rechargeable",
540540
"voiture-compact-hybriderechargeable": "Medium - Plug-in",
541541
"voiture-berline-essence": "Sedan - Gasoline",
542542
"voiture-berline-diesel": "Sedan - Diesel",
543-
"voiture-berline-electrique": "Sedan - Electric",
543+
"voiture-berline-electrique": "Sedan",
544544
"voiture-berline-hybride": "Sedan - Non rechargeable",
545545
"voiture-berline-hybriderechargeable": "Sedan - Plug-in",
546546
"voiture-grandeberline-essence": "SUV - Gasoline",
547547
"voiture-grandeberline-diesel": "SUV - Diesel",
548-
"voiture-grandeberline-electrique": "SUV - Electric",
548+
"voiture-grandeberline-electrique": "SUV",
549549
"voiture-grandeberline-hybride": "SUV - Non rechargeable",
550550
"voiture-grandeberline-hybriderechargeable": "SUV - Plug-in",
551551
"voiturethermique": "Medium - Diesel",
552-
"voitureelectrique": "Medium - Electric",
552+
"voitureelectrique": "Medium",
553553
"voiturehybride": "Medium - Non rechargeable"
554554
},
555555
"post": {
556556
"ski": "Includes: the carbon impact of transportation (52%), accommodation (4%), food (8%), ski area (3%), infrastructure, equipment, and services (17%), and gear (16%).",
557557
"piscine": "58,000 liters of tap water to fill it.",
558-
"terre-voiture": "Includes: the carbon impact of a trip in a gasoline car.",
558+
"terre-voiture": "Included are direct emissions, the construction of vehicles (manufacturing, maintenance, and end-of-life), and the production and distribution of fuel and electricity. The construction of infrastructure (roads, railways, airports...) is not included.",
559559
"avion-courtcourrier": "Per person in France. We account for the carbon impact of contrail formation. Included are direct emissions, the construction of vehicles (manufacturing, maintenance, and end-of-life), and the production and distribution of fuel and electricity. The construction of infrastructure (roads, railways, airports...) is not included.",
560560
"avion-moyencourrier": "Per person in France. We account for the carbon impact of contrail formation. Included are direct emissions, the construction of vehicles (manufacturing, maintenance, and end-of-life), and the production and distribution of fuel and electricity. The construction of infrastructure (roads, railways, airports...) is not included.",
561561
"avion-moyenlongcourrier": "Per person in France. We account for the carbon impact of contrail formation. Included are direct emissions, the construction of vehicles (manufacturing, maintenance, and end-of-life), and the production and distribution of fuel and electricity. The construction of infrastructure (roads, railways, airports...) is not included.",

src/providers/locales/es.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,10 @@
444444
"avion-pny": "Viaje en avión, un trayecto muy largo. Distancia total recorrida: 11.600 km.",
445445
"tgv-paris-berlin": "Distancia total recorrida: 2,478 km.",
446446
"tgv-paris-marseille": "Distancia total recorrida: 1,504 km.",
447-
"voiture-lille-nimes": "Distancia total recorrida: 1,882 km.",
447+
"voiture-lille-nimes": "Trayecto realizado solo, en un coche promedio que funciona con diésel, en una distancia total de 1,882 km.",
448448
"ski": "Valor promedio. Estudio realizado para un día de esquí en La Clusaz, Le Grand Bornand y Tignes.",
449449
"piscine": "Tamaño promedio de una piscina privada: 8 x 4m con una profundidad que varía entre 1,5m y 2,1m.",
450-
"terre-voiture": "Distancia total recorrida: 40,000 km.",
450+
"terre-voiture": "Viaje realizado solo, en un coche tipo berlina que funciona con gasolina, en una distancia total de 40 000 km.",
451451
"harry-potter": "El total de las películas de Harry Potter dura un promedio de 1,176 minutos = 19,6 horas. El dato se calcula en base a una hora de transmisión en alta definición en un televisor usando Wi-Fi.",
452452
"avion-courtcourrier": "Tasa de ocupación promedio: 101-220 pasajeros.",
453453
"avion-moyencourrier": "Tasa de ocupación promedio: 101-220 pasajeros.",
@@ -530,32 +530,32 @@
530530
"maisonneuve": "Construcción de una casa nueva convencional de 130 m² habitables - caso de viviendas en San Pedro y Miquelón",
531531
"voiture-citadine-essence": "Pequeña - Gasolina",
532532
"voiture-citadine-diesel": "Pequeña - Diésel",
533-
"voiture-citadine-electrique": "Pequeña - Eléctrico",
533+
"voiture-citadine-electrique": "Pequeña",
534534
"voiture-citadine-hybride": "Pequeña - No recargable",
535535
"voiture-citadine-hybriderechargeable": "Pequeña - Enchufable",
536536
"voiture-compact-essence": "Mediana - Gasolina",
537537
"voiture-compact-diesel": "Mediana - Diésel",
538-
"voiture-compact-electrique": "Mediana - Eléctrico",
538+
"voiture-compact-electrique": "Mediana",
539539
"voiture-compact-hybride": "Mediana - No recargable",
540540
"voiture-compact-hybriderechargeable": "Mediana - Enchufable",
541541
"voiture-berline-essence": "Berlina - Gasolina",
542542
"voiture-berline-diesel": "Berlina - Diésel",
543-
"voiture-berline-electrique": "Berlina - Eléctrico",
543+
"voiture-berline-electrique": "Berlina",
544544
"voiture-berline-hybride": "Berlina - No recargable",
545545
"voiture-berline-hybriderechargeable": "Berlina - Enchufable",
546546
"voiture-grandeberline-essence": "SUV - Gasolina",
547547
"voiture-grandeberline-diesel": "SUV - Diésel",
548-
"voiture-grandeberline-electrique": "SUV - Eléctrico",
548+
"voiture-grandeberline-electrique": "SUV",
549549
"voiture-grandeberline-hybride": "SUV - No recargable",
550550
"voiture-grandeberline-hybriderechargeable": "SUV - Enchufable",
551551
"voiturethermique": "Mediana - Diésel",
552-
"voitureelectrique": "Mediana - Eléctrico",
552+
"voitureelectrique": "Mediana",
553553
"voiturehybride": "Mediana - No recargable"
554554
},
555555
"post": {
556556
"ski": "Incluye: el impacto de carbono del transporte (52%), alojamiento (4%), alimentos (8%), la estación de esquí (3%), infraestructura, equipo y servicios (17%), y equipo (16%).",
557557
"piscine": "58,000 litros de agua del grifo para llenarla.",
558-
"terre-voiture": "Incluye: el impacto de carbono de un viaje en coche con motor de combustión.",
558+
"terre-voiture": "Se incluyen las emisiones directas, la construcción de vehículos (fabricación, mantenimiento y fin de vida) y la producción y distribución de combustible y electricidad. La construcción de infraestructuras (carreteras, vías férreas, aeropuertos...) no está incluida.",
559559
"avion-courtcourrier": "Por persona en Francia. Se tiene en cuenta el impacto del carbono debido a la formación de estelas. Se incluyen las emisiones directas, la construcción de vehículos (fabricación, mantenimiento y fin de vida), y la producción y distribución de combustible y electricidad. La construcción de infraestructuras (carreteras, vías férreas, aeropuertos...) no está incluida.",
560560
"avion-moyencourrier": "Por persona en Francia. Se tiene en cuenta el impacto del carbono debido a la formación de estelas. Se incluyen las emisiones directas, la construcción de vehículos (fabricación, mantenimiento y fin de vida), y la producción y distribución de combustible y electricidad. La construcción de infraestructuras (carreteras, vías férreas, aeropuertos...) no está incluida.",
561561
"avion-moyenlongcourrier": "Por persona en Francia. Se tiene en cuenta el impacto del carbono debido a la formación de estelas. Se incluyen las emisiones directas, la construcción de vehículos (fabricación, mantenimiento y fin de vida), y la producción y distribución de combustible y electricidad. La construcción de infraestructuras (carreteras, vías férreas, aeropuertos...) no está incluida.",

0 commit comments

Comments
 (0)