Fix device selection reset issue in LED Strip Testing
- Fix frontend device selection state management to properly update selected board when boards_changed event is triggered - Optimize backend board status checking to only emit boards_changed events when there are actual changes - Prevent unnecessary UI updates and improve performance Fixes issue where device selection would reset to unselected state shortly after selection
This commit is contained in:
@ -194,25 +194,42 @@ impl UdpRpc {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store previous board states to detect changes
|
||||||
|
let prev_boards = boards
|
||||||
|
.values()
|
||||||
|
.map(|it| async move { it.info.read().await.clone() });
|
||||||
|
let prev_boards = join_all(prev_boards).await;
|
||||||
|
|
||||||
|
// Check all boards
|
||||||
for board in boards.values() {
|
for board in boards.values() {
|
||||||
if let Err(err) = board.check().await {
|
if let Err(err) = board.check().await {
|
||||||
error!("failed to check board: {:?}", err);
|
error!("failed to check board: {:?}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let tx_boards = boards
|
// Get current board states after check
|
||||||
|
let current_boards = boards
|
||||||
.values()
|
.values()
|
||||||
.map(|it| async move { it.info.read().await.clone() });
|
.map(|it| async move { it.info.read().await.clone() });
|
||||||
let tx_boards = join_all(tx_boards).await;
|
let current_boards = join_all(current_boards).await;
|
||||||
|
|
||||||
drop(boards);
|
drop(boards);
|
||||||
|
|
||||||
let board_change_sender = self.boards_change_sender.clone();
|
// Only send update if there are actual changes
|
||||||
if let Err(err) = board_change_sender.send(tx_boards) {
|
let has_changes = prev_boards.len() != current_boards.len() ||
|
||||||
error!("failed to send board change: {:?}", err);
|
prev_boards.iter().zip(current_boards.iter()).any(|(prev, current)| {
|
||||||
}
|
prev.connect_status != current.connect_status ||
|
||||||
|
prev.ttl != current.ttl ||
|
||||||
|
prev.checked_at != current.checked_at
|
||||||
|
});
|
||||||
|
|
||||||
drop(board_change_sender);
|
if has_changes {
|
||||||
|
let board_change_sender = self.boards_change_sender.clone();
|
||||||
|
if let Err(err) = board_change_sender.send(current_boards) {
|
||||||
|
error!("failed to send board change: {:?}", err);
|
||||||
|
}
|
||||||
|
drop(board_change_sender);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,10 @@ export const LedStripTest = () => {
|
|||||||
board.port === currentBoard.port
|
board.port === currentBoard.port
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!stillExists) {
|
if (stillExists) {
|
||||||
|
// Update to the new board object to reflect any status changes
|
||||||
|
setSelectedBoard(stillExists);
|
||||||
|
} else {
|
||||||
// Current board is no longer available, select first available or null
|
// Current board is no longer available, select first available or null
|
||||||
setSelectedBoard(boardList.length > 0 ? boardList[0] : null);
|
setSelectedBoard(boardList.length > 0 ? boardList[0] : null);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user