diff --git a/package-lock.json b/package-lock.json index 0498d3e2..0ddfd55e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -63,6 +63,7 @@ "typeface-francois-one": "0.0.71", "typeface-public-sans": "^1.1.4", "url": "^0.11.0", + "usehooks-ts": "^3.1.0", "uuid": "^3.4.0", "zlib": "npm:browserify-zlib@^0.2.0" }, @@ -30759,6 +30760,21 @@ "node": ">=0.10.0" } }, + "node_modules/usehooks-ts": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/usehooks-ts/-/usehooks-ts-3.1.0.tgz", + "integrity": "sha512-bBIa7yUyPhE1BCc0GmR96VU/15l/9gP1Ch5mYdLcFBaFGQsdmXkvjV0TtOqW1yUd6VjIwDunm+flSciCQXujiw==", + "license": "MIT", + "dependencies": { + "lodash.debounce": "^4.0.8" + }, + "engines": { + "node": ">=16.15.0" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17 || ^18" + } + }, "node_modules/utf-8-validate": { "version": "5.0.10", "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.10.tgz", @@ -56138,6 +56154,14 @@ "integrity": "sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==", "dev": true }, + "usehooks-ts": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/usehooks-ts/-/usehooks-ts-3.1.0.tgz", + "integrity": "sha512-bBIa7yUyPhE1BCc0GmR96VU/15l/9gP1Ch5mYdLcFBaFGQsdmXkvjV0TtOqW1yUd6VjIwDunm+flSciCQXujiw==", + "requires": { + "lodash.debounce": "^4.0.8" + } + }, "utf-8-validate": { "version": "5.0.10", "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.10.tgz", diff --git a/package.json b/package.json index b0cc5ce7..bf9a3448 100644 --- a/package.json +++ b/package.json @@ -147,6 +147,7 @@ "typeface-francois-one": "0.0.71", "typeface-public-sans": "^1.1.4", "url": "^0.11.0", + "usehooks-ts": "^3.1.0", "uuid": "^3.4.0", "zlib": "npm:browserify-zlib@^0.2.0" }, diff --git a/src/components/Cellar/CellarInventoryTabPanel.js b/src/components/Cellar/CellarInventoryTabPanel.js index 999bb050..b14c86f3 100644 --- a/src/components/Cellar/CellarInventoryTabPanel.js +++ b/src/components/Cellar/CellarInventoryTabPanel.js @@ -1,11 +1,12 @@ /** @typedef {import("../../index").farmhand.keg} keg */ -import React, { useContext } from 'react' +import React, { useContext, useState } from 'react' import { number } from 'prop-types' import Divider from '@mui/material/Divider/index.js' import Card from '@mui/material/Card/index.js' import CardContent from '@mui/material/CardContent/index.js' import ReactMarkdown from 'react-markdown' +import SearchBar from '../SearchBar/index.js' import FarmhandContext from '../Farmhand/Farmhand.context.js' import { KEG_INTEREST_RATE, @@ -15,6 +16,8 @@ import { } from '../../constants.js' import { integerString } from '../../utils/index.js' +import { itemsMap } from '../../data/maps.js' +import { FERMENTED_CROP_NAME } from '../../templates.js' import { TabPanel } from './TabPanel/index.js' import { Keg } from './Keg.js' @@ -25,6 +28,8 @@ import { Keg } from './Keg.js' * @param {number} props.currentTab */ export const CellarInventoryTabPanel = ({ index, currentTab }) => { + const [searchQuery, setSearchQuery] = useState('') + /** * @type {{ * gameState: { @@ -37,14 +42,32 @@ export const CellarInventoryTabPanel = ({ index, currentTab }) => { gameState: { cellarInventory, purchasedCellar }, } = useContext(FarmhandContext) + const searchTerms = searchQuery + .toLowerCase() + .split(' ') + .filter(term => term.length > 0) + + const filteredKegs = cellarInventory.filter(keg => { + const item = itemsMap[keg.itemId] + const itemName = item.name.toLowerCase() + const fermentationRecipeName = `${FERMENTED_CROP_NAME}${itemName}` + + return searchTerms.every( + term => fermentationRecipeName.includes(term) || itemName.includes(term) + ) + }) + return (

Capacity: {integerString(cellarInventory.length)} /{' '} {integerString(PURCHASEABLE_CELLARS.get(purchasedCellar).space)}

+ {cellarInventory.length > 0 && ( + + )} + )} + + + ) + })()}
+ {cowShopInventory.length > 0 && ( + + )}