Browse Source

Fix sample data. Update units equivalences

Tatiana Inama 7 years atrás
parent
commit
ad334b0025

+ 9 - 2
recipes/src/components/RecipeForm/index.tsx

@@ -4,6 +4,7 @@ import Recipe, { Ingredient, SubRecipe } from 'src/types/recipes';
 import { Grid, Row, Cell } from '@material/react-layout-grid';
 import './styles.scss';
 import sample_image from 'sample.png';
+import { GetMeasure, MeasuresTypes } from 'services/measurements';
 
 type IngredientsListProps = {
   ingredients: SubRecipe[],
@@ -63,11 +64,17 @@ const SubrecipeForm = ({form, remove, push}: any) => {
                 <Field name={`ingredients[${selectedTab}].ingredients[${index}].name`} />
                 <Field name={`ingredients[${selectedTab}].ingredients[${index}].quantity`}/>
                 <Field component='select' name={`ingredients[${selectedTab}].ingredients[${index}].unit`}>
-                  <option value='gr'>gr</option>
+                  {
+                    MeasuresTypes().map((measure, i) => (
+                      <option key={i} value={measure}>{measure}</option>    
+                    ))
+                  }
+                  <option value=''></option>
+                  {/* <option value='gr'>gr</option>
                   <option value='cup'>cup</option>
                   <option value='ml'>ml</option>
                   <option value='tablespoon'>tbsp</option>
-                  <option value='teaspoon'>tsp</option>
+                  <option value='teaspoon'>tsp</option> */}
                 </Field>
                 <Field name={`ingredients[${selectedTab}].ingredients[${index}].notes`} />
                 <Field name={`ingredients[${selectedTab}].ingredients[${index}]._original`}/>

+ 247 - 218
recipes/src/containers/Recipes/Create/index.tsx

@@ -32,241 +32,270 @@ class CreateRecipe extends React.Component<CreateRecipeProps, CreateRecipeState>
       ..._recipe,
       form: {
         ..._recipe,
-        ingredients: [
+        "ingredients": [
           {
-            "name": "For the Chicken:",
-            "ingredients": [
-              {
-                "name": "thin boneless skinless chicken breast",
-                "quantity": 1.5,
-                "unit": "pound",
-                "_original": "1-1/2 lb of Thin Boneless Skinless Chicken Breast",
-                "suggestions": []
-              },
-              {
-                "name": "olive oil",
-                "quantity": 2,
-                "unit": "tablespoon",
-                "_original": "2 Tbsp of Olive Oil",
-                "suggestions": []
-              },
-              {
-                "name": "juice of  lime",
-                "quantity": 1,
-                "unit": "",
-                "_original": "Juice of 1 Lime",
-                "suggestions": []
-              },
-              {
-                "name": "chili powder",
-                "quantity": 0.5,
-                "unit": "teaspoon",
-                "_original": "1/2 tsp of Chili Powder",
-                "suggestions": [
+              "name": "For the Chicken:",
+              "ingredients": [
                   {
-                    "_id": "5cf1397d72cd194524435041",
-                    "name": "cocoa powder",
-                    "variants": [
-                      "cocoa"
-                    ],
-                    "equivalence": 118,
-                    "referenceUnit": "cup",
-                    "prefferedUnit": "gr",
-                    "measure": 2
+                      "name": "thin boneless skinless chicken breast",
+                      "quantity": 1.5,
+                      "unit": "lb",
+                      "_original": "1-1/2 lb of Thin Boneless Skinless Chicken Breast",
+                      "suggestions": [
+                          {
+                              "_id": "5d1659a3dae0822ea455db18",
+                              "name": "chicken breast",
+                              "variants": [
+                                  "chicken",
+                                  "skinless chicken"
+                              ],
+                              "referenceUnit": "lb",
+                              "prefferedUnit": "g",
+                              "measure": 0
+                          }
+                      ]
                   },
                   {
-                    "_id": "5cf1397d72cd19452443503c",
-                    "name": "icing sugar",
-                    "variants": [
-                      "confectioner sugar",
-                      "powdered sugar"
-                    ],
-                    "equivalence": 125,
-                    "referenceUnit": "cup",
-                    "prefferedUnit": "gr",
-                    "measure": 2
-                  }
-                ]
-              },
-              {
-                "name": "oregano",
-                "quantity": 0.5,
-                "unit": "teaspoon",
-                "_original": "1/2 tsp of Oregano",
-                "suggestions": []
-              },
-              {
-                "name": "cumin",
-                "quantity": 0.5,
-                "unit": "teaspoon",
-                "_original": "1/2 tsp of Cumin",
-                "suggestions": []
-              },
-              {
-                "name": "paprika",
-                "quantity": 0.5,
-                "unit": "teaspoon",
-                "_original": "1/2 tsp of Paprika",
-                "suggestions": []
-              },
-              {
-                "name": "granulated garlic",
-                "quantity": 0.5,
-                "unit": "teaspoon",
-                "_original": "1/2 tsp of Granulated Garlic",
-                "suggestions": [
+                      "name": "olive oil",
+                      "quantity": 2,
+                      "unit": "tbsp",
+                      "_original": "2 Tbsp of Olive Oil",
+                      "suggestions": [
+                          {
+                              "_id": "5d1659a3dae0822ea455db19",
+                              "name": "olive oil",
+                              "variants": [],
+                              "referenceUnit": "tbsp",
+                              "prefferedUnit": "tbsp",
+                              "measure": 1
+                          }
+                      ]
+                  },
+                  {
+                      "name": "juice of  lime",
+                      "quantity": 1,
+                      "unit": "",
+                      "_original": "Juice of 1 Lime",
+                      "suggestions": []
+                  },
+                  {
+                      "name": "chili powder",
+                      "quantity": 0.5,
+                      "unit": "tsp",
+                      "_original": "1/2 tsp of Chili Powder",
+                      "suggestions": [
+                          {
+                              "_id": "5d1659a3dae0822ea455db17",
+                              "name": "cocoa powder",
+                              "variants": [
+                                  "cocoa"
+                              ],
+                              "equivalence": 118,
+                              "referenceUnit": "cup",
+                              "prefferedUnit": "g",
+                              "measure": 2
+                          },
+                          {
+                              "_id": "5d1659a3dae0822ea455db12",
+                              "name": "icing sugar",
+                              "variants": [
+                                  "confectioner sugar",
+                                  "powdered sugar"
+                              ],
+                              "equivalence": 125,
+                              "referenceUnit": "cup",
+                              "prefferedUnit": "g",
+                              "measure": 2
+                          }
+                      ]
+                  },
                   {
-                    "_id": "5cf1397d72cd19452443503b",
-                    "name": "granulated sugar",
-                    "variants": [
-                      "sugar",
-                      "plain sugar"
-                    ],
-                    "equivalence": 200,
-                    "referenceUnit": "cup",
-                    "prefferedUnit": "gr",
-                    "measure": 2
+                      "name": "oregano",
+                      "quantity": 0.5,
+                      "unit": "tsp",
+                      "_original": "1/2 tsp of Oregano",
+                      "suggestions": []
+                  },
+                  {
+                      "name": "cumin",
+                      "quantity": 0.5,
+                      "unit": "tsp",
+                      "_original": "1/2 tsp of Cumin",
+                      "suggestions": []
+                  },
+                  {
+                      "name": "paprika",
+                      "quantity": 0.5,
+                      "unit": "tsp",
+                      "_original": "1/2 tsp of Paprika",
+                      "suggestions": []
+                  },
+                  {
+                      "name": "granulated garlic",
+                      "quantity": 0.5,
+                      "unit": "tsp",
+                      "_original": "1/2 tsp of Granulated Garlic",
+                      "suggestions": [
+                          {
+                              "_id": "5d1659a3dae0822ea455db11",
+                              "name": "granulated sugar",
+                              "variants": [
+                                  "sugar",
+                                  "plain sugar"
+                              ],
+                              "equivalence": 200,
+                              "referenceUnit": "cup",
+                              "prefferedUnit": "g",
+                              "measure": 2
+                          }
+                      ]
+                  },
+                  {
+                      "name": "salt, to taste",
+                      "quantity": 0,
+                      "unit": "",
+                      "_original": "Salt, to taste",
+                      "suggestions": []
                   }
-                ]
-              },
-              {
-                "name": "salt, to taste",
-                "quantity": 0,
-                "unit": "",
-                "_original": "Salt, to taste",
-                "suggestions": []
-              }
-            ]
+              ]
           },
           {
-            "name": "For the Dressing:",
-            "ingredients": [
-              {
-                "name": "plain greek yogurt",
-                "quantity": 0.5,
-                "unit": "cup",
-                "_original": "1/2 cup of Plain Greek Yogurt",
-                "suggestions": [
+              "name": "For the Dressing:",
+              "ingredients": [
+                  {
+                      "name": "plain greek yogurt",
+                      "quantity": 0.5,
+                      "unit": "cup",
+                      "_original": "1/2 cup of Plain Greek Yogurt",
+                      "suggestions": [
+                          {
+                              "_id": "5d1659a3dae0822ea455db16",
+                              "name": "yogurt",
+                              "variants": [
+                                  "plain yogurt"
+                              ],
+                              "equivalence": 245,
+                              "referenceUnit": "cup",
+                              "prefferedUnit": "g",
+                              "measure": 2
+                          },
+                          {
+                              "_id": "5d1659a3dae0822ea455db11",
+                              "name": "granulated sugar",
+                              "variants": [
+                                  "sugar",
+                                  "plain sugar"
+                              ],
+                              "equivalence": 200,
+                              "referenceUnit": "cup",
+                              "prefferedUnit": "g",
+                              "measure": 2
+                          },
+                          {
+                              "_id": "5d1659a3dae0822ea455db06",
+                              "name": "all purpose flour",
+                              "variants": [
+                                  "plain flour",
+                                  "all purpose flour",
+                                  "regular flour"
+                              ],
+                              "equivalence": 125,
+                              "referenceUnit": "cup",
+                              "prefferedUnit": "g",
+                              "translation": {
+                                  "dutch": "patentbloem"
+                              },
+                              "measure": 2
+                          }
+                      ]
+                  },
                   {
-                    "_id": "5cf1397d72cd194524435040",
-                    "name": "yogurt",
-                    "variants": [
-                      "plain yogurt"
-                    ],
-                    "equivalence": 245,
-                    "referenceUnit": "cup",
-                    "prefferedUnit": "gr",
-                    "measure": 2
+                      "name": "fresh cilantro",
+                      "quantity": 1,
+                      "unit": "cup",
+                      "_original": "1 cup of Fresh Cilantro",
+                      "suggestions": []
                   },
                   {
-                    "_id": "5cf1397d72cd19452443503b",
-                    "name": "granulated sugar",
-                    "variants": [
-                      "sugar",
-                      "plain sugar"
-                    ],
-                    "equivalence": 200,
-                    "referenceUnit": "cup",
-                    "prefferedUnit": "gr",
-                    "measure": 2
+                      "name": "scallions, roughly chopped",
+                      "quantity": 2,
+                      "unit": "",
+                      "_original": "2 Scallions, roughly chopped",
+                      "suggestions": []
                   },
                   {
-                    "_id": "5cf1397d72cd194524435030",
-                    "name": "all purpose flour",
-                    "variants": [
-                      "plain flour",
-                      "all purpose flour",
-                      "regular flour",
-                      "flour"
-                    ],
-                    "equivalence": 125,
-                    "referenceUnit": "cup",
-                    "prefferedUnit": "gr",
-                    "translation": {
-                      "dutch": "patentbloem"
-                    },
-                    "measure": 2
+                      "name": "juice of  lime or more, according to taste",
+                      "quantity": 1,
+                      "unit": "",
+                      "_original": "Juice of 1 Lime or more, according to taste",
+                      "suggestions": []
+                  },
+                  {
+                      "name": "olive oil",
+                      "quantity": 1,
+                      "unit": "tbsp",
+                      "_original": "1 Tbsp of Olive Oil",
+                      "suggestions": [
+                          {
+                              "_id": "5d1659a3dae0822ea455db19",
+                              "name": "olive oil",
+                              "variants": [],
+                              "referenceUnit": "tbsp",
+                              "prefferedUnit": "tbsp",
+                              "measure": 1
+                          }
+                      ]
+                  },
+                  {
+                      "name": "salt, to taste",
+                      "quantity": 0,
+                      "unit": "",
+                      "_original": "Salt, to taste",
+                      "suggestions": []
                   }
-                ]
-              },
-              {
-                "name": "fresh cilantro",
-                "quantity": 1,
-                "unit": "cup",
-                "_original": "1 cup of Fresh Cilantro",
-                "suggestions": []
-              },
-              {
-                "name": "scallions, roughly chopped",
-                "quantity": 2,
-                "unit": "",
-                "_original": "2 Scallions, roughly chopped",
-                "suggestions": []
-              },
-              {
-                "name": "juice of  lime or more, according to taste",
-                "quantity": 1,
-                "unit": "",
-                "_original": "Juice of 1 Lime or more, according to taste",
-                "suggestions": []
-              },
-              {
-                "name": "olive oil",
-                "quantity": 1,
-                "unit": "tablespoon",
-                "_original": "1 Tbsp of Olive Oil",
-                "suggestions": []
-              },
-              {
-                "name": "salt, to taste",
-                "quantity": 0,
-                "unit": "",
-                "_original": "Salt, to taste",
-                "suggestions": []
-              }
-            ]
+              ]
           },
           {
-            "name": "For the rest of the salad:",
-            "ingredients": [
-              {
-                "name": "fresh lettuce of your choice",
-                "quantity": 0,
-                "unit": "",
-                "_original": "Fresh Lettuce of your choice",
-                "suggestions": []
-              },
-              {
-                "name": "bell peppers, halved and seeded",
-                "quantity": 2,
-                "unit": "",
-                "_original": "2 Bell Peppers, halved and seeded",
-                "suggestions": []
-              },
-              {
-                "name": "scallions or red onion, sliced",
-                "quantity": 0,
-                "unit": "",
-                "_original": "Scallions or REd Onion, sliced",
-                "suggestions": []
-              },
-              {
-                "name": "pico de gallo salsa",
-                "quantity": 0.5,
-                "unit": "cup",
-                "_original": "1/2 cup of Pico De Gallo Salsa",
-                "suggestions": []
-              },
-              {
-                "name": "avocado, sliced",
-                "quantity": 1,
-                "unit": "",
-                "_original": "1 Avocado, sliced",
-                "suggestions": []
-              }
-            ]
+              "name": "For the rest of the salad:",
+              "ingredients": [
+                  {
+                      "name": "fresh lettuce of your choice",
+                      "quantity": 0,
+                      "unit": "",
+                      "_original": "Fresh Lettuce of your choice",
+                      "suggestions": []
+                  },
+                  {
+                      "name": "bell peppers, halved and seeded",
+                      "quantity": 2,
+                      "unit": "",
+                      "_original": "2 Bell Peppers, halved and seeded",
+                      "suggestions": []
+                  },
+                  {
+                      "name": "scallions or red onion, sliced",
+                      "quantity": 0,
+                      "unit": "",
+                      "_original": "Scallions or REd Onion, sliced",
+                      "suggestions": []
+                  },
+                  {
+                      "name": "pico de gallo salsa",
+                      "quantity": 0.5,
+                      "unit": "cup",
+                      "_original": "1/2 cup of Pico De Gallo Salsa",
+                      "suggestions": []
+                  },
+                  {
+                      "name": "avocado, sliced",
+                      "quantity": 1,
+                      "unit": "",
+                      "_original": "1 Avocado, sliced",
+                      "suggestions": []
+                  }
+              ]
           }
-        ],
+      ],
       },
       scrapeUrl: '',
     }

+ 31 - 1
recipes/src/services/measurements.ts

@@ -2,6 +2,24 @@ import convert from 'convert-units';
 
 type Measure = 'mass'|'volume'|'temperature';
 
+const units = {
+  cup: 'cup',
+  gallon: 'gal',
+  ounce: 'oz',
+  pint: 'pt',
+  pound: 'lb',
+  quart: 'qt',
+  tablespoon: 'tbsp',
+  teaspoon: 'tsp',
+  gram: 'g',
+  kilogram: 'kg',
+  liter: 'l',
+  milligram: 'mg',
+  milliliter: 'ml',
+  package: 'pkg',
+  stick: 'sticks',
+}
+
 const measureValues: { [key:string]: string[] } = {
   mass: ['g', 'kg', 'oz', 'lb'],
   volume: [ 'ml', 'tsp', 'tbsp', 'cup', 'pnt', 'gal', 'oz', 'l'],
@@ -14,6 +32,18 @@ const MeasuresTypes = (measure?: Measure) => {
   [ ...measureValues.mass, ...measureValues.volume, ...measureValues.misc ]
 };
 
+const GetMeasure: (unit:string) => Measure | undefined = unit => {
+  try {
+    // @ts-ignore
+    const data = convert().describe(units[unit]);
+    console.log("unit", unit, data)
+    return data.measure;
+  } catch {
+    return undefined;
+  }
+}
+
 export {
-  MeasuresTypes
+  MeasuresTypes,
+  GetMeasure,
 };

+ 19 - 21
recipes/src/types/recipes.ts

@@ -4,12 +4,6 @@ export interface Ingredient {
   unit: string,
   _original: string,
   suggestions?: Suggestion[],
-  convertion?: {
-    measure: Measures,
-    equivalence?: number,
-    referenceUnit: Units,
-    prefferedUnit: Units,
-  }
 }
 
 export interface SubRecipe {
@@ -66,26 +60,30 @@ export interface Equivalences {
   tbsp?: number,
   tsp?: number,
   stick?: number,
-  gr?: number,
+  g?: number,
   ml?: number,
   oz?: number,
   lb?: number,
 }
 
-type Units = 
-  "cup" |
-  "tbsp" |
-  "tsp" |
-  "stick" |
-  "gr" |
-  "ml" |
-  "oz" |
-  "lb" |
-  "pint" |
-  "gal" |
-  "unit" |
-  "pinch" |
-  "to taste"
+type Units =
+'cup' |
+'gal' |
+'oz' |
+'pt' |
+'lb' |
+'qt' |
+'tbsp' |
+'tsp' |
+'g' |
+'kg' |
+'l' |
+'mg' |
+'ml' |
+'pkg' |
+'sticks' |
+'pinch' |
+'to taste'
 ;
 
 enum Measures {