Skip to content

Commit

Permalink
Moves more bits into helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbrain-za committed Nov 11, 2023
1 parent 29ac79a commit d1da00f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/code_editor/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/challenges.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::fetchers::{GetStatus, Getter};
use super::fetchers::Getter;
use std::fmt::{self, Display, Formatter};

#[derive(
Expand Down Expand Up @@ -42,7 +42,6 @@ impl Challenges {
_ => {
let mut getter = Getter::<String>::new(&self.get_info_url(), context, false);
getter.get();

Some(getter)
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/helpers/fetchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ pub enum GetStatus<T: Clone + Sync + Send> {
Failed(String),
}

impl std::fmt::Display for GetStatus<String> {
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<T: Clone + Sync + Send + 'static> {

Check warning on line 25 in src/helpers/fetchers.rs

View workflow job for this annotation

GitHub Actions / Check

struct `Getter` is never constructed

Check failure on line 25 in src/helpers/fetchers.rs

View workflow job for this annotation

GitHub Actions / Clippy

struct `Getter` is never constructed
promise: Option<Promise<Result<T, String>>>,
with_credentials: bool,
Expand Down

0 comments on commit d1da00f

Please sign in to comment.