2023-04-25 13:16:11 +00:00
|
|
|
#![allow(non_snake_case)]
|
|
|
|
use dioxus::prelude::*;
|
2023-06-05 08:47:04 +00:00
|
|
|
use tokio::time::sleep;
|
2023-04-25 13:16:11 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
dioxus_desktop::launch(App);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn App(cx: Scope) -> Element {
|
2023-06-06 00:06:27 +00:00
|
|
|
let enable_directory_upload = use_state(cx, || false);
|
2023-04-25 13:16:11 +00:00
|
|
|
let files_uploaded: &UseRef<Vec<String>> = use_ref(cx, Vec::new);
|
|
|
|
|
|
|
|
cx.render(rsx! {
|
2023-06-06 00:06:27 +00:00
|
|
|
label {
|
|
|
|
input {
|
|
|
|
r#type: "checkbox",
|
|
|
|
checked: "{enable_directory_upload}",
|
|
|
|
oninput: move |evt| {
|
2023-09-01 20:38:55 +00:00
|
|
|
enable_directory_upload.set(evt.value().parse().unwrap());
|
2023-06-06 00:06:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"Enable directory upload"
|
|
|
|
}
|
|
|
|
|
2023-04-25 13:16:11 +00:00
|
|
|
input {
|
|
|
|
r#type: "file",
|
2023-07-10 09:11:56 +00:00
|
|
|
accept: ".txt,.rs",
|
2023-04-25 14:26:56 +00:00
|
|
|
multiple: true,
|
2023-06-06 00:06:27 +00:00
|
|
|
directory: **enable_directory_upload,
|
2023-04-25 13:16:11 +00:00
|
|
|
onchange: |evt| {
|
|
|
|
to_owned![files_uploaded];
|
|
|
|
async move {
|
2023-09-01 20:38:55 +00:00
|
|
|
if let Some(file_engine) = &evt.files() {
|
2023-04-25 13:16:11 +00:00
|
|
|
let files = file_engine.files();
|
2023-06-05 08:47:04 +00:00
|
|
|
for file_name in files {
|
|
|
|
sleep(std::time::Duration::from_secs(1)).await;
|
|
|
|
files_uploaded.write().push(file_name);
|
2023-04-25 13:16:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-06-05 08:47:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
div { "progress: {files_uploaded.read().len()}" },
|
2023-04-25 13:16:11 +00:00
|
|
|
|
|
|
|
ul {
|
|
|
|
for file in files_uploaded.read().iter() {
|
|
|
|
li { "{file}" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|