Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/components/NextDepartureHero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import { useMemo, useState, useEffect } from 'react';
import { Bus, Train, Sparkles, MapPin, Clock, ArrowRight } from 'lucide-react';
import { UnifiedEntry } from '@/types';

// ⚡ Bolt: Cache Intl.DateTimeFormat instance to avoid expensive recreation on every render

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Excellente initiative de mettre en cache l'instance de Intl.DateTimeFormat. Cela évite des recréations coûteuses à chaque rendu du composant, améliorant ainsi les performances. Le commentaire de documentation est également très utile pour comprendre l'objectif de cette constante.

const TIME_FORMATTER = new Intl.DateTimeFormat('fr-FR', {
timeZone: 'Europe/Paris',
hour: '2-digit',
minute: '2-digit'
});

interface NextDepartureHeroProps {
entry: UnifiedEntry | null;
boardType: 'departures' | 'arrivals';
Expand Down Expand Up @@ -54,11 +61,9 @@ export default function NextDepartureHero({ entry, boardType }: NextDepartureHer
? (entry.provenance || 'Provenance inconnue')
: entry.destination;

const formattedTime = new Intl.DateTimeFormat('fr-FR', {
timeZone: 'Europe/Paris',
hour: '2-digit',
minute: '2-digit'
}).format(new Date((boardType === 'arrivals' ? entry.arrivalTime : entry.departureTime) * 1000));
const formattedTime = TIME_FORMATTER.format(
new Date((boardType === 'arrivals' ? entry.arrivalTime : entry.departureTime) * 1000)
);

return (
<div className={`relative mb-6 overflow-hidden rounded-2xl border ${borderColor} bg-gradient-to-br ${bgGradient} p-4 md:p-6 shadow-2xl ${shadowColor} backdrop-blur-xl ring-1 ${glowRing} transition-all duration-300`}>
Expand Down