fix(items_list): fix new item addition with async handling and stabilization delay
This commit is contained in:
parent
d565563edb
commit
de7c5c62c8
1 changed files with 34 additions and 28 deletions
|
@ -925,9 +925,19 @@ pub fn ItemsList(
|
||||||
).await;
|
).await;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add a new row if this is the last row - in a separate update call
|
// Add a new row if this is the last row
|
||||||
if index == items_len - 1 {
|
if index == items_len - 1 {
|
||||||
// First, create a completely new item
|
// Clone before moving into the async block
|
||||||
|
let set_items_for_new_item = set_items_clone.clone();
|
||||||
|
let current_url_for_async = Rc::clone(¤t_url_clone);
|
||||||
|
let selected_properties_for_async = selected_properties_clone.clone();
|
||||||
|
|
||||||
|
// Use a small delay to ensure clean component lifecycle
|
||||||
|
spawn_local(async move {
|
||||||
|
// Wait for the current update to complete and component to stabilize
|
||||||
|
gloo_timers::future::TimeoutFuture::new(10).await;
|
||||||
|
|
||||||
|
// Create a new item with empty values
|
||||||
let new_item = Item {
|
let new_item = Item {
|
||||||
id: Uuid::new_v4().to_string(),
|
id: Uuid::new_v4().to_string(),
|
||||||
name: String::new(),
|
name: String::new(),
|
||||||
|
@ -938,25 +948,21 @@ pub fn ItemsList(
|
||||||
|
|
||||||
// Clone for database save
|
// Clone for database save
|
||||||
let new_item_clone = new_item.clone();
|
let new_item_clone = new_item.clone();
|
||||||
let current_url_for_new_item = Rc::clone(¤t_url_clone);
|
|
||||||
let selected_properties_for_new_item = selected_properties_clone.clone();
|
|
||||||
|
|
||||||
// Add the new item in a separate update to force re-rendering
|
// Add the new item in a separate update to force re-rendering
|
||||||
set_items_clone.update(|items| {
|
set_items_for_new_item.update(|items| {
|
||||||
items.push(new_item);
|
items.push(new_item);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save the new item to the database in a separate task
|
// Save the new item to the database in a separate task
|
||||||
let current_url_for_task = Rc::clone(¤t_url_for_new_item);
|
|
||||||
let selected_properties_for_task = selected_properties_for_new_item;
|
|
||||||
|
|
||||||
spawn_local(async move {
|
spawn_local(async move {
|
||||||
save_item_to_db(
|
save_item_to_db(
|
||||||
new_item_clone,
|
new_item_clone,
|
||||||
selected_properties_for_task,
|
selected_properties_for_async,
|
||||||
current_url_for_task.to_string()
|
current_url_for_async.to_string()
|
||||||
).await;
|
).await;
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue