Skip to content

Commit 36e159b

Browse files
fix(services/content/flights): proper typings
1 parent b9d37ae commit 36e159b

File tree

4 files changed

+36
-29
lines changed

4 files changed

+36
-29
lines changed

src/components/pages/about/flight-map.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { useMotionValue, useSpring, useTransform } from 'framer-motion';
21
import 'leaflet/dist/leaflet.css';
32
import { useTheme } from 'next-themes';
43
import dynamic from 'next/dynamic';
54
import { useState } from 'react';
65

76
import { Airline, Flight } from 'services/content/flights';
87

9-
import { airportCoordinates, getAirlineColor, getTileUrl } from 'utils/flights';
8+
import { AirportCode, airportCoordinates, getAirlineColor, getTileUrl } from 'utils/flights';
109
import { classNames } from 'utils/styles';
1110

1211
import Tooltip from 'components/shared/tooltip';
@@ -55,18 +54,12 @@ function AirlineSelector({ airlines, selectedAirline, setSelectedAirline, isDark
5554

5655
interface MapProps {
5756
flights: Flight[];
58-
airports: string[];
57+
airports: Array<AirportCode>;
5958
isDarkMode: boolean;
6059
}
6160

6261
function Map({ flights, airports, isDarkMode }: MapProps) {
6362
const [hoveredFlight, setHoveredFlight] = useState<number | null>(null);
64-
const x = useMotionValue(0);
65-
66-
const config = { damping: 5, stiffness: 100 };
67-
const rotate = useSpring(useTransform(x, [-100, 100], [-45, 45]), config);
68-
const translateX = useSpring(useTransform(x, [-100, 100], [-47, 47]), config);
69-
7063
return (
7164
<MapContainer center={[20, 0]} zoom={2} className="absolute inset-0 w-full h-full">
7265
<TileLayer
@@ -137,7 +130,7 @@ function Map({ flights, airports, isDarkMode }: MapProps) {
137130
interface FlightMapProps {
138131
flights: Flight[];
139132
airlines: Airline[];
140-
airports: string[];
133+
airports: AirportCode[];
141134
}
142135

143136
export default function FlightMap({ flights, airlines, airports }: FlightMapProps) {

src/data/currency.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"CZK": {
3-
"timestamp": 1726323987664,
3+
"timestamp": 1727572583111,
44
"base": "CZK",
55
"rates": {
6-
"USD": 0.044067,
7-
"EUR": 0.039762,
8-
"GBP": 0.033578,
9-
"JPY": 6.20612615,
10-
"BRL": 0.245231,
11-
"AUD": 0.065732,
12-
"CAD": 0.059915,
13-
"CHF": 0.03742,
14-
"INR": 3.696372
6+
"USD": 0.044418,
7+
"EUR": 0.03976,
8+
"GBP": 0.03322,
9+
"JPY": 6.3142563,
10+
"BRL": 0.241362,
11+
"AUD": 0.064271,
12+
"CAD": 0.060068,
13+
"CHF": 0.037365,
14+
"INR": 3.718504
1515
}
1616
}
1717
}

src/services/content/flights.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { readFileSync } from 'fs';
22
import { join } from 'path';
33

4-
import { airlineNames } from 'utils/flights';
4+
import { AirlineCode, airlineNames, AirportCode } from 'utils/flights';
55

66
// ---------------------------------------------------------------------------
77
// UTILS
@@ -14,16 +14,16 @@ const DATA_SRC = join(process.cwd(), 'src/data/flights.txt');
1414
// ---------------------------------------------------------------------------
1515

1616
export interface Flight {
17-
airline: keyof typeof airlineNames;
17+
airline: AirlineCode;
1818
flightNumber: string;
19-
origin: string;
20-
destination: string;
19+
origin: AirportCode;
20+
destination: AirportCode;
2121
departureTime: string;
2222
arrivalTime: string;
2323
}
2424

2525
export interface Airline {
26-
code: keyof typeof airlineNames;
26+
code: AirlineCode;
2727
name: string;
2828
}
2929

@@ -53,7 +53,14 @@ export default class FlightsContentService {
5353
.map((line) => {
5454
const [, , , , , , , airline, flightNumber, , origin, destination, departureTime, arrivalTime] =
5555
line.split(';');
56-
return { airline, flightNumber, origin, destination, departureTime, arrivalTime };
56+
return {
57+
airline: airline as AirlineCode,
58+
origin: origin as AirportCode,
59+
destination: destination as AirportCode,
60+
flightNumber,
61+
departureTime,
62+
arrivalTime,
63+
};
5764
})
5865
.filter((flight) => flight.airline && flight.flightNumber && flight.origin && flight.destination);
5966
}
@@ -62,7 +69,7 @@ export default class FlightsContentService {
6269
// getters
6370
// ---------------------------------------------------------------------------
6471

65-
public getAirlines(): Airline[] {
72+
public getAirlines() {
6673
const airlineSet = new Set(this.flights.map((flight) => flight.airline));
6774

6875
return Array.from(airlineSet).map((code) => ({
@@ -72,7 +79,7 @@ export default class FlightsContentService {
7279
}
7380

7481
public getAirports() {
75-
const airportSet = new Set<string>();
82+
const airportSet = new Set<AirportCode>();
7683

7784
this.flights.forEach((flight) => {
7885
airportSet.add(flight.origin);

src/utils/flights.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const airportCoordinates = {
4545
LHR: [51.47, -0.4543],
4646
NTE: [47.1531, -1.6111],
4747
ASR: [38.7704, 35.495],
48-
} as const;
48+
} as const satisfies Record<string, [number, number]>;
4949

5050
export const airlineColors: { [key: string]: string } = {
5151
AD: '#D81B60', // Azul Brazilian Airlines
@@ -117,3 +117,10 @@ export const getTileUrl = (isDarkMode: boolean) =>
117117
isDarkMode
118118
? 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/dark_all/{z}/{x}/{y}.png'
119119
: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
120+
121+
// ---------------------------------------------------------------------------
122+
// Types
123+
// ---------------------------------------------------------------------------
124+
125+
export type AirportCode = keyof typeof airportCoordinates;
126+
export type AirlineCode = keyof typeof airlineNames;

0 commit comments

Comments
 (0)