fix: external bag race condition

This commit is contained in:
cha0s 2024-09-21 20:36:03 -05:00
parent 9d176c2930
commit 5492ec32bd
2 changed files with 12 additions and 7 deletions

View File

@ -1,3 +1,5 @@
import {memo} from 'react';
import styles from './external.module.css';
import Grid from './grid.jsx';
@ -5,7 +7,7 @@ import Grid from './grid.jsx';
/**
* External inventory.
*/
export default function External({
function External({
isInventoryOpen,
onActivate,
slots,
@ -25,3 +27,5 @@ export default function External({
</div>
);
}
export default memo(External);

View File

@ -383,6 +383,12 @@ function Ui({disconnected}) {
payload: {type: 'swapSlots', value: [0, mainEntityRef.current, i + 11]},
});
}, [client, mainEntityRef]);
const externalInventoryOnActivate = useCallback((i) => {
client.send({
type: 'Action',
payload: {type: 'swapSlots', value: [0, externalInventory, i]},
});
}, [client, externalInventory]);
return (
<div
className={styles.ui}
@ -508,12 +514,7 @@ function Ui({disconnected}) {
{externalInventory && (
<External
isInventoryOpen={isInventoryOpen}
onActivate={(i) => {
client.send({
type: 'Action',
payload: {type: 'swapSlots', value: [0, externalInventory, i]},
});
}}
onActivate={externalInventoryOnActivate}
slots={externalInventorySlots}
/>
)}