import {FC, useMemo} from "react"; import {FactorySelect} from "./FactorySelect"; import {useDetails} from "../src/hooks/useDetails"; import {Entity, Group} from "../src/types"; import styles from "./Group.module.css" import {EntitySpan} from "./EntitySpan"; interface Props { onRemove: () => void onSetOutputFactories: (uids: string[]) => void onSetIntermediateFactories: (uids: string[]) => void onSetInputFactories: (uids: string[]) => void onToggleExported: () => void onRename: (name: string) => void onDoIgnore: (name: string) => void group: Group sets: { doNotSuggest: Set basic: Set exported: Set } } export const GroupBox: FC = ({ onRemove, onRename, onSetOutputFactories, onSetIntermediateFactories, onSetInputFactories, onToggleExported, group: { inputs, intermediates, factories, isExported, name }, sets: { doNotSuggest, basic, exported }, onDoIgnore }) => { const details = useDetails() const calculatedInputs = useMemo(() => { const newData: string[] = details .filter(detail => intermediates.includes(detail.href) || factories.includes(detail.href)) .flatMap(detail => Object.keys(detail.recipe?.prerequisites ?? {})) const uniqueInputs = Array.from(new Set(newData)) return uniqueInputs .filter(input => !intermediates.includes(input) && !factories.includes(input)) }, [details, intermediates, factories]) const suggestions = useMemo(() => { const availableIngredients = Array.from(new Set([...intermediates, ...factories, ...calculatedInputs, ...inputs])) const selectedValues = Array.from(new Set([...intermediates, ...factories, ...inputs])) return details .filter(detail => { if (!detail.recipe) return false if (selectedValues.includes(detail.href)) return false if (doNotSuggest.has(detail.href)) return false const prerequisites = Object.keys(detail.recipe?.prerequisites ?? {}) return prerequisites.every(pre => availableIngredients.includes(pre)) }) }, [inputs, doNotSuggest, details, calculatedInputs, intermediates, factories]) const addIntermediateFactory = (uid: string) => { onSetIntermediateFactories([...intermediates, uid]) } const addOutputFactory = (uid: string) => { onSetOutputFactories([...factories, uid]) } return

{ event.currentTarget.innerText = event.currentTarget.innerText.trim() onRename(event.currentTarget.innerText); }} > {name}

Inputs

    { calculatedInputs.map(input =>
  • addIntermediateFactory(input)} style={{color: basic.has(input) ? 'darkgreen' : exported.has(input) ? 'orange' : undefined}} leftClickText={"Add to intermediate factories"} />
  • ) }

Suggestions

    {suggestions.map(suggestion =>
  • addOutputFactory(suggestion.href)} onContextMenu={event => { event.preventDefault() onDoIgnore(suggestion.href) }} leftClickText={"Add to output factories"} rightClickText={"Exclude this recipe from suggestions"} />
  • )}
}