fix: COM ports stale closure bug, remove USB printer option
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -232,19 +232,25 @@ function DeviceForm({
|
||||
.finally(() => setPrintersLoading(false))
|
||||
}
|
||||
|
||||
// Загружаем порты когда выбирается COM
|
||||
// Загружаем порты когда выбирается COM (availablePorts в deps чтобы не было stale closure)
|
||||
useEffect(() => {
|
||||
if (connection !== 'com' || !wsOnline || availablePorts !== null) return
|
||||
loadPorts()
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [connection, wsOnline])
|
||||
setPortsLoading(true)
|
||||
api.workstations.listPorts(slug, wsId)
|
||||
.then(r => setAvailablePorts(r.ports))
|
||||
.catch(() => setAvailablePorts([]))
|
||||
.finally(() => setPortsLoading(false))
|
||||
}, [connection, wsOnline, slug, wsId, availablePorts])
|
||||
|
||||
// Загружаем принтеры когда выбирается Windows
|
||||
useEffect(() => {
|
||||
if (connection !== 'windows' || !wsOnline || availablePrinters !== null) return
|
||||
loadPrinters()
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [connection, wsOnline])
|
||||
setPrintersLoading(true)
|
||||
api.workstations.listPrinters(slug, wsId)
|
||||
.then(r => setAvailablePrinters(r.printers))
|
||||
.catch(() => setAvailablePrinters([]))
|
||||
.finally(() => setPrintersLoading(false))
|
||||
}, [connection, wsOnline, slug, wsId, availablePrinters])
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!name.trim()) return
|
||||
@@ -400,7 +406,6 @@ function DeviceForm({
|
||||
{ id: 'network', icon: <Network size={14} />, label: 'Сеть (TCP)' },
|
||||
{ id: 'windows', icon: <Monitor size={14} />, label: 'Windows принтер' },
|
||||
{ id: 'com', icon: <Cable size={14} />, label: 'COM-порт' },
|
||||
{ id: 'usb', icon: <Usb size={14} />, label: 'USB' },
|
||||
] as const).map(c => (
|
||||
<button
|
||||
key={c.id}
|
||||
|
||||
Reference in New Issue
Block a user