fix: use api lib in PulseTestPage
This commit is contained in:
parent
79b6bdbcd2
commit
893244169d
1 changed files with 9 additions and 21 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
import { useAuth } from '../context/AuthContext';
|
||||
import { Activity, Thermometer, Droplets, Wind, Sun, Wifi, WifiOff, RefreshCw, Bell } from 'lucide-react';
|
||||
import { useNotifications } from '../hooks/useNotifications';
|
||||
import api from '../lib/api';
|
||||
|
||||
interface PulseDevice {
|
||||
id: string;
|
||||
|
|
@ -29,7 +29,6 @@ interface PulseStatus {
|
|||
}
|
||||
|
||||
export default function PulseTestPage() {
|
||||
const { token } = useAuth();
|
||||
const { connected: wsConnected, alerts, unreadCount } = useNotifications();
|
||||
|
||||
const [status, setStatus] = useState<PulseStatus | null>(null);
|
||||
|
|
@ -40,33 +39,22 @@ export default function PulseTestPage() {
|
|||
const [lastUpdate, setLastUpdate] = useState<Date | null>(null);
|
||||
|
||||
const fetchData = async () => {
|
||||
if (!token) return;
|
||||
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
// Fetch status
|
||||
const statusRes = await fetch('/api/pulse/status', {
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
});
|
||||
const statusData = await statusRes.json();
|
||||
setStatus(statusData);
|
||||
const statusRes = await api.get('/api/pulse/status');
|
||||
setStatus(statusRes.data);
|
||||
|
||||
if (statusData.connected) {
|
||||
if (statusRes.data.connected) {
|
||||
// Fetch devices
|
||||
const devicesRes = await fetch('/api/pulse/devices', {
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
});
|
||||
const devicesData = await devicesRes.json();
|
||||
setDevices(devicesData.devices || []);
|
||||
const devicesRes = await api.get('/api/pulse/devices');
|
||||
setDevices(devicesRes.data.devices || []);
|
||||
|
||||
// Fetch readings
|
||||
const readingsRes = await fetch('/api/pulse/readings', {
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
});
|
||||
const readingsData = await readingsRes.json();
|
||||
setReadings(readingsData.readings || []);
|
||||
const readingsRes = await api.get('/api/pulse/readings');
|
||||
setReadings(readingsRes.data.readings || []);
|
||||
}
|
||||
|
||||
setLastUpdate(new Date());
|
||||
|
|
@ -83,7 +71,7 @@ export default function PulseTestPage() {
|
|||
// Refresh every 30 seconds
|
||||
const interval = setInterval(fetchData, 30000);
|
||||
return () => clearInterval(interval);
|
||||
}, [token]);
|
||||
}, []);
|
||||
|
||||
const getStatusColor = (connected: boolean) =>
|
||||
connected ? 'text-green-500' : 'text-red-500';
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue