import { useBackend, useLocalState } from '../backend'; import { Button, Dimmer, Flex, Icon, LabeledList, Section, Tabs } from '../components'; import { Window } from '../layouts'; export const PersonalCrafting = (props, context) => { const { act, data } = useBackend(context); const { busy, display_craftable_only, display_compact } = data; const crafting_recipes = data.crafting_recipes || {}; // Sort everything into flat categories const categories = []; const recipes = []; for (let category of Object.keys(crafting_recipes)) { const subcategories = crafting_recipes[category]; if ('has_subcats' in subcategories) { for (let subcategory of Object.keys(subcategories)) { if (subcategory === 'has_subcats') { continue; } // Push category categories.push({ name: subcategory, category, subcategory, }); // Push recipes const _recipes = subcategories[subcategory]; for (let recipe of _recipes) { recipes.push({ ...recipe, category: subcategory, }); } } continue; } // Push category categories.push({ name: category, category, }); // Push recipes const _recipes = crafting_recipes[category]; for (let recipe of _recipes) { recipes.push({ ...recipe, category, }); } } // Sort out the tab state const [tab, setTab] = useLocalState(context, 'tab', categories[0]?.name); const shownRecipes = recipes.filter((recipe) => recipe.category === tab); return ( {!!busy && ( {' Crafting...'} )}
act('toggle_compact')} /> act('toggle_recipes')} /> }> {categories.map((category) => ( { setTab(category.name); act('set_category', { category: category.category, subcategory: category.subcategory, }); }}> {category.name} ))}
); }; const CraftingList = (props, context) => { const { craftables = [] } = props; const { act, data } = useBackend(context); const { craftability = {}, display_compact, display_craftable_only } = data; return craftables.map((craftable) => { if (display_craftable_only && !craftability[craftable.ref]) { return null; } // Compact display if (display_compact) { return ( act('make', { recipe: craftable.ref, }) } /> }> {craftable.req_text} ); } // Full display return (
act('make', { recipe: craftable.ref, }) } /> }> {!!craftable.req_text && {craftable.req_text}} {!!craftable.catalyst_text && {craftable.catalyst_text}} {!!craftable.tool_text && {craftable.tool_text}}
); }); };