Attempt to fix #196 - sticky selector
This commit is contained in:
parent
54eba32bb4
commit
4a6045a3e4
4 changed files with 12 additions and 3 deletions
|
@ -42,7 +42,9 @@ const useItems = () => {
|
|||
(items) => {
|
||||
setItemMap(
|
||||
items.reduce((acc, item) => {
|
||||
acc[item.id] = item;
|
||||
if (item && item.id) {
|
||||
acc[item.id] = item;
|
||||
}
|
||||
return acc;
|
||||
}, {})
|
||||
);
|
||||
|
|
|
@ -34,6 +34,11 @@ const findSelected = (itemMap, rect) => {
|
|||
.filter((elem) => {
|
||||
const { clientHeight, clientWidth, id } = elem;
|
||||
const item = itemMap[id];
|
||||
if (!item) {
|
||||
// Avoid to find item that are not yet removed from DOM
|
||||
console.error(`Missing item ${id}`);
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
!item.locked &&
|
||||
isPointInsideRect({ x: item.x, y: item.y }, rect) &&
|
||||
|
|
|
@ -23,7 +23,9 @@ export const AllItemsSelector = selector({
|
|||
key: "AllItemsSelector",
|
||||
get: ({ get }) => {
|
||||
const itemMap = get(ItemMapAtom);
|
||||
return get(ItemListAtom).map((id) => itemMap[id]);
|
||||
return get(ItemListAtom)
|
||||
.map((id) => itemMap[id])
|
||||
.filter((item) => item); // This filter clean the selection of missing items
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ export const GameProvider = ({ gameId, game, children }) => {
|
|||
newGame.availableItems.map((item) => ({ ...item, id: nanoid() }))
|
||||
);
|
||||
}
|
||||
setItemList(newGame.items);
|
||||
setItemList(newGame.items.filter((item) => item)); // The filter avoid the empty item bug on reload
|
||||
setBoardConfig(newGame.board, false);
|
||||
setGameLoaded(true);
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue