Skip to content

Commit

Permalink
feat: add select_item fn
Browse files Browse the repository at this point in the history
  • Loading branch information
kKaskak committed Oct 3, 2024
1 parent a0ca367 commit 80eaf4e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/types/streaming_server/server_url_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ impl ServerUrlBucket {
}
}

pub fn select_item(&mut self, id: &str) -> Result<(), String> {
if let Some(current_selected_item) = self.items.values_mut().find(|item| item.selected) {
current_selected_item.selected = false;
}

if let Some(new_selected_item) = self.items.get_mut(id) {
new_selected_item.selected = true;
Ok(())
} else {
Err("Item not found".to_string())
}
}

pub fn selected_item(&self) -> Option<&ServerUrlItem> {
self.items.values().find(|item| item.selected)
}
Expand Down

0 comments on commit 80eaf4e

Please sign in to comment.