app.rs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. use crate::{
  2. list::NodeIdList,
  3. node_info::{NodeInfo, NodeInfoView},
  4. };
  5. //use smol::Timer;
  6. //use std::{collections::HashMap, time::Duration};
  7. #[derive(Clone)]
  8. pub struct App {
  9. pub node_list: NodeIdList,
  10. pub node_info: NodeInfoView,
  11. }
  12. impl App {
  13. pub fn new() -> App {
  14. let infos = vec![
  15. NodeInfo {
  16. id: "0385048034sodisofjhosd1111q3434".to_string(),
  17. connections: 10,
  18. is_active: true,
  19. last_message: "hey how are you?".to_string(),
  20. },
  21. NodeInfo {
  22. id: "09w30we9wsnfksdfkdjflsjkdfjdfsd".to_string(),
  23. connections: 5,
  24. is_active: false,
  25. last_message: "lmao".to_string(),
  26. },
  27. NodeInfo {
  28. id: "038043325alsdlasjfrsdfsdfsdjsdf".to_string(),
  29. connections: 7,
  30. is_active: true,
  31. last_message: "gm".to_string(),
  32. },
  33. NodeInfo {
  34. id: "04985034953ldflsdjflsdjflsdjfii".to_string(),
  35. connections: 2,
  36. is_active: true,
  37. last_message: "hihi".to_string(),
  38. },
  39. NodeInfo {
  40. id: "09850249352asdjapsdikalskasdkas".to_string(),
  41. connections: 10,
  42. is_active: true,
  43. last_message: "wtf".to_string(),
  44. },
  45. ];
  46. let node_info = NodeInfoView::new(infos.clone());
  47. let ids = vec![
  48. infos[0].id.clone(),
  49. infos[1].id.clone(),
  50. infos[2].id.clone(),
  51. infos[3].id.clone(),
  52. infos[4].id.clone(),
  53. ];
  54. let node_list = NodeIdList::new(ids);
  55. App { node_list, node_info }
  56. }
  57. // TODO: implement this
  58. //async fn sleep(self, dur: Duration) {
  59. // Timer::after(dur).await;
  60. //}
  61. //pub async fn update(mut self) {
  62. // self.node_list.nodes.insert("New node joined".to_string(), "".to_string());
  63. // //self.sleep(Duration::from_secs(2)).await;
  64. //}
  65. }