feat: add setup complete step
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
mod github_step;
|
mod github_step;
|
||||||
mod screen;
|
mod screen;
|
||||||
|
mod setup_complete_step;
|
||||||
mod storage;
|
mod storage;
|
||||||
mod welcome_step;
|
mod welcome_step;
|
||||||
|
|
||||||
@@ -14,10 +15,10 @@ use crate::{app, screen::setup_wizard::screen::Screen};
|
|||||||
pub(crate) enum Step {
|
pub(crate) enum Step {
|
||||||
Welcome,
|
Welcome,
|
||||||
ConnectToGithub,
|
ConnectToGithub,
|
||||||
Customization,
|
SetupComplete,
|
||||||
}
|
}
|
||||||
|
|
||||||
const ALL_SETUP_STEPS: [Step; 3] = [Step::Welcome, Step::ConnectToGithub, Step::Customization];
|
const ALL_SETUP_STEPS: [Step; 3] = [Step::Welcome, Step::ConnectToGithub, Step::SetupComplete];
|
||||||
|
|
||||||
pub fn read_setup_status() -> SetupStatus {
|
pub fn read_setup_status() -> SetupStatus {
|
||||||
storage::read_setup_state()
|
storage::read_setup_state()
|
||||||
@@ -65,7 +66,7 @@ impl Step {
|
|||||||
match self {
|
match self {
|
||||||
Step::Welcome => 0,
|
Step::Welcome => 0,
|
||||||
Step::ConnectToGithub => 1,
|
Step::ConnectToGithub => 1,
|
||||||
Step::Customization => 2,
|
Step::SetupComplete => 2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ use crate::{
|
|||||||
text::text,
|
text::text,
|
||||||
},
|
},
|
||||||
screen::setup_wizard::{
|
screen::setup_wizard::{
|
||||||
ALL_SETUP_STEPS, Step, github_step,
|
ALL_SETUP_STEPS, SetupStatus, Step, github_step,
|
||||||
storage::{StoredSetupState, store_setup_state},
|
setup_complete_step::setup_complete_step,
|
||||||
|
storage::{StoredSetupState, store_setup_status},
|
||||||
welcome_step::welcome_step,
|
welcome_step::welcome_step,
|
||||||
},
|
},
|
||||||
storage,
|
storage,
|
||||||
@@ -38,29 +39,24 @@ impl Screen {
|
|||||||
fn advance_to_next_step(&mut self, cx: &mut gpui::Context<Self>) {
|
fn advance_to_next_step(&mut self, cx: &mut gpui::Context<Self>) {
|
||||||
let next_step = match self.current_step {
|
let next_step = match self.current_step {
|
||||||
Step::Welcome => Step::ConnectToGithub,
|
Step::Welcome => Step::ConnectToGithub,
|
||||||
Step::ConnectToGithub => Step::Customization,
|
Step::ConnectToGithub => Step::SetupComplete,
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
};
|
};
|
||||||
self.current_step = next_step;
|
self.current_step = next_step;
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_setup_state(&mut self, state: StoredSetupState, cx: &mut gpui::Context<Self>) {
|
fn save_setup_state(&mut self, state: SetupStatus, cx: &mut gpui::Context<Self>) {
|
||||||
_ = cx.background_executor().block(store_setup_state(state));
|
_ = cx.background_executor().block(store_setup_status(state));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_github_connected(&mut self, user_id: api::user::Id, cx: &mut gpui::Context<Self>) {
|
fn on_github_connected(&mut self, user_id: api::user::Id, cx: &mut gpui::Context<Self>) {
|
||||||
let state = StoredSetupState {
|
|
||||||
step: Step::Customization,
|
|
||||||
connected_user_id: Some(user_id),
|
|
||||||
};
|
|
||||||
self.save_setup_state(state, cx);
|
|
||||||
|
|
||||||
// TODO: handle state write error
|
// TODO: handle state write error
|
||||||
_ = storage::update_persisted_state(|state| {
|
_ = storage::update_persisted_state(|state| {
|
||||||
state.selected_account = user_id;
|
state.selected_account = user_id;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.save_setup_state(SetupStatus::Completed, cx);
|
||||||
self.advance_to_next_step(cx);
|
self.advance_to_next_step(cx);
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
@@ -96,7 +92,7 @@ impl Screen {
|
|||||||
let label = match step {
|
let label = match step {
|
||||||
Step::Welcome => "Welcome!",
|
Step::Welcome => "Welcome!",
|
||||||
Step::ConnectToGithub => "Connect to GitHub",
|
Step::ConnectToGithub => "Connect to GitHub",
|
||||||
Step::Customization => "Customize Novem",
|
Step::SetupComplete => "Complete!",
|
||||||
};
|
};
|
||||||
let is_completed = i < self.current_step.order();
|
let is_completed = i < self.current_step.order();
|
||||||
let is_current = self.current_step == *step;
|
let is_current = self.current_step == *step;
|
||||||
@@ -148,7 +144,7 @@ impl gpui::Render for Screen {
|
|||||||
None => self.init_github_step_view(cx).clone().into_any_element(),
|
None => self.init_github_step_view(cx).clone().into_any_element(),
|
||||||
},
|
},
|
||||||
|
|
||||||
Step::Customization => text("customization").into_any_element(),
|
Step::SetupComplete => setup_complete_step().into_any_element(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let theme = app::current_theme(cx);
|
let theme = app::current_theme(cx);
|
||||||
|
|||||||
33
src/screen/setup_wizard/setup_complete_step.rs
Normal file
33
src/screen/setup_wizard/setup_complete_step.rs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
use gpui::{ParentElement, Styled, div};
|
||||||
|
|
||||||
|
use crate::component::{button::button, text::text};
|
||||||
|
|
||||||
|
pub(crate) fn setup_complete_step() -> impl gpui::IntoElement {
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.size_full()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex_1()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.child(text("ദ്ദി/ᐠ - ⩊ -マ.ᐟ").text_2xl().styled(|it| it.mb_4()))
|
||||||
|
.child(text("Setup complete!").bold().text_2xl())
|
||||||
|
.child(text("You can now start using Novem.").opacity(0.8)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.justify_end()
|
||||||
|
.w_full()
|
||||||
|
.p_4()
|
||||||
|
.pt_0()
|
||||||
|
.child(button("setup-done").label("Start")),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -15,9 +15,9 @@ pub(crate) enum SetupStatus {
|
|||||||
Completed,
|
Completed,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn store_setup_state(state: StoredSetupState) -> anyhow::Result<()> {
|
pub(crate) async fn store_setup_status(state: SetupStatus) -> anyhow::Result<()> {
|
||||||
let path = storage::data_dir_path().join("setup.json");
|
let path = storage::data_dir_path().join("setup.json");
|
||||||
let content = serde_json::to_string(&SetupStatus::InProgress(state))?;
|
let content = serde_json::to_string(&state)?;
|
||||||
tokio::fs::write(path, content).await?;
|
tokio::fs::write(path, content).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user