Add processing status

This commit is contained in:
Spxg
2025-05-18 18:05:21 +08:00
parent 16196f0797
commit 65742e09a3
4 changed files with 30 additions and 7 deletions

View File

@@ -172,6 +172,7 @@ fn LoadButton(input_ref: NodeRef<Input>) -> impl IntoView {
filename: filename.clone(),
loaded: ev.loaded(),
total: ev.total(),
opened: None,
}));
}
},

View File

@@ -82,16 +82,34 @@ pub fn Status() -> impl IntoView {
let import_progress = move || {
if let Some(progress) = &*state.import_progress().read() {
let filename = format!("Filename: {}", progress.filename);
let status = format!("Loading: {} of {} bytes.", progress.loaded, progress.total);
let loading = format!("Loading: {} of {} bytes.", progress.loaded, progress.total);
let status = if progress.loaded == progress.total {
view! { <p>"Loading completed"</p> }.into_any()
} else {
().into_any()
};
let process = if progress.loaded == progress.total {
match &progress.opened {
Some(success) => {
if *success {
view! { <p>"Process success"</p> }.into_any()
} else {
view! { <p>"Process failed"</p> }.into_any()
}
}
None => view! { <p>"Processing..."</p> }.into_any(),
}
} else {
().into_any()
};
view! {
<p>{filename}</p>
<p>{status}</p>
{if progress.loaded == progress.total {
view! { <p>"Loading completed"</p> }.into_any()
} else {
().into_any()
}}
<p>{loading}</p>
{status}
{process}
}
.into_any()
} else {

View File

@@ -107,6 +107,7 @@ pub struct ImportProgress {
pub filename: String,
pub loaded: f64,
pub total: f64,
pub opened: Option<bool>,
}
pub struct Exported {

View File

@@ -273,6 +273,9 @@ pub async fn handle_state(state: Store<GlobalState>, mut rx: UnboundedReceiver<W
| WorkerResponse::StepOut(_) => unimplemented!(),
WorkerResponse::LoadDb(result) => {
let keep_ctx = result.is_ok();
if let Some(progress) = &mut *state.import_progress().write() {
progress.opened = Some(keep_ctx);
}
if let Err(err) = result {
state.last_error().set(Some(SQLightError::new_worker(err)));
}