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