Skip to content

Commit

Permalink
done should come from CURRENT_TUTORIAL, not fs
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Nov 6, 2023
1 parent ecc17dd commit a1db437
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions fastn-core/src/tutor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ static CURRENT_TUTORIAL: once_cell::sync::Lazy<async_lock::RwLock<Option<Tutoria

#[derive(serde::Deserialize)]
pub struct Tutorial {
path: String,
id: String,
data: fastn_core::commands::serve::AppData,
}

pub(crate) async fn config(
app_data: &fastn_core::commands::serve::AppData,
) -> fastn_core::Result<(fastn_core::Config, String)> {
let (root, app_data) = match CURRENT_TUTORIAL.read().await.as_ref() {
Some(context) => (Some(context.path.clone()), context.data.clone()),
Some(context) => (Some(context.id.clone()), context.data.clone()),
None => (None, app_data.clone()),
};

Expand Down Expand Up @@ -85,13 +85,13 @@ pub async fn process(
));
}

let state =
let fs_state: TutorStateFS =
match tokio::fs::read(dirs::home_dir().unwrap().join(".fastn").join("tutor.json")).await {
Ok(v) => serde_json::from_slice(&v)?,
Err(e) => match dbg!(e.kind()) {
std::io::ErrorKind::NotFound => {
println!("not found, using default");
TutorState::default()
TutorStateFS::default()
}
_ => {
println!("error: {:?}, {:?}", e, e.kind());
Expand All @@ -100,13 +100,23 @@ pub async fn process(
},
};

let state = TutorState {
fs_state,
current: CURRENT_TUTORIAL.read().await.as_ref().map(|t| t.id.clone()),
};

doc.from_json(&state, &kind, &value)
}

#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Default, serde::Serialize)]
struct TutorState {
fs_state: TutorStateFS,
current: Option<String>,
}

#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
struct TutorStateFS {
done: Vec<String>,
current: String,
}

pub fn is_tutor() -> bool {
Expand Down

0 comments on commit a1db437

Please sign in to comment.