11import React , { useState , useEffect } from 'react' ;
2- import {
3- Circle ,
4- Square ,
5- CloudUpload ,
6- Trash2 ,
7- Database ,
2+ import {
3+ Circle ,
4+ Square ,
5+ CloudUpload ,
6+ Trash2 ,
7+ Database ,
88 AlertCircle ,
99 CheckCircle2 ,
1010 Activity ,
11- Settings ,
1211 Globe ,
1312 RefreshCw ,
1413 Wifi ,
15- WifiOff
14+ WifiOff ,
15+ FlaskConical
1616} from 'lucide-react' ;
1717import { loggingService } from './services/LoggingService' ;
1818import { syncService } from './services/SyncService' ;
19+ import type { ConnectionTestResult } from './services/SyncService' ;
1920import { webSocketService } from './services/WebSocketService' ;
2021import type { ConnectionStatus } from './services/WebSocketService' ;
2122import { loggingHandler } from './services/LoggingHandler' ;
@@ -26,6 +27,8 @@ const FlightDataRecorder: React.FC = () => {
2627 const [ totalCount , setTotalCount ] = useState ( 0 ) ;
2728 const [ isSyncing , setIsSyncing ] = useState ( syncService . isSyncing ( ) ) ;
2829 const [ syncProgress , setSyncProgress ] = useState ( { processed : 0 , total : 0 } ) ;
30+ const [ connTest , setConnTest ] = useState < ConnectionTestResult | null > ( null ) ;
31+ const [ isTesting , setIsTesting ] = useState ( false ) ;
2932
3033 // Connection state
3134 const [ wsStatus , setWsStatus ] = useState < ConnectionStatus > ( {
@@ -36,13 +39,17 @@ const FlightDataRecorder: React.FC = () => {
3639
3740 // Settings for InfluxDB
3841 const [ influxSettings , setInfluxSettings ] = useState ( {
39- url : localStorage . getItem ( 'influx-url' ) || 'http ://localhost:8181 ' ,
42+ url : localStorage . getItem ( 'influx-url' ) || 'https ://influxdb3.westernformularacing.org ' ,
4043 token : localStorage . getItem ( 'influx-token' ) || '' ,
4144 org : localStorage . getItem ( 'influx-org' ) || 'WFR' ,
42- bucket : localStorage . getItem ( 'influx-bucket' ) || 'WFR25'
45+ bucket : localStorage . getItem ( 'influx-bucket' ) || 'WFR26' ,
4346 } ) ;
4447
4548 useEffect ( ( ) => {
49+ // Legacy cleanup: SSO-cookie mode no longer uses CF service-token fields.
50+ localStorage . removeItem ( 'influx-cfClientId' ) ;
51+ localStorage . removeItem ( 'influx-cfClientSecret' ) ;
52+
4653 // Initialize standard handlers
4754 loggingHandler . initialize ( ) ;
4855 webSocketService . initialize ( ) ;
@@ -119,6 +126,18 @@ const FlightDataRecorder: React.FC = () => {
119126 localStorage . setItem ( `influx-${ key } ` , value ) ;
120127 } ;
121128
129+ const handleTestConnection = async ( ) => {
130+ setIsTesting ( true ) ;
131+ setConnTest ( null ) ;
132+ const result = await syncService . testConnection (
133+ influxSettings . url ,
134+ influxSettings . token ,
135+ influxSettings . bucket
136+ ) ;
137+ setConnTest ( result ) ;
138+ setIsTesting ( false ) ;
139+ } ;
140+
122141 const saveWsUrl = ( ) => {
123142 if ( customWsUrl ) {
124143 localStorage . setItem ( 'custom-ws-url' , customWsUrl ) ;
@@ -138,7 +157,7 @@ const FlightDataRecorder: React.FC = () => {
138157 </ div >
139158 WFR Flight Recorder
140159 </ h1 >
141- < p className = "text-slate-400 mt-1 font-medium italic" > High-Fidelity Telemetry Logging </ p >
160+ < p className = "text-slate-400 mt-1 font-medium italic" > ehh we will get our antenna figured out soon </ p >
142161 </ div >
143162
144163 < div className = "flex items-center gap-3" >
@@ -286,10 +305,23 @@ const FlightDataRecorder: React.FC = () => {
286305 className = "w-full bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 font-mono text-sm focus:ring-2 focus:ring-blue-500 outline-none"
287306 />
288307 </ div >
308+ < p className = "text-[10px] text-slate-500 leading-relaxed border border-slate-700/60 rounded-xl px-3 py-2 bg-slate-900/60" >
309+ Cloudflare Access uses your browser SSO session. Sync requests include cookies automatically.
310+ </ p >
289311 </ div >
290312 </ div >
291313
292314 < div className = "mt-auto pt-6 border-t border-slate-700/50" >
315+ { connTest && (
316+ < div className = { `mb-4 flex items-start gap-2 px-4 py-3 rounded-xl text-sm font-mono border ${
317+ connTest . ok
318+ ? 'bg-emerald-500/10 border-emerald-500/30 text-emerald-400'
319+ : 'bg-red-500/10 border-red-500/30 text-red-400'
320+ } `} >
321+ { connTest . ok ? < CheckCircle2 size = { 16 } className = "mt-0.5 shrink-0" /> : < AlertCircle size = { 16 } className = "mt-0.5 shrink-0" /> }
322+ < span > { connTest . message } </ span >
323+ </ div >
324+ ) }
293325 { isSyncing && (
294326 < div className = "mb-4" >
295327 < div className = "flex justify-between text-[10px] font-black text-emerald-400 uppercase tracking-widest mb-2" >
@@ -305,14 +337,24 @@ const FlightDataRecorder: React.FC = () => {
305337 </ div >
306338 ) }
307339
308- < button
309- disabled = { isSyncing || unsyncedCount === 0 }
310- onClick = { handleSync }
311- className = "w-full bg-emerald-600 hover:bg-emerald-700 disabled:bg-slate-700 disabled:opacity-50 disabled:cursor-not-allowed text-white font-black py-5 rounded-2xl flex items-center justify-center gap-3 transition-all shadow-xl shadow-emerald-900/20 uppercase tracking-widest text-lg"
312- >
313- { isSyncing ? < Activity className = "animate-spin" size = { 24 } /> : < CloudUpload size = { 24 } /> }
314- { isSyncing ? 'Synchronizing...' : 'Upload Data to InfluxDB' }
315- </ button >
340+ < div className = "flex gap-3" >
341+ < button
342+ disabled = { isTesting || isSyncing }
343+ onClick = { handleTestConnection }
344+ className = "flex items-center justify-center gap-2 px-5 py-5 rounded-2xl font-black text-sm uppercase tracking-widest border-2 border-slate-600 hover:border-blue-500 text-slate-400 hover:text-blue-400 disabled:opacity-50 disabled:cursor-not-allowed transition-all"
345+ >
346+ { isTesting ? < Activity className = "animate-spin" size = { 18 } /> : < FlaskConical size = { 18 } /> }
347+ Test
348+ </ button >
349+ < button
350+ disabled = { isSyncing || unsyncedCount === 0 }
351+ onClick = { handleSync }
352+ className = "flex-1 bg-emerald-600 hover:bg-emerald-700 disabled:bg-slate-700 disabled:opacity-50 disabled:cursor-not-allowed text-white font-black py-5 rounded-2xl flex items-center justify-center gap-3 transition-all shadow-xl shadow-emerald-900/20 uppercase tracking-widest text-lg"
353+ >
354+ { isSyncing ? < Activity className = "animate-spin" size = { 24 } /> : < CloudUpload size = { 24 } /> }
355+ { isSyncing ? 'Synchronizing...' : 'Upload to InfluxDB' }
356+ </ button >
357+ </ div >
316358 </ div >
317359 </ div >
318360 </ div >
0 commit comments