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

View File

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