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