diff --git a/src/pages/nutrition/index.tsx b/src/pages/nutrition/index.tsx index d024739cda..71cc4998b7 100644 --- a/src/pages/nutrition/index.tsx +++ b/src/pages/nutrition/index.tsx @@ -9,9 +9,11 @@ import { import { Box, Button } from "@mui/material"; import Stack from "@mui/material/Stack"; import { + deleteRobotoff, isValidUnit, NUTRIMENTS, postRobotoff, + skipRobotoff, structurePredictions, } from "./utils"; import { NutrimentPrediction } from "./insight.types"; @@ -54,212 +56,224 @@ export default function Nutrition() { key={insight.source_image} src={`${OFF_IMAGE_URL}${insight.source_image}`} alt="" - style={{ width: "100%", maxHeight: "90vh" }} + style={{ + width: "100%", + maxHeight: "200vh", + }} /> - - - - - - - - - + + +
Nutri
{nutrimentsDetected.map((nutrimentId) => { return ( -
- - - - + {UNITS.map((unit) => ( + + ))} + + ) : ( + + {item?.unit} + + )} + + ); })} - - - - - - - -
Nutri100g - serving{" "} - -
{NUTRIMENTS[nutrimentId] ?? nutrimentId} - - setValues((p) => ({ - ...p, - [`${nutrimentId}_100g`]: { - ...p[`${nutrimentId}_100g`], - value: event.target.value, - }, - })) - } - /> +
+ {NUTRIMENTS[nutrimentId] ?? nutrimentId} +
+ ); + })} + + +
100g
+ {nutrimentsDetected.map((nutrimentId) => { + const key = `${nutrimentId}_100g`; + const item = values[key]; + + return ( +
+ + setValues((p) => ({ + ...p, + [key]: { + ...p[key], + value: event.target.value, + }, + })) + } + /> - {isValidUnit(values[`${nutrimentId}_100g`]?.unit) ? ( - - ) : ( - - {values[`${nutrimentId}_100g`]?.unit} - - )} -
- - setValues((p) => ({ - ...p, - [`${nutrimentId}_serving`]: { - ...p[`${nutrimentId}_serving`], - value: event.target.value, - }, - })) - } - /> + {UNITS.map((unit) => ( + + ))} + + ) : ( + + {item?.unit} + + )} + + + ); + })} + + + +
+ serving{" "} + +
+ {nutrimentsDetected.map((nutrimentId) => { + const key = `${nutrimentId}_serving`; + const item = values[key]; - {isValidUnit(values[`${nutrimentId}_serving`]?.unit) ? ( - - ) : ( - - {values[`${nutrimentId}_serving`]?.unit} - - )} + return ( +
+ + setValues((p) => ({ + ...p, + [key]: { + ...p[key], + value: event.target.value, + }, + })) + } + /> -
- - - - -
- {/* {showRaw && ( -
-                {JSON.stringify(insight, null, 2)}
-              
- )} - */} - + +
+ + + + + + ); } - -// nutrient: { -// } -// nutrition_data_per = "100g" | "serving"; diff --git a/src/pages/nutrition/utils.ts b/src/pages/nutrition/utils.ts index f0b1949cd0..42892a9cc5 100644 --- a/src/pages/nutrition/utils.ts +++ b/src/pages/nutrition/utils.ts @@ -18,7 +18,7 @@ export const NUTRIMENTS = { }; export function isValidUnit(unit: string | null) { - return unit === null || UNITS.includes(unit); + return unit == null || UNITS.includes(unit); } export function structurePredictions( @@ -63,8 +63,35 @@ export function postRobotoff(config: PostRobotoffParams) { `${ROBOTOFF_API_URL}/insights/annotate`, { insight_id: insightId, + annotation: 2, data: { nutrient: filteredValues }, }, { withCredentials: true }, ); } + +export function skipRobotoff(config: Pick) { + const { insightId } = config; + + axios.post( + `${ROBOTOFF_API_URL}/insights/annotate`, + { + insight_id: insightId, + annotation: -1, + }, + { withCredentials: true }, + ); +} + +export function deleteRobotoff(config: Pick) { + const { insightId } = config; + + axios.post( + `${ROBOTOFF_API_URL}/insights/annotate`, + { + insight_id: insightId, + annotation: 0, + }, + { withCredentials: true }, + ); +}