Skip to content

Commit 2658ae8

Browse files
authored
fix: use signals rather than Action::new_local() (closes #3746) (#3749)
1 parent 90fc727 commit 2658ae8

File tree

1 file changed

+11
-9
lines changed
  • examples/server_fns_axum/src

1 file changed

+11
-9
lines changed

examples/server_fns_axum/src/app.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,8 @@ pub fn FileUpload() -> impl IntoView {
363363
Ok(count)
364364
}
365365

366-
let upload_action = Action::new_local(|data: &FormData| {
367-
// `MultipartData` implements `From<FormData>`
368-
file_length(data.clone().into())
369-
});
366+
let pending = RwSignal::new(false);
367+
let result = RwSignal::new(None);
370368

371369
view! {
372370
<h3>File Upload</h3>
@@ -375,22 +373,26 @@ pub fn FileUpload() -> impl IntoView {
375373
ev.prevent_default();
376374
let target = ev.target().unwrap().unchecked_into::<HtmlFormElement>();
377375
let form_data = FormData::new_with_form(&target).unwrap();
378-
upload_action.dispatch_local(form_data);
376+
pending.set(true);
377+
spawn_local(async move {
378+
result.set(Some(file_length(form_data.into()).await));
379+
pending.set(false);
380+
});
379381
}>
380382
<input type="file" name="file_to_upload"/>
381383
<input type="submit"/>
382384
</form>
383385
<p>
384386
{move || {
385-
if upload_action.input_local().read().is_none() && upload_action.value().read().is_none()
387+
if !pending.get() && result.read().is_none()
386388
{
387389
"Upload a file.".to_string()
388-
} else if upload_action.pending().get() {
390+
} else if pending.get() {
389391
"Uploading...".to_string()
390-
} else if let Some(Ok(value)) = upload_action.value().get() {
392+
} else if let Some(Ok(value)) = result.get() {
391393
value.to_string()
392394
} else {
393-
format!("{:?}", upload_action.value().get())
395+
format!("{:?}", result.get())
394396
}
395397
}}
396398

0 commit comments

Comments
 (0)