Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix HasFileData for WebDragData #1917

Merged
merged 2 commits into from
Feb 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 9 additions & 14 deletions packages/web/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use dioxus_html::{
};
use js_sys::Array;
use wasm_bindgen::{prelude::wasm_bindgen, JsCast, JsValue};
use web_sys::{Document, Element, Event, MouseEvent};
use web_sys::{Document, DragEvent, Element, Event, MouseEvent};

pub(crate) struct WebEventConverter;

Expand Down Expand Up @@ -49,10 +49,7 @@ impl HtmlEventConverter for WebEventConverter {
#[inline(always)]
fn convert_drag_data(&self, event: &dioxus_html::PlatformEventData) -> dioxus_html::DragData {
let event = downcast_event(event);
DragData::new(WebDragData::new(
event.element.clone(),
event.raw.clone().unchecked_into(),
))
DragData::new(WebDragData::new(event.raw.clone().unchecked_into()))
}

#[inline(always)]
Expand Down Expand Up @@ -462,13 +459,12 @@ impl HasFileData for WebFormData {
}

struct WebDragData {
element: Element,
raw: MouseEvent,
}

impl WebDragData {
fn new(element: Element, raw: MouseEvent) -> Self {
Self { element, raw }
fn new(raw: MouseEvent) -> Self {
Self { raw }
}
}

Expand Down Expand Up @@ -529,17 +525,16 @@ impl HasFileData for WebDragData {
#[cfg(not(feature = "file_engine"))]
let files = None;
#[cfg(feature = "file_engine")]
let files = self
.element
.dyn_ref()
.and_then(|input: &web_sys::HtmlInputElement| {
input.files().and_then(|files| {
let files = self.raw.dyn_ref::<DragEvent>().and_then(|drag_event| {
drag_event.data_transfer().and_then(|dt| {
dt.files().and_then(|files| {
#[allow(clippy::arc_with_non_send_sync)]
crate::file_engine::WebFileEngine::new(files).map(|f| {
std::sync::Arc::new(f) as std::sync::Arc<dyn dioxus_html::FileEngine>
})
})
});
})
});

files
}
Expand Down