Files
Alberto-Audrix 32a36cceff
CI / lint-and-test (push) Canceled after 0s
first commit
2026-07-28 08:55:05 +07:00

81 lines
2.8 KiB
TypeScript

import React from 'react';
import { IotDevice, IotDeviceType } from '../../types';
import { useAppContext } from '../../context/AppContext';
const statusConfig: {
[key in IotDevice['status']]: { text: string; color: string; pulse: boolean };
} = {
online: { text: 'Online', color: 'text-green-600', pulse: true },
offline: { text: 'Offline', color: 'text-gray-500', pulse: false },
error: { text: 'Error', color: 'text-red-500', pulse: false },
};
const SensorItem: React.FC<{ device: IotDevice; locationName: string }> = ({
device,
locationName,
}) => {
const status = statusConfig[device.status];
return (
<div className="flex items-center justify-between p-3 bg-gray-50 rounded-lg hover:bg-gray-100/70 transition-colors">
<div>
<p className="font-semibold text-gray-800 text-sm truncate" title={device.name}>
{device.name}
</p>
<p className="text-xs text-gray-500 truncate" title={locationName}>
{locationName}
</p>
</div>
<div className="text-right flex-shrink-0 pl-2">
<p className="font-bold text-gray-800 text-lg">{device.currentValue}</p>
<div
className={`flex items-center justify-end space-x-1.5 ${status.color} text-xs font-semibold`}
>
{status.pulse && (
<span className="relative flex h-2 w-2">
<span
className={`animate-ping absolute inline-flex h-full w-full rounded-full opacity-75 ${status.color.replace('text-', 'bg-')}`}
></span>
<span
className={`relative inline-flex rounded-full h-2 w-2 ${status.color.replace('text-', 'bg-')}`}
></span>
</span>
)}
<span>{status.text}</span>
</div>
</div>
</div>
);
};
const LiveScaleList: React.FC = () => {
const { iotDevices, getFullLocationName } = useAppContext();
const weightSensors = iotDevices.filter((d) => d.type === IotDeviceType.WEIGHT_SCALE);
return (
<div className="bg-white p-6 rounded-xl shadow-sm h-full flex flex-col">
<h2 className="text-xl font-bold mb-4">Statistik per Sensor Timbangan</h2>
{weightSensors.length > 0 ? (
<div className="space-y-3 overflow-y-auto flex-grow pr-2">
{weightSensors.map((device) => (
<SensorItem
key={device.id}
device={device}
locationName={getFullLocationName(device.floorId)}
/>
))}
</div>
) : (
<div className="flex-grow flex items-center justify-center text-center text-gray-500">
<div>
<i className="fa-solid fa-weight-scale text-4xl text-gray-300"></i>
<p className="mt-2">Tidak ada sensor timbangan ditemukan.</p>
</div>
</div>
)}
</div>
);
};
export default LiveScaleList;