add file property to drag data

This commit is contained in:
Evan Almloff committed 2023-04-27 10:21:05 -05:00
1 parent c904411190
commit ada246c12e
11 files changed
+133 -77

No files matched your search

+25 -2
View File
@@ -2,10 +2,10 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(App);
dioxus_desktop::launch(app);
}
fn App(cx: Scope) -> Element {
fn app(cx: Scope) -> Element {
let files_uploaded: &UseRef<Vec<String>> = use_ref(cx, Vec::new);
cx.render(rsx! {
@@ -27,6 +27,29 @@ fn App(cx: Scope) -> Element {
}
},
}
div {
width: "100px",
height: "100px",
border: "1px solid black",
prevent_default: "ondrop dragover dragenter",
ondrop: move |evt| {
to_owned![files_uploaded];
async move {
if let Some(file_engine) = &evt.files {
let files = file_engine.files();
for file_name in &files {
if let Some(file) = file_engine.read_file_to_string(file_name).await{
files_uploaded.write().push(file);
}
}
}
}
},
ondragover: move |event: DragEvent| {
event.stop_propagation();
},
"Drop files here"
}
ul {
for file in files_uploaded.read().iter() {