add support for unwearing items!
This commit is contained in:
parent
a9d50bd0c3
commit
f49c2552ce
2 changed files with 20 additions and 5 deletions
|
@ -40,7 +40,12 @@ function Item({ item, isWorn, dispatchToOutfit }) {
|
||||||
d="flex"
|
d="flex"
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
cursor="pointer"
|
cursor="pointer"
|
||||||
onClick={() => dispatchToOutfit({ type: "wearItem", itemId: item.id })}
|
onClick={() =>
|
||||||
|
dispatchToOutfit({
|
||||||
|
type: isWorn ? "unwearItem" : "wearItem",
|
||||||
|
itemId: item.id,
|
||||||
|
})
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<ItemThumbnail src={item.thumbnailUrl} isWorn={isWorn} />
|
<ItemThumbnail src={item.thumbnailUrl} isWorn={isWorn} />
|
||||||
<Box width="3" />
|
<Box width="3" />
|
||||||
|
|
|
@ -63,12 +63,12 @@ const outfitStateReducer = (apolloClient) => (baseState, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case "wearItem":
|
case "wearItem":
|
||||||
return produce(baseState, (state) => {
|
return produce(baseState, (state) => {
|
||||||
|
// A hack to work around https://github.com/immerjs/immer/issues/586
|
||||||
|
state.wornItemIds.add("fake-id-immer#586").delete("fake-id-immer#586");
|
||||||
|
|
||||||
const { wornItemIds, closetedItemIds } = state;
|
const { wornItemIds, closetedItemIds } = state;
|
||||||
const { itemId } = action;
|
const { itemId } = action;
|
||||||
|
|
||||||
// Move the item out of the closet.
|
|
||||||
closetedItemIds.delete(itemId);
|
|
||||||
|
|
||||||
// Move conflicting items to the closet.
|
// Move conflicting items to the closet.
|
||||||
//
|
//
|
||||||
// We do this by looking them up in the Apollo Cache, which is going to
|
// We do this by looking them up in the Apollo Cache, which is going to
|
||||||
|
@ -87,9 +87,19 @@ const outfitStateReducer = (apolloClient) => (baseState, action) => {
|
||||||
closetedItemIds.add(conflictingId);
|
closetedItemIds.add(conflictingId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add this item to the worn set.
|
// Move this item from the closet to the worn set.
|
||||||
|
closetedItemIds.delete(itemId);
|
||||||
wornItemIds.add(itemId);
|
wornItemIds.add(itemId);
|
||||||
});
|
});
|
||||||
|
case "unwearItem":
|
||||||
|
return produce(baseState, (state) => {
|
||||||
|
const { wornItemIds, closetedItemIds } = state;
|
||||||
|
const { itemId } = action;
|
||||||
|
|
||||||
|
// Move this item from the worn set to the closet.
|
||||||
|
wornItemIds.delete(itemId);
|
||||||
|
closetedItemIds.add(itemId);
|
||||||
|
});
|
||||||
default:
|
default:
|
||||||
throw new Error(`unexpected action ${action}`);
|
throw new Error(`unexpected action ${action}`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue