app.rs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. use crate::{
  2. info::InfoScreen,
  3. list::StatefulList,
  4. types::{NodeId, NodeInfo},
  5. };
  6. use std::collections::HashMap;
  7. // the information here should be continually updating
  8. // nodes are added from the result of rpc requests
  9. #[derive(Clone)]
  10. pub struct App {
  11. pub node_list: StatefulList,
  12. }
  13. impl App {
  14. pub fn new() -> App {
  15. let mut hashmap: HashMap<NodeId, NodeInfo> = HashMap::new();
  16. let node_id = Self::get_node_id();
  17. let node_info = Self::get_node_info();
  18. // TODO: fix this
  19. for id in node_id.iter() {
  20. for info in node_info.iter() {
  21. hashmap.insert(id.to_string(), info.to_string());
  22. }
  23. }
  24. let node_info = InfoScreen::new();
  25. App { node_list: StatefulList::new(hashmap, node_info) }
  26. }
  27. fn get_node_id() -> Vec<String> {
  28. let mut node_list = Vec::new();
  29. for num in 1..100 {
  30. let new_nodes = format!("\nNode {}\n", num);
  31. node_list.push(new_nodes);
  32. }
  33. node_list
  34. }
  35. fn get_node_info() -> Vec<String> {
  36. let mut node_info = Vec::new();
  37. for _num in 1..100 {
  38. //let new_info = format!("\nConnections: {}\n", num);
  39. let new_info = "";
  40. node_info.push(new_info.to_string());
  41. }
  42. node_info
  43. }
  44. // every 5 seconds
  45. // TODO: implement this
  46. //fn update(&mut self) {
  47. // let node = self.node.remove(0);
  48. // self.nodes.push(node);
  49. //}
  50. }