MCPcopy Create free account
hub / github.com/allocnode/oh-my-sage / DevicePanel

Function DevicePanel

src/components/DevicePanel.tsx:68–200  ·  view source on GitHub ↗
({
                                        collapsed = false,
                                        devices: propDevices,
                                        stats: propStats,
                                        loading: propLoading,
                                        onRefresh,
                                    }: DevicePanelProps)

Source from the content-addressed store, hash-verified

66}
67
68export default function DevicePanel({
69 collapsed = false,
70 devices: propDevices,
71 stats: propStats,
72 loading: propLoading,
73 onRefresh,
74 }: DevicePanelProps) {
75 const [rooms, setRooms] = useState<Room[]>([]);
76 const [searchText, setSearchText] = useState('');
77
78 // 当 props 变化时更新房间分组
79 useEffect(() => {
80 if (propDevices) {
81 const roomMap: Record<string, Device[]> = {};
82 propDevices.forEach(device => {
83 const roomName = device.roomName || '未分组';
84 if (!roomMap[roomName]) {
85 roomMap[roomName] = [];
86 }
87 roomMap[roomName].push(device);
88 });
89 setRooms(Object.entries(roomMap).map(([name, devs]) => ({
90 name,
91 deviceCount: devs.length,
92 devices: devs,
93 })));
94 }
95 }, [propDevices]);
96
97 // 过滤设备
98 const filteredRooms = rooms.map(room => ({
99 ...room,
100 devices: room.devices.filter(d =>
101 d.name.toLowerCase().includes(searchText.toLowerCase()) ||
102 d.model.toLowerCase().includes(searchText.toLowerCase())
103 ),
104 })).filter(room => room.devices.length > 0);
105
106 if (collapsed) {
107 return (
108 <div style={{padding: 16, textAlign: 'center'}}>
109 <Badge count={propStats?.online || 0} showZero>
110 <HomeOutlined style={{fontSize: 24}}/>
111 </Badge>
112 </div>
113 );
114 }
115
116 return (
117 <div style={{height: '100%', minHeight: 0, display: 'flex', flexDirection: 'column'}}>
118 {/* 头部 */}
119 <div style={{padding: '16px', borderBottom: '1px solid #f0f0f0'}}>
120 <div style={{display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 12}}>
121 <Text strong>设备列表</Text>
122 <Button
123 icon={<SyncOutlined/>}
124 size="small"
125 onClick={onRefresh}

Callers

nothing calls this directly

Calls 1

getDeviceIconFunction · 0.85

Tested by

no test coverage detected