diff --git a/package-lock.json b/package-lock.json index a3bbe99..9b54474 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "@expo/vector-icons": "^15.0.3", "@react-native-async-storage/async-storage": "2.2.0", - "@react-native-picker/picker": "2.11.1", + "@react-native-picker/picker": "2.11.4", "@types/tesseract.js": "^0.0.2", "expo": "~54.0.0", "expo-blur": "~15.0.8", @@ -23,18 +23,19 @@ "expo-linear-gradient": "~15.0.8", "expo-location": "~19.0.8", "expo-notifications": "~0.32.16", + "expo-secure-store": "~15.0.5", "expo-status-bar": "~3.0.9", "react": "19.1.0", "react-native": "0.81.5", "react-native-android-widget": "^0.20.1", "react-native-calendars": "^1.1314.0", - "react-native-webview": "13.15.0", + "react-native-webview": "13.16.1", "tesseract.js": "^7.0.0" }, "devDependencies": { "@react-native-community/cli": "^20.1.3", "@types/react": "~19.1.10", - "pdfjs-dist": "^5.5.207", + "pdfjs-dist": "^5.6.205", "typescript": "~5.9.2" } }, @@ -80,7 +81,6 @@ "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.29.0.tgz", "integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==", "license": "MIT", - "peer": true, "dependencies": { "@babel/code-frame": "^7.29.0", "@babel/generator": "^7.29.0", @@ -1492,7 +1492,6 @@ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.29.2.tgz", "integrity": "sha512-JiDShH45zKHWyGe4ZNVRrCjBz8Nh9TMmZG1kh4QTK8hCBTWBi8Da+i7s1fJw7/lYpM4ccepSNfqzZ/QvABBi5g==", "license": "MIT", - "peer": true, "engines": { "node": ">=6.9.0" } @@ -2431,7 +2430,6 @@ "integrity": "sha512-sLo8cu9JyFNfuuF1C+8NJ4DHE/PEFaXGd4enkcxi/OJjGG8+sOQrdjNQ4i+cVh/2c+ah1mEMwsYjc3z0+/MqSg==", "devOptional": true, "license": "MIT", - "peer": true, "dependencies": { "@react-native-community/cli-clean": "20.1.3", "@react-native-community/cli-config": "20.1.3", @@ -2996,9 +2994,9 @@ } }, "node_modules/@react-native-picker/picker": { - "version": "2.11.1", - "resolved": "https://registry.npmjs.org/@react-native-picker/picker/-/picker-2.11.1.tgz", - "integrity": "sha512-ThklnkK4fV3yynnIIRBkxxjxR4IFbdMNJVF6tlLdOJ/zEFUEFUEdXY0KmH0iYzMwY8W4/InWsLiA7AkpAbnexA==", + "version": "2.11.4", + "resolved": "https://registry.npmjs.org/@react-native-picker/picker/-/picker-2.11.4.tgz", + "integrity": "sha512-Kf8h1AMnBo54b1fdiVylP2P/iFcZqzpMYcglC28EEFB1DEnOjsNr6Ucqc+3R9e91vHxEDnhZFbYDmAe79P2gjA==", "license": "MIT", "workspaces": [ "example" @@ -3399,7 +3397,6 @@ "integrity": "sha512-Qec1E3mhALmaspIrhWt9jkQMNdw6bReVu64mjvhbhq2NFPftLPVr+l1SZgmw/66WwBNpDh7ao5AT6gF5v41PFA==", "devOptional": true, "license": "MIT", - "peer": true, "dependencies": { "csstype": "^3.0.2" } @@ -4109,7 +4106,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "baseline-browser-mapping": "^2.9.0", "caniuse-lite": "^1.0.30001759", @@ -5014,7 +5010,6 @@ "resolved": "https://registry.npmjs.org/expo/-/expo-54.0.33.tgz", "integrity": "sha512-3yOEfAKqo+gqHcV8vKcnq0uA5zxlohnhA3fu4G43likN8ct5ZZ3LjAh9wDdKteEkoad3tFPvwxmXW711S5OHUw==", "license": "MIT", - "peer": true, "dependencies": { "@babel/runtime": "^7.20.0", "@expo/cli": "54.0.23", @@ -5130,7 +5125,6 @@ "resolved": "https://registry.npmjs.org/expo-font/-/expo-font-14.0.11.tgz", "integrity": "sha512-ga0q61ny4s/kr4k8JX9hVH69exVSIfcIc19+qZ7gt71Mqtm7xy2c6kwsPTCyhBW2Ro5yXTT8EaZOpuRi35rHbg==", "license": "MIT", - "peer": true, "dependencies": { "fontfaceobserver": "^2.1.0" }, @@ -5239,6 +5233,15 @@ "react-native": "*" } }, + "node_modules/expo-secure-store": { + "version": "15.0.8", + "resolved": "https://registry.npmjs.org/expo-secure-store/-/expo-secure-store-15.0.8.tgz", + "integrity": "sha512-lHnzvRajBu4u+P99+0GEMijQMFCOYpWRO4dWsXSuMt77+THPIGjzNvVKrGSl6mMrLsfVaKL8BpwYZLGlgA+zAw==", + "license": "MIT", + "peerDependencies": { + "expo": "*" + } + }, "node_modules/expo-server": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/expo-server/-/expo-server-1.0.5.tgz", @@ -8412,16 +8415,16 @@ } }, "node_modules/pdfjs-dist": { - "version": "5.5.207", - "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-5.5.207.tgz", - "integrity": "sha512-WMqqw06w1vUt9ZfT0gOFhMf3wHsWhaCrxGrckGs5Cci6ybDW87IvPaOd2pnBwT6BJuP/CzXDZxjFgmSULLdsdw==", + "version": "5.6.205", + "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-5.6.205.tgz", + "integrity": "sha512-tlUj+2IDa7G1SbvBNN74UHRLJybZDWYom+k6p5KIZl7huBvsA4APi6mKL+zCxd3tLjN5hOOEE9Tv7VdzO88pfg==", "dev": true, "license": "Apache-2.0", "engines": { "node": ">=20.19.0 || >=22.13.0 || >=24" }, "optionalDependencies": { - "@napi-rs/canvas": "^0.1.95", + "@napi-rs/canvas": "^0.1.96", "node-readable-to-web-readable-stream": "^0.4.2" } }, @@ -8436,7 +8439,6 @@ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, @@ -8716,7 +8718,6 @@ "resolved": "https://registry.npmjs.org/react/-/react-19.1.0.tgz", "integrity": "sha512-FS+XFBNvn3GTAWq26joslQgWNoFu08F4kl0J4CgdNKADkdSGXQyTCnKteIAJy96Br6YbpEU1LSzV5dYtjMkMDg==", "license": "MIT", - "peer": true, "engines": { "node": ">=0.10.0" } @@ -8742,7 +8743,6 @@ "resolved": "https://registry.npmjs.org/react-native/-/react-native-0.81.5.tgz", "integrity": "sha512-1w+/oSjEXZjMqsIvmkCRsOc8UBYv163bTWKTI8+1mxztvQPhCRYGTvZ/PL1w16xXHneIj/SLGfxWg2GWN2uexw==", "license": "MIT", - "peer": true, "dependencies": { "@jest/create-cache-key-function": "^29.7.0", "@react-native/assets-registry": "0.81.5", @@ -8849,11 +8849,10 @@ "license": "MIT" }, "node_modules/react-native-webview": { - "version": "13.15.0", - "resolved": "https://registry.npmjs.org/react-native-webview/-/react-native-webview-13.15.0.tgz", - "integrity": "sha512-Vzjgy8mmxa/JO6l5KZrsTC7YemSdq+qB01diA0FqjUTaWGAGwuykpJ73MDj3+mzBSlaDxAEugHzTtkUQkQEQeQ==", + "version": "13.16.1", + "resolved": "https://registry.npmjs.org/react-native-webview/-/react-native-webview-13.16.1.tgz", + "integrity": "sha512-If0eHhoEdOYDcHsX+xBFwHMbWBGK1BvGDQDQdVkwtSIXiq1uiqjkpWVP2uQ1as94J0CzvFE9PUNDuhiX0Z6ubw==", "license": "MIT", - "peer": true, "dependencies": { "escape-string-regexp": "^4.0.0", "invariant": "2.2.4" @@ -8952,7 +8951,6 @@ "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.14.2.tgz", "integrity": "sha512-jCvmsr+1IUSMUyzOkRcvnVbX3ZYC6g9TDrDbFuFmRDq7PD4yaGbLKNQL6k2jnArV8hjYxh7hVhAZB6s9HDGpZA==", "license": "MIT", - "peer": true, "engines": { "node": ">=0.10.0" } @@ -10211,9 +10209,8 @@ "version": "5.9.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", - "dev": true, + "devOptional": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/src/components/ShiftTimeline.tsx b/src/components/ShiftTimeline.tsx index 9c7f60b..312782a 100644 --- a/src/components/ShiftTimeline.tsx +++ b/src/components/ShiftTimeline.tsx @@ -7,7 +7,7 @@ import { MaterialIcons } from '@expo/vector-icons'; import { useAppTheme, type ThemeColors } from '../context/ThemeContext'; import { useAirport } from '../context/AirportContext'; import { getAirlineOps, getAirlineColor } from '../utils/airlineOps'; -import { fetchAirportScheduleRaw } from '../utils/fr24api'; +import { fetchAirportScheduleRaw, type FR24FlightData } from '../utils/fr24api'; import { useLanguage } from '../context/LanguageContext'; if (Platform.OS === 'android' && UIManager.setLayoutAnimationEnabledExperimental) { @@ -36,7 +36,7 @@ type Flight = { ops: { checkInOpen: number; checkInClose: number; gateOpen: number; gateClose: number }; }; -function parseFlight(item: any): Flight | null { +function parseFlight(item: FR24FlightData): Flight | null { const f = item.flight; if (!f) return null; const ts = f.time?.scheduled?.departure; diff --git a/src/screens/FlightScreen.tsx b/src/screens/FlightScreen.tsx index 3a28fb0..3627fde 100644 --- a/src/screens/FlightScreen.tsx +++ b/src/screens/FlightScreen.tsx @@ -11,7 +11,7 @@ import { MaterialIcons } from '@expo/vector-icons'; import { useAppTheme, type ThemeColors } from '../context/ThemeContext'; import { useAirport } from '../context/AirportContext'; import { getAirlineOps, getAirlineColor } from '../utils/airlineOps'; -import { fetchAirportScheduleRaw } from '../utils/fr24api'; +import { fetchAirportScheduleRaw, type FR24FlightData } from '../utils/fr24api'; import { fetchStaffMonitorData, normalizeFlightNumber, type StaffMonitorFlight } from '../utils/staffMonitor'; import { formatAirportHeader } from '../utils/airportSettings'; import { requestWidgetUpdate } from 'react-native-android-widget'; @@ -111,7 +111,7 @@ async function cancelPreviousNotifications() { } async function scheduleShiftNotifications( - shiftFlights: any[], + shiftFlights: FR24FlightData[], shiftEnd: number, locale: string, ): Promise { @@ -172,7 +172,7 @@ async function cancelPinnedNotifications() { await AsyncStorage.removeItem(PINNED_NOTIF_IDS_KEY); } -async function schedulePinnedNotifications(item: any, tab: 'arrivals' | 'departures', locale: string): Promise { +async function schedulePinnedNotifications(item: FR24FlightData, tab: 'arrivals' | 'departures', locale: string): Promise { await cancelPinnedNotifications(); const now = Date.now() / 1000; const ids: string[] = []; @@ -243,8 +243,8 @@ export default function FlightScreen() { const [refreshing, setRefreshing] = useState(false); const [activeTab, setActiveTab] = useState<'arrivals' | 'departures'>('departures'); const [activeDay, setActiveDay] = useState<'today' | 'tomorrow'>('today'); - const [arrivals, setArrivals] = useState([]); - const [departures, setDepartures] = useState([]); + const [arrivals, setArrivals] = useState([]); + const [departures, setDepartures] = useState([]); const [shifts, setShifts] = useState<{ today: { start: number; end: number } | null; tomorrow: { start: number; end: number } | null }>({ today: null, tomorrow: null }); const [notifsEnabled, setNotifsEnabled] = useState(false); const [scheduledCount, setScheduledCount] = useState(0); @@ -252,8 +252,8 @@ export default function FlightScreen() { const [inboundArrivals, setInboundArrivals] = useState>({}); const [filterMode, setFilterMode] = useState<'mine' | 'all'>('mine'); const [filterMenuVisible, setFilterMenuVisible] = useState(false); - const [allArrivalsFull, setAllArrivalsFull] = useState([]); - const [allDeparturesFull, setAllDeparturesFull] = useState([]); + const [allArrivalsFull, setAllArrivalsFull] = useState([]); + const [allDeparturesFull, setAllDeparturesFull] = useState([]); const [staffMonitorDeps, setStaffMonitorDeps] = useState([]); const [staffMonitorArrs, setStaffMonitorArrs] = useState([]); @@ -371,7 +371,7 @@ export default function FlightScreen() { return (ciO <= shiftToday!.end && ciC >= shiftToday!.start) || (gO <= shiftToday!.end && gC >= shiftToday!.start); }) .map(item => { - const ts = item.flight.time.scheduled.departure; + const ts = item.flight?.time?.scheduled?.departure || 0; const airline = item.flight?.airline?.name || 'Sconosciuta'; const ops = getAirlineOps(airline); const fn = item.flight?.identification?.number?.default || 'N/A'; @@ -486,7 +486,7 @@ export default function FlightScreen() { } }, [notifsEnabled, shifts, arrivals]); - const pinFlight = useCallback(async (item: any) => { + const pinFlight = useCallback(async (item: FR24FlightData) => { try { const id = item.flight?.identification?.number?.default; if (!id) return; @@ -543,7 +543,7 @@ export default function FlightScreen() { }); })(); - const renderFlight = useCallback(({ item }: { item: any }) => { + const renderFlight = useCallback(({ item }: { item: FR24FlightData }) => { const flightNumber = item.flight?.identification?.number?.default || 'N/A'; const airline = item.flight?.airline?.name || 'Sconosciuta'; const iataCode = item.flight?.airline?.code?.iata || ''; diff --git a/src/utils/autoNotifications.ts b/src/utils/autoNotifications.ts index c2edd58..5846ed0 100644 --- a/src/utils/autoNotifications.ts +++ b/src/utils/autoNotifications.ts @@ -2,7 +2,7 @@ import * as Calendar from 'expo-calendar'; import * as Notifications from 'expo-notifications'; import AsyncStorage from '@react-native-async-storage/async-storage'; import { getAirlineOps } from './airlineOps'; -import { fetchAirportScheduleRaw } from './fr24api'; +import { fetchAirportScheduleRaw, type FR24FlightData } from './fr24api'; import { showShiftOngoingNotification, dismissShiftOngoingNotification, @@ -63,13 +63,13 @@ export async function autoScheduleNotifications(): Promise { const { departures: allDepartures, arrivals: allArrivals } = await fetchAirportScheduleRaw(); // Filter departures during shift - const shiftDepartures = allDepartures.filter((item: any) => { + const shiftDepartures = allDepartures.filter((item: FR24FlightData) => { const ts = item.flight?.time?.scheduled?.departure; return ts && ts >= shiftStart && ts <= shiftEnd; }); // Filter arrivals during shift (inbound aircraft that become our departures) - const shiftArrivals = allArrivals.filter((item: any) => { + const shiftArrivals = allArrivals.filter((item: FR24FlightData) => { const ts = item.flight?.time?.scheduled?.arrival; return ts && ts >= shiftStart && ts <= shiftEnd; }); @@ -83,8 +83,8 @@ export async function autoScheduleNotifications(): Promise { if (now >= shiftStart && now <= shiftEnd) { const upcoming = shiftDepartures - .filter((f: any) => (f.flight?.time?.scheduled?.departure ?? 0) > now) - .sort((a: any, b: any) => + .filter((f: FR24FlightData) => (f.flight?.time?.scheduled?.departure ?? 0) > now) + .sort((a: FR24FlightData, b: FR24FlightData) => (a.flight?.time?.scheduled?.departure ?? 0) - (b.flight?.time?.scheduled?.departure ?? 0), ); const next = upcoming[0]; diff --git a/src/utils/fr24api.ts b/src/utils/fr24api.ts index a560d89..11924c8 100644 --- a/src/utils/fr24api.ts +++ b/src/utils/fr24api.ts @@ -10,23 +10,79 @@ import { const FETCH_TIMEOUT = 10000; // 10 seconds +export type FR24FlightData = { + flight: { + identification?: { + id?: string; + number?: { + default?: string; + }; + }; + airline?: { + name?: string; + code?: { + iata?: string; + }; + }; + airport?: { + origin?: { + name?: string; + code?: { + iata?: string; + }; + }; + destination?: { + name?: string; + code?: { + iata?: string; + }; + }; + }; + time?: { + scheduled?: { + arrival?: number; + departure?: number; + }; + estimated?: { + arrival?: number; + departure?: number; + }; + real?: { + arrival?: number; + departure?: number; + }; + }; + status?: { + text?: string; + generic?: { + status?: { + color?: string; + }; + }; + }; + aircraft?: { + registration?: string; + }; + }; +}; + export type FR24Schedule = { - arrivals: any[]; - departures: any[]; + arrivals: FR24FlightData[]; + departures: FR24FlightData[]; airportCode: string; airport: AirportInfo; }; export type FR24ScheduleRaw = { - allArrivals: any[]; - allDepartures: any[]; - arrivals: any[]; - departures: any[]; + allArrivals: FR24FlightData[]; + allDepartures: FR24FlightData[]; + arrivals: FR24FlightData[]; + departures: FR24FlightData[]; airportCode: string; airport: AirportInfo; }; -function filterAirlines(data: any[]) { +function filterAirlines(data: FR24FlightData[]) { return data.filter(item => ALLOWED_AIRLINES.some(key => (item.flight?.airline?.name || '').toLowerCase().includes(key)), );