11import { useState , useEffect } from 'react' ;
22import { X , Radio , Plane , MapPin } from 'lucide-react' ;
3+ import { fetchFrequencies } from '../../utils/fetch/data' ;
4+ import type { AirportFrequency } from '../../types/airports' ;
5+ import type { Flight } from '../../types/flight' ;
36import Button from '../common/Button' ;
47import Dropdown from '../common/Dropdown' ;
5- import type { Flight } from '../../types/flight' ;
6- import { fetchFrequencies } from '../../utils/fetch/data' ;
78
89interface ContactAcarsModalProps {
910 isOpen : boolean ;
@@ -26,24 +27,31 @@ export default function ContactAcarsModal({
2627 const [ customMessage , setCustomMessage ] = useState ( '' ) ;
2728 const [ sending , setSending ] = useState ( false ) ;
2829 const [ selectedPosition , setSelectedPosition ] = useState < string > ( 'TWR' ) ;
29- const [ frequencies , setFrequencies ] = useState < { type : string ; freq : string } [ ] > ( [ ] ) ;
30+ const [ frequencies , setFrequencies ] = useState <
31+ { type : string ; freq : string } [ ]
32+ > ( [ ] ) ;
3033
31- const flightsWithAcars = flights . filter ( f => activeAcarsFlights . has ( f . id ) ) ;
34+ const flightsWithAcars = flights . filter ( ( f ) =>
35+ activeAcarsFlights . has ( f . id )
36+ ) ;
3237
3338 useEffect ( ( ) => {
3439 const loadFrequencies = async ( ) => {
3540 try {
36- const freqData = await fetchFrequencies ( ) ;
37- const airportFreq = freqData . find ( ( f : any ) => f . icao === airportIcao ) ;
38- const freqs = Array . isArray ( airportFreq ?. frequencies ) ? airportFreq . frequencies : [ ] ;
41+ const freqData : AirportFrequency [ ] = await fetchFrequencies ( ) ;
42+ const airportFreq = freqData . find (
43+ ( f : AirportFrequency ) => f . icao === airportIcao
44+ ) ;
45+ const freqs = Array . isArray ( airportFreq ?. frequencies )
46+ ? airportFreq . frequencies
47+ : [ ] ;
3948 setFrequencies ( freqs ) ;
4049
41- // Set default position to first available frequency, preferring TWR
4250 if ( freqs . length > 0 ) {
43- const twr = freqs . find ( f => f . type === 'TWR' ) ;
51+ const twr = freqs . find ( ( f ) => f . type === 'TWR' ) ;
4452 setSelectedPosition ( twr ? 'TWR' : freqs [ 0 ] . type ) ;
4553 }
46- } catch ( error ) {
54+ } catch {
4755 setFrequencies ( [ ] ) ;
4856 }
4957 } ;
@@ -54,7 +62,7 @@ export default function ContactAcarsModal({
5462 } , [ airportIcao ] ) ;
5563
5664 const getDefaultMessage = ( ) => {
57- const freq = frequencies . find ( f => f . type === selectedPosition ) ;
65+ const freq = frequencies . find ( ( f ) => f . type === selectedPosition ) ;
5866 if ( freq ) {
5967 return `CONTACT ME ON ${ airportIcao } _${ selectedPosition } ${ freq . freq } ` ;
6068 }
@@ -91,7 +99,9 @@ export default function ContactAcarsModal({
9199 < Radio className = "h-6 w-6 text-blue-400" />
92100 </ div >
93101 < div >
94- < h3 className = "text-xl font-semibold" > Contact ACARS Terminal</ h3 >
102+ < h3 className = "text-xl font-semibold" >
103+ Contact ACARS Terminal
104+ </ h3 >
95105 < p className = "text-sm text-gray-400 mt-1" >
96106 Send a message to a flight's ACARS terminal
97107 </ p >
@@ -112,7 +122,9 @@ export default function ContactAcarsModal({
112122 < div className = "text-center py-8 text-gray-400" >
113123 < Radio className = "h-12 w-12 mx-auto mb-3 opacity-50" />
114124 < p > No flights with active ACARS terminals</ p >
115- < p className = "text-sm mt-2" > Flights must open their ACARS terminal first</ p >
125+ < p className = "text-sm mt-2" >
126+ Flights must open their ACARS terminal first
127+ </ p >
116128 </ div >
117129 ) : (
118130 < >
@@ -125,7 +137,9 @@ export default function ContactAcarsModal({
125137 { flightsWithAcars . map ( ( flight ) => (
126138 < button
127139 key = { flight . id }
128- onClick = { ( ) => setSelectedFlight ( flight ) }
140+ onClick = { ( ) =>
141+ setSelectedFlight ( flight )
142+ }
129143 className = { `w-full text-left p-4 rounded-lg border-2 transition-all ${
130144 selectedFlight ?. id === flight . id
131145 ? 'border-blue-500 bg-blue-500/10'
@@ -141,11 +155,13 @@ export default function ContactAcarsModal({
141155 </ div >
142156 < div className = "text-sm text-gray-400 flex items-center gap-2 mt-1" >
143157 < MapPin className = "h-3 w-3" />
144- { flight . departure } → { flight . arrival }
158+ { flight . departure } →{ ' ' }
159+ { flight . arrival }
145160 </ div >
146161 </ div >
147162 </ div >
148- { selectedFlight ?. id === flight . id && (
163+ { selectedFlight ?. id ===
164+ flight . id && (
149165 < div className = "h-5 w-5 rounded-full bg-blue-500 flex items-center justify-center" >
150166 < div className = "h-2 w-2 rounded-full bg-white" > </ div >
151167 </ div >
@@ -168,9 +184,9 @@ export default function ContactAcarsModal({
168184 Contact as
169185 </ label >
170186 < Dropdown
171- options = { frequencies . map ( freq => ( {
187+ options = { frequencies . map ( ( freq ) => ( {
172188 value : freq . type ,
173- label : `${ freq . type } - ${ freq . freq } `
189+ label : `${ freq . type } - ${ freq . freq } ` ,
174190 } ) ) }
175191 value = { selectedPosition }
176192 onChange = { setSelectedPosition }
@@ -191,7 +207,9 @@ export default function ContactAcarsModal({
191207 < input
192208 type = "text"
193209 value = { customMessage }
194- onChange = { ( e ) => setCustomMessage ( e . target . value ) }
210+ onChange = { ( e ) =>
211+ setCustomMessage ( e . target . value )
212+ }
195213 placeholder = { getDefaultMessage ( ) }
196214 className = "w-full px-4 py-2 bg-gray-800 border border-gray-700 rounded-lg text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500"
197215 maxLength = { 100 }
0 commit comments