import { flow } from 'common/fp'; import { filter, sortBy } from 'common/collections'; import { useBackend, useSharedState } from '../backend'; import { Box, Button, Flex, Input, Section, Dropdown } from '../components'; import { Window } from '../layouts'; import { Materials } from './ExosuitFabricator'; import { createSearch, toTitleCase } from 'common/string'; const canBeMade = (recipe, materials, mult = 1) => { if (recipe.requirements === null) { return true; } let recipeRequiredMaterials = Object.keys(recipe.requirements); for (let mat_id of recipeRequiredMaterials) { let material = materials.find((val) => val.name === mat_id); if (!material) { continue; // yes, if we cannot find the material, we just ignore it :V } if (material.amount < recipe.requirements[mat_id] * mult) { return false; } } return true; }; export const Autolathe = (props, context) => { const { act, data } = useBackend(context); const { recipes, busy, materials, categories } = data; const [category, setCategory] = useSharedState(context, 'category', 0); const [searchText, setSearchText] = useSharedState(context, 'search_text', ''); const testSearch = createSearch(searchText, (recipe) => recipe.name); const recipesToShow = flow([ filter((recipe) => recipe.category === categories[category]), searchText && filter(testSearch), sortBy((recipe) => recipe.name.toLowerCase()), ])(recipes); return (
setCategory(categories.indexOf(val))} /> }> setSearchText(v)} mb={1} /> {recipesToShow.map((recipe) => ( {(!recipe.is_stack && ( )) || null} {(recipe.requirements && Object.keys(recipe.requirements) .map((mat) => toTitleCase(mat) + ': ' + recipe.requirements[mat]) .join(', ')) || No resources required.} ))}
); };