Browse Source

map: error if view.node_id is still empty after first initialization loop

lunar-mining 4 years ago
parent
commit
2506932665
2 changed files with 19 additions and 13 deletions
  1. 15 12
      bin/map/src/main.rs
  2. 4 1
      bin/map/src/ui.rs

+ 15 - 12
bin/map/src/main.rs

@@ -216,7 +216,6 @@ async fn poll(client: Map, model: Arc<Model>) -> Result<()> {
             async_util::sleep(2).await;
         }
     } else {
-        // TODO: fix this
         async_util::sleep(10).await;
         Err(Error::ConnectTimeout)
     }
@@ -233,21 +232,25 @@ async fn render<B: Backend>(terminal: &mut Terminal<B>, model: Arc<Model>) -> io
 
     view.id_list.state.select(Some(0));
     view.info_list.index = 0;
+    let mut counter = 0;
 
     loop {
+        counter = counter + 1;
         view.update(model.info_list.infos.lock().await.clone());
-        if view.info_list.infos.is_empty() {
-            // TODO: this lags forever if IRC is not running. add an error
-            let mut progress = 0;
-            while progress < 100 {
-                terminal.draw(|f| {
-                    ui::init_panel(f, progress);
-                })?;
-
-                Timer::after(Duration::from_millis(1)).await;
-                progress = progress + 1;
+        if view.id_list.node_id.is_empty() {
+            if counter == 1 {
+                let mut progress = 0;
+                while progress < 100 {
+                    terminal.draw(|f| {
+                        ui::init_panel(f, progress);
+                    })?;
+                    Timer::after(Duration::from_millis(1)).await;
+                    progress = progress + 1;
+                }
+            } else if counter == 2 {
+                terminal.clear()?;
+                println!("Could not connect to node. Are you sure IRC is running?");
             }
-            terminal.clear()?;
         } else {
             terminal.draw(|f| {
                 ui::ui(f, view.clone());

+ 4 - 1
bin/map/src/ui.rs

@@ -85,5 +85,8 @@ pub fn init_panel<B: Backend>(f: &mut Frame<'_, B>, progress: u16) {
         .percent(progress);
 
     f.render_widget(gauge, slice[0]);
-    // TODO: loading widget
+}
+
+pub fn error<B: Backend>(f: &mut Frame<'_, B>) {
+    // thing
 }