diff --git a/src/code_editor/editor.rs b/src/code_editor/editor.rs index 80e8c7d..3fb1ae1 100644 --- a/src/code_editor/editor.rs +++ b/src/code_editor/editor.rs @@ -126,18 +126,17 @@ impl CodeEditor { let getter = &mut self.info_fetcher; if let Some(getter) = getter { - match &getter.check_promise() { - GetStatus::NotStarted => {} - GetStatus::InProgress => {} - GetStatus::Success(text) => { - self.instructions = text.clone(); - } + let result = &getter.check_promise(); + match result { GetStatus::Failed(err) => { self.toasts .error(format!("Error fetching challenge info: {}", err)) .set_duration(Some(Duration::from_secs(5))); - log::error!("Error fetching file: {}", err); + log::error!("Error fetching document: {}", err); + } + _ => { + self.instructions = result.to_string(); } } } diff --git a/src/helpers/challenges.rs b/src/helpers/challenges.rs index ae45933..17e4eba 100644 --- a/src/helpers/challenges.rs +++ b/src/helpers/challenges.rs @@ -1,4 +1,4 @@ -use super::fetchers::{GetStatus, Getter}; +use super::fetchers::Getter; use std::fmt::{self, Display, Formatter}; #[derive( @@ -42,7 +42,6 @@ impl Challenges { _ => { let mut getter = Getter::::new(&self.get_info_url(), context, false); getter.get(); - Some(getter) } } diff --git a/src/helpers/fetchers.rs b/src/helpers/fetchers.rs index 2058a6b..64dbd3d 100644 --- a/src/helpers/fetchers.rs +++ b/src/helpers/fetchers.rs @@ -11,6 +11,17 @@ pub enum GetStatus { Failed(String), } +impl std::fmt::Display for GetStatus { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + GetStatus::NotStarted => write!(f, "Not started"), + GetStatus::InProgress => write!(f, "Loading..."), + GetStatus::Success(s) => write!(f, "{}", s), + GetStatus::Failed(s) => write!(f, "{}", s), + } + } +} + pub struct Getter { promise: Option>>, with_credentials: bool,