Skip to content

Commit dad5208

Browse files
committed
refactor(web): replace console statements with logger and fix lint issues
- Remove unused Alert import from RepositoryAlgorithmsPanel - Replace console.log/warn with proper logger in use-field-fetch and useCameraPersistence - Fix ref naming conventions (add Ref suffix) in NetworkProvider and PerformanceDashboard
1 parent b8ec2d4 commit dad5208

File tree

5 files changed

+42
-46
lines changed

5 files changed

+42
-46
lines changed

apps/web/src/components/algorithms/RepositoryAlgorithmsPanel.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import {
99
Accordion,
10-
Alert,
1110
Badge,
1211
Box,
1312
Button,

apps/web/src/components/ui/NetworkProvider.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ export const NetworkProvider = ({
167167
const [showOfflineModal, setShowOfflineModal] = useState<boolean>(false);
168168

169169
// Refs for performance tracking
170-
const responseTimes = useRef<number[]>([]);
171-
const totalRequests = useRef<number>(0);
172-
const successfulRequests = useRef<number>(0);
173-
const retryTimeouts = useRef<Map<string, NodeJS.Timeout>>(new Map());
170+
const responseTimesRef = useRef<number[]>([]);
171+
const totalRequestsRef = useRef<number>(0);
172+
const successfulRequestsRef = useRef<number>(0);
173+
const retryTimeoutsRef = useRef<Map<string, NodeJS.Timeout>>(new Map());
174174

175175
// Network monitoring
176176
const checkNetworkStatus = useCallback(async () => {
@@ -185,12 +185,12 @@ export const NetworkProvider = ({
185185
const responseTime = endTime - startTime;
186186

187187
if (response.ok) {
188-
responseTimes.current.push(responseTime);
189-
if (responseTimes.current.length > 10) {
190-
responseTimes.current = responseTimes.current.slice(-10);
188+
responseTimesRef.current.push(responseTime);
189+
if (responseTimesRef.current.length > 10) {
190+
responseTimesRef.current = responseTimesRef.current.slice(-10);
191191
}
192192

193-
const avgTime = responseTimes.current.reduce((a, b) => a + b, 0) / responseTimes.current.length;
193+
const avgTime = responseTimesRef.current.reduce((a, b) => a + b, 0) / responseTimesRef.current.length;
194194
setAverageResponseTime(avgTime);
195195

196196
// Update status based on connection speed
@@ -224,16 +224,16 @@ export const NetworkProvider = ({
224224
setQueue(prev => prev.slice(1));
225225

226226
// Clear retry timeout
227-
const timeout = retryTimeouts.current.get(request.id);
227+
const timeout = retryTimeoutsRef.current.get(request.id);
228228
if (timeout) {
229229
clearTimeout(timeout);
230-
retryTimeouts.current.delete(request.id);
230+
retryTimeoutsRef.current.delete(request.id);
231231
}
232232

233233
// Update stats
234234
setConsecutiveFailures(0);
235235
setLastSuccessfulRequest(Date.now());
236-
successfulRequests.current++;
236+
successfulRequestsRef.current++;
237237

238238
// Resolve request
239239
request.resolve(response);
@@ -249,7 +249,7 @@ export const NetworkProvider = ({
249249
processQueue();
250250
}, delay);
251251

252-
retryTimeouts.current.set(request.id, timeout);
252+
retryTimeoutsRef.current.set(request.id, timeout);
253253

254254
// Move to end of queue
255255
setQueue(prev => [...prev.slice(1), request]);
@@ -258,10 +258,10 @@ export const NetworkProvider = ({
258258
setQueue(prev => prev.slice(1));
259259
setFailedRequests(prev => prev + 1);
260260

261-
const timeout = retryTimeouts.current.get(request.id);
261+
const timeout = retryTimeoutsRef.current.get(request.id);
262262
if (timeout) {
263263
clearTimeout(timeout);
264-
retryTimeouts.current.delete(request.id);
264+
retryTimeoutsRef.current.delete(request.id);
265265
}
266266

267267
request.reject(error as Error);
@@ -303,14 +303,14 @@ export const NetworkProvider = ({
303303
// Clear all queued requests
304304
const clearQueue = useCallback(() => {
305305
queue.forEach(request => {
306-
const timeout = retryTimeouts.current.get(request.id);
306+
const timeout = retryTimeoutsRef.current.get(request.id);
307307
if (timeout) {
308308
clearTimeout(timeout);
309309
}
310310
request.reject(new Error('Queue cleared'));
311311
});
312312

313-
retryTimeouts.current.clear();
313+
retryTimeoutsRef.current.clear();
314314
setQueue([]);
315315
}, [queue]);
316316

@@ -329,8 +329,8 @@ export const NetworkProvider = ({
329329

330330
// Get network statistics
331331
const getNetworkStats = useCallback(() => ({
332-
totalRequests: totalRequests.current,
333-
successfulRequests: successfulRequests.current,
332+
totalRequests: totalRequestsRef.current,
333+
successfulRequests: successfulRequestsRef.current,
334334
failedRequests: failedRequests,
335335
averageResponseTime
336336
}), [failedRequests, averageResponseTime]);

apps/web/src/components/ui/PerformanceDashboard.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ export const PerformanceDashboard = ({
140140
const [alerts, setAlerts] = useState<Array<{ level: AlertLevel; message: string }>>([]);
141141

142142
// Refs for performance tracking
143-
const frameCount = useRef(0);
144-
const lastFrameTime = useRef(performance.now());
145-
const fpsHistory = useRef<number[]>([]);
146-
const animationFrameId = useRef<number | undefined>(undefined);
143+
const frameCountRef = useRef(0);
144+
const lastFrameTimeRef = useRef(performance.now());
145+
const fpsHistoryRef = useRef<number[]>([]);
146+
const animationFrameIdRef = useRef<number | undefined>(undefined);
147147

148148
// Get performance level
149149
const getPerformanceLevel = useCallback((metric: number, thresholds: typeof PERFORMANCE_THRESHOLDS.fps | typeof PERFORMANCE_THRESHOLDS.frameTime): PerformanceLevel => {
@@ -190,19 +190,19 @@ export const PerformanceDashboard = ({
190190
// Performance monitoring loop
191191
const measurePerformance = useCallback(() => {
192192
const currentTime = performance.now();
193-
const deltaTime = currentTime - lastFrameTime.current;
193+
const deltaTime = currentTime - lastFrameTimeRef.current;
194194

195-
frameCount.current++;
196-
fpsHistory.current.push(1000 / deltaTime);
195+
frameCountRef.current++;
196+
fpsHistoryRef.current.push(1000 / deltaTime);
197197

198-
if (fpsHistory.current.length > 60) {
199-
fpsHistory.current = fpsHistory.current.slice(-60);
198+
if (fpsHistoryRef.current.length > 60) {
199+
fpsHistoryRef.current = fpsHistoryRef.current.slice(-60);
200200
}
201201

202202
// Calculate FPS
203203
const currentFPS = Math.round(1000 / deltaTime);
204204
const averageFPS = Math.round(
205-
fpsHistory.current.reduce((sum, fps) => sum + fps, 0) / fpsHistory.current.length
205+
fpsHistoryRef.current.reduce((sum, fps) => sum + fps, 0) / fpsHistoryRef.current.length
206206
);
207207

208208
// Get memory usage
@@ -213,7 +213,7 @@ export const PerformanceDashboard = ({
213213
currentFPS,
214214
averageFPS,
215215
frameTimeMs: Math.round(deltaTime),
216-
droppedFrames: Math.max(0, frameCount.current - averageFPS),
216+
droppedFrames: Math.max(0, frameCountRef.current - averageFPS),
217217
memoryUsedMB: memUsage.used,
218218
memoryLimitMB: memUsage.limit,
219219
memoryPressure: memUsage.pressure,
@@ -230,31 +230,31 @@ export const PerformanceDashboard = ({
230230
};
231231

232232
setMetrics(newMetrics);
233-
lastFrameTime.current = currentTime;
234-
animationFrameId.current = requestAnimationFrame(measurePerformance);
233+
lastFrameTimeRef.current = currentTime;
234+
animationFrameIdRef.current = requestAnimationFrame(measurePerformance);
235235
}, [calculateMemoryUsage, maxHistoryPoints]);
236236

237237
// Start/stop monitoring
238238
const toggleMonitoring = useCallback(() => {
239239
if (isMonitoring) {
240-
if (animationFrameId.current) {
241-
cancelAnimationFrame(animationFrameId.current);
240+
if (animationFrameIdRef.current) {
241+
cancelAnimationFrame(animationFrameIdRef.current);
242242
}
243243
setIsMonitoring(false);
244244
} else {
245-
frameCount.current = 0;
246-
fpsHistory.current = [];
247-
lastFrameTime.current = performance.now();
248-
animationFrameId.current = requestAnimationFrame(measurePerformance);
245+
frameCountRef.current = 0;
246+
fpsHistoryRef.current = [];
247+
lastFrameTimeRef.current = performance.now();
248+
animationFrameIdRef.current = requestAnimationFrame(measurePerformance);
249249
setIsMonitoring(true);
250250
}
251251
}, [isMonitoring, measurePerformance]);
252252

253253
// Cleanup on unmount
254254
useEffect(() => {
255255
return () => {
256-
if (animationFrameId.current) {
257-
cancelAnimationFrame(animationFrameId.current);
256+
if (animationFrameIdRef.current) {
257+
cancelAnimationFrame(animationFrameIdRef.current);
258258
}
259259
};
260260
}, []);

apps/web/src/hooks/use-field-fetch.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export const useFieldFetch = ({
2626

2727
const fetchField = useCallback(
2828
async (fieldName: string) => {
29-
console.log('[useFieldFetch] fetchField called', { fieldName, entityId, entityType });
3029
setIsFetching(true);
3130
setError(null);
3231

@@ -46,7 +45,6 @@ export const useFieldFetch = ({
4645
},
4746
});
4847

49-
console.log('[useFieldFetch] API call successful', { fieldName, result });
5048
logger.debug("api", "Successfully fetched field", {
5149
entityId,
5250
entityType,
@@ -55,14 +53,12 @@ export const useFieldFetch = ({
5553
});
5654

5755
if (result && onSuccess) {
58-
console.log('[useFieldFetch] Calling onSuccess callback', { result });
5956
onSuccess(result);
6057
}
6158

6259
return result;
6360
} catch (err) {
6461
const error = err instanceof Error ? err : new Error("Failed to fetch field");
65-
console.error('[useFieldFetch] API call failed', { fieldName, error });
6662
logger.error("api", "Failed to fetch field", {
6763
entityId,
6864
entityType,

apps/web/src/hooks/useCameraPersistence.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* using localStorage for cross-session persistence.
66
*/
77

8+
import { logger } from "@bibgraph/utils";
89
import { useCallback, useEffect, useRef,useState } from 'react';
910

1011
export interface CameraState {
@@ -139,7 +140,7 @@ export const useCameraPersistence = (options: UseCameraPersistenceOptions = {}):
139140
latestStateRef.current = parsed;
140141
}
141142
} catch (error) {
142-
console.warn('Failed to load camera state:', error);
143+
logger.warn("camera", "Failed to load camera state", { error });
143144
}
144145
setIsLoaded(true);
145146
}, [storageKey, enabled]);
@@ -151,7 +152,7 @@ export const useCameraPersistence = (options: UseCameraPersistenceOptions = {}):
151152
try {
152153
localStorage.setItem(storageKey, JSON.stringify(state));
153154
} catch (error) {
154-
console.warn('Failed to save camera state:', error);
155+
logger.warn("camera", "Failed to save camera state", { error });
155156
}
156157
}, [storageKey, enabled]);
157158

0 commit comments

Comments
 (0)