fix: problems with prop dropping
This commit is contained in:
parent
845d64c981
commit
a96581cbf0
4 changed files with 115 additions and 50 deletions
|
|
@ -281,13 +281,9 @@ async fn handle_socket(
|
|||
}
|
||||
|
||||
// Drop the setup connection - we'll use recv_conn for the receive task
|
||||
// and pool for cleanup (which will use the same RLS context issue, but leave_channel
|
||||
// needs user_id match anyway)
|
||||
// and pool for cleanup (leave_channel needs user_id match anyway)
|
||||
drop(conn);
|
||||
|
||||
// Clone pool for use in the receive task (needed for multi-query operations)
|
||||
let recv_pool = pool.clone();
|
||||
|
||||
// Spawn task to handle incoming messages from client
|
||||
let recv_task = tokio::spawn(async move {
|
||||
while let Some(Ok(msg)) = receiver.next().await {
|
||||
|
|
@ -404,7 +400,7 @@ async fn handle_socket(
|
|||
let pos_y = member.position_y + offset_y;
|
||||
|
||||
match loose_props::drop_prop_to_canvas(
|
||||
&recv_pool,
|
||||
&mut *recv_conn,
|
||||
inventory_item_id,
|
||||
user_id,
|
||||
channel_id,
|
||||
|
|
@ -426,6 +422,16 @@ async fn handle_socket(
|
|||
}
|
||||
Err(e) => {
|
||||
tracing::error!("[WS] Drop prop failed: {:?}", e);
|
||||
let (code, message) = match &e {
|
||||
chattyness_error::AppError::Forbidden(msg) => {
|
||||
("PROP_NOT_DROPPABLE".to_string(), msg.clone())
|
||||
}
|
||||
chattyness_error::AppError::NotFound(msg) => {
|
||||
("PROP_NOT_FOUND".to_string(), msg.clone())
|
||||
}
|
||||
_ => ("DROP_FAILED".to_string(), format!("{:?}", e)),
|
||||
};
|
||||
let _ = tx.send(ServerMessage::Error { code, message });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -453,6 +459,10 @@ async fn handle_socket(
|
|||
}
|
||||
Err(e) => {
|
||||
tracing::error!("[WS] Pick up prop failed: {:?}", e);
|
||||
let _ = tx.send(ServerMessage::Error {
|
||||
code: "PICKUP_FAILED".to_string(),
|
||||
message: format!("{:?}", e),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -251,6 +251,7 @@ pub fn InventoryPopup(
|
|||
let item = items.get().into_iter().find(|i| i.id == item_id)?;
|
||||
let handle_drop = handle_drop.clone();
|
||||
let is_dropping = dropping.get();
|
||||
let is_droppable = item.is_droppable;
|
||||
|
||||
Some(view! {
|
||||
<div class="mt-4 pt-4 border-t border-gray-700">
|
||||
|
|
@ -260,15 +261,25 @@ pub fn InventoryPopup(
|
|||
<p class="text-gray-400 text-sm">
|
||||
{if item.is_transferable { "Transferable" } else { "Not transferable" }}
|
||||
{if item.is_portable { " \u{2022} Portable" } else { "" }}
|
||||
{if is_droppable { " \u{2022} Droppable" } else { " \u{2022} Essential" }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
// Drop button
|
||||
// Drop button - disabled for non-droppable (essential) props
|
||||
<button
|
||||
type="button"
|
||||
class="px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg transition-colors disabled:opacity-50"
|
||||
on:click=move |_| handle_drop(item_id)
|
||||
disabled=is_dropping
|
||||
class=if is_droppable {
|
||||
"px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg transition-colors disabled:opacity-50"
|
||||
} else {
|
||||
"px-4 py-2 bg-gray-600 text-gray-400 rounded-lg cursor-not-allowed"
|
||||
}
|
||||
on:click=move |_| {
|
||||
if is_droppable {
|
||||
handle_drop(item_id);
|
||||
}
|
||||
}
|
||||
disabled=is_dropping || !is_droppable
|
||||
title=if is_droppable { "" } else { "Essential prop cannot be dropped" }
|
||||
>
|
||||
{if is_dropping { "Dropping..." } else { "Drop" }}
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ fn handle_server_message(
|
|||
// Heartbeat acknowledged - nothing to do
|
||||
}
|
||||
ServerMessage::Error { code, message } => {
|
||||
#[cfg(debug_assertions)]
|
||||
// Always log errors to console (not just debug mode)
|
||||
web_sys::console::error_1(&format!("[WS] Server error: {} - {}", code, message).into());
|
||||
}
|
||||
ServerMessage::ChatMessageReceived {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue