diff --git a/src/components/Farmhand/Farmhand.context.js b/src/components/Farmhand/Farmhand.context.js index f177b1d2f..b44d01739 100644 --- a/src/components/Farmhand/Farmhand.context.js +++ b/src/components/Farmhand/Farmhand.context.js @@ -8,19 +8,19 @@ import { createContext } from 'react' /** * @type {import('react').Context<{ * gameState: farmhand.state & { - * blockInput: boolean, - * features: Record, - * fieldToolInventory: farmhand.item[], - * isChatAvailable: boolean, - * levelEntitlements: farmhand.levelEntitlements, - * plantableCropInventory: farmhand.item[], - * playerInventory: farmhand.item[], - * playerInventoryQuantities: Record, - * shopInventory: farmhand.item[], - * viewList: string[], - * viewTitle: string, + * blockInput: boolean, + * features: Record, + * fieldToolInventory: farmhand.item[], + * isChatAvailable: boolean, + * levelEntitlements: farmhand.levelEntitlements, + * plantableCropInventory: farmhand.item[], + * playerInventory: farmhand.item[], + * playerInventoryQuantities: Record, + * shopInventory: farmhand.item[], + * viewList: string[], + * viewTitle: string, * } - * handlers: {} + * handlers: Record void> * }>} */ // @ts-expect-error diff --git a/src/components/FermentationRecipeList/FermentationRecipe.js b/src/components/FermentationRecipeList/FermentationRecipe.js index 0d7cc319b..e441ab0aa 100644 --- a/src/components/FermentationRecipeList/FermentationRecipe.js +++ b/src/components/FermentationRecipeList/FermentationRecipe.js @@ -46,21 +46,11 @@ const getRecipesInstancesInCellar = memoize( * @param {item} props.item */ export const FermentationRecipe = ({ item }) => { - /** - * @type {{ - * gameState: { - * inventory: Array., - * cellarInventory: Array., - * purchasedCellar: number - * }, - * handlers: { - * handleMakeFermentationRecipeClick: function(item, number) - * } - * }} - */ const { gameState: { inventory, cellarInventory, purchasedCellar }, - handlers: { handleMakeFermentationRecipeClick }, + handlers: { + /** @type {function(item, number)} */ handleMakeFermentationRecipeClick, + }, } = useContext(FarmhandContext) const [quantity, setQuantity] = useState(1) diff --git a/src/components/WineRecipeList/WineRecipe.js b/src/components/WineRecipeList/WineRecipe.js index 531f49dc5..8a901dfef 100644 --- a/src/components/WineRecipeList/WineRecipe.js +++ b/src/components/WineRecipeList/WineRecipe.js @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useContext } from 'react' import { oneOf } from 'prop-types' import Card from '@mui/material/Card' import CardHeader from '@mui/material/CardHeader' @@ -13,6 +13,8 @@ import { wineService } from '../../services/wine' import { grapeVariety } from '../../enums' import { wines } from '../../img' import { integerString } from '../../utils' +import { getInventoryQuantityMap } from '../../utils/getInventoryQuantityMap' +import FarmhandContext from '../Farmhand/Farmhand.context' /** * @param {{ @@ -20,9 +22,14 @@ import { integerString } from '../../utils' * }} props */ export const WineRecipe = ({ wineVariety }) => { + const { + gameState: { inventory }, + } = useContext(FarmhandContext) const wineName = grapeVarietyNameMap[wineVariety] const grape = grapeVarietyVarietyGrapeMap[wineVariety] + const inventoryQuantityMap = getInventoryQuantityMap(inventory) + return ( { {integerString(wineService.getDaysToMature(wineVariety))}

- Ingredients:{' '} + Required:{' '} {integerString(wineService.getGrapesRequiredForWine(wineVariety))}{' '} - x {grape.name} + x {grape.name} (available:{' '} + {integerString(inventoryQuantityMap[grape.id])})

{ - // FIXME: Show number of required grapes in inventory // FIXME: Show amount in cellar } diff --git a/src/utils/getInventoryQuantityMap.js b/src/utils/getInventoryQuantityMap.js index 667bf1682..ec0d810dd 100644 --- a/src/utils/getInventoryQuantityMap.js +++ b/src/utils/getInventoryQuantityMap.js @@ -3,18 +3,15 @@ */ import { memoize } from './memoize' -/** - * @param {item[]} inventory - * @returns {Object} - */ export const getInventoryQuantityMap = memoize( /** - * @param {item[]} inventory - * @returns {Object} + * @param {{ id: item['id'], quantity: number }[]} inventory + * @returns {Record} */ inventory => inventory.reduce((acc, { id, quantity }) => { acc[id] = quantity + return acc }, {}) )