diff --git a/client-electron/src/pages/recipes/components/recipe-editor-components/recipe-editor.tsx b/client-electron/src/pages/recipes/components/recipe-editor-components/recipe-editor.tsx index b97b1b3..50fff0a 100644 --- a/client-electron/src/pages/recipes/components/recipe-editor-components/recipe-editor.tsx +++ b/client-electron/src/pages/recipes/components/recipe-editor-components/recipe-editor.tsx @@ -36,23 +36,31 @@ export const RecipeEditor: React.FC = ({ const [editorShowState, setEditorShowState] = useState(EditorShowStateEnum.RECIPES_IN_USE) - const { recipesEnable, recipesDisable } = useMemo<{ - recipesEnable: ItemMetadata[] - recipesDisable: ItemMetadata[] - }>(() => { - return { - recipesEnable: recipes.Recipe01.filter(r => r.isUse).map(x => ({ - id: x.productCode, - name: x.name, - lastChange: x.LastChange - })), - recipesDisable: recipes.Recipe01.filter(r => !r.isUse).map(x => ({ - id: x.productCode, - name: x.name, - lastChange: x.LastChange - })) - } - }, [recipes]) + const { recipesEnable, recipesDisable } = useMemo( + () => + recipes.Recipe01.reduce<{ recipesEnable: ItemMetadata[]; recipesDisable: ItemMetadata[] }>( + (acc, curr) => { + if (curr.isUse) { + acc.recipesEnable.push({ + id: curr.productCode, + name: curr.name, + lastChange: curr.LastChange + }) + return acc + } else { + acc.recipesDisable.push({ + id: curr.productCode, + name: curr.name, + lastChange: curr.LastChange + }) + } + + return acc + }, + { recipesEnable: [], recipesDisable: [] } + ), + [recipes.Recipe01] + ) const [currentItems, setCurrentItems] = useState(recipesEnable) @@ -62,10 +70,8 @@ export const RecipeEditor: React.FC = ({ onSelectFn: id => setSelectedRecipe(id.toString()) }) - const { selectedMaterial, setSelectedMaterial, selectedRecipe, setSelectedRecipe } = useRecipeDashboard( + const { selectedRecipe, setSelectedRecipe } = useRecipeDashboard( useShallow(state => ({ - selectedMaterial: state.selectedMaterial, - setSelectedMaterial: state.setSelectedMaterial, selectedRecipe: state.selectedRecipe, setSelectedRecipe: state.setSelectedRecipe })) @@ -90,15 +96,11 @@ export const RecipeEditor: React.FC = ({ id: x.id, name: x.materialName })) - currentSelectId = selectedMaterial - onSelectedFn = id => setSelectedMaterial(Number(id)) } else if (editorShowState === EditorShowStateEnum.TOPPING_GROUPS) { list = recipes.Topping.ToppingGroup.map(x => ({ id: x.groupID, name: x.name })) - currentSelectId = selectedMaterial - onSelectedFn = id => setSelectedMaterial(Number(id)) } else if (editorShowState === EditorShowStateEnum.TOPPING_LIST) { list = recipes.Topping.ToppingList.map(x => ({ id: x.id, diff --git a/client-electron/src/pages/recipes/components/recipe-editor-components/recipe-list.tsx b/client-electron/src/pages/recipes/components/recipe-editor-components/recipe-list.tsx index cf39ac2..1f56c90 100644 --- a/client-electron/src/pages/recipes/components/recipe-editor-components/recipe-list.tsx +++ b/client-electron/src/pages/recipes/components/recipe-editor-components/recipe-list.tsx @@ -13,9 +13,9 @@ const RecipeList: React.FC = ({ items, currentSelectId, onSelec return (
- {items.map(item => ( + {items.map((item, index) => (