Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Nutrition Game #70 #114

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c7043b9
bug: shortCut issue solved
Shmigolk Jul 27, 2022
9c92737
UI: add settings icon and moved links in NavBar to the right
Shmigolk Jul 27, 2022
d0149e2
UI: align pictures and add gap
Shmigolk Jul 27, 2022
4529d8b
UI: add settings icon and moved links in NavBar to the right
Shmigolk Jul 27, 2022
0df05c0
UI: align pictures and add gap
Shmigolk Jul 28, 2022
c89e1f2
UI: create table component
Shmigolk Jul 29, 2022
3a5bd0d
UI: add media queueueueueueury
Shmigolk Jul 29, 2022
9412b2c
fix: add controlled input
Shmigolk Jul 31, 2022
d36a119
fix: add controlled input
Shmigolk Jul 31, 2022
ce50230
Merge remote-tracking branch 'upstream/master' into nutrition
Shmigolk Aug 1, 2022
93d4b4e
feature: change the code of additional nutr
Shmigolk Aug 1, 2022
fe21b02
feature: implement adding nutriments to the table
Shmigolk Aug 1, 2022
a674dfd
feature: implement adding nutriments to the table and removing them f…
Shmigolk Aug 1, 2022
630f0ef
feature: add delete icons and implement deleting nutriments from the …
Shmigolk Aug 1, 2022
257bd35
feature: add Title and the description of the product (hardcoded)
Shmigolk Aug 1, 2022
cb1e486
feature: get data from API. Display picture
Shmigolk Aug 2, 2022
ecd4f07
feature: make clickHandler shorter
Shmigolk Aug 2, 2022
fb90329
feature: move nutriments arraus out of the component. Refresh the tab…
Shmigolk Aug 3, 2022
b952bc4
feature: replace useEffect with React.useEffect
Shmigolk Aug 3, 2022
7d36892
feature: restructure Table component. Make TableRowComp
Shmigolk Aug 9, 2022
b179515
feature: now delete icon toggle display property
Shmigolk Aug 9, 2022
cb6e2c2
feature: now delete icon toggle display property
Shmigolk Aug 9, 2022
089d9df
Merge remote-tracking branch 'origin/master' into nutrition
alexfauquette Aug 9, 2022
79d4643
remove unused import
alexfauquette Aug 9, 2022
9b873e3
feature: now i18n works into the table
Shmigolk Aug 11, 2022
10f5d56
Merge branch 'master' into nutrition
Shmigolk Aug 11, 2022
0add0f0
feature: add keys to common json and en json
Shmigolk Aug 11, 2022
93e7719
Merge remote-tracking branch 'origin/nutrition' into nutrition
Shmigolk Aug 11, 2022
79764f1
feature: display correct properties in select elements
Shmigolk Aug 12, 2022
ae0bffe
feature: on change is working
Shmigolk Aug 12, 2022
30be061
UI: fixed width problem
Shmigolk Aug 13, 2022
7214c83
UI: change the order of elements of productCard and add temporary bor…
Shmigolk Aug 13, 2022
d19a758
bug: fix onChange handler bug
Shmigolk Aug 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
NotFoundPage,
NutriscoreValidator,
Home,
Nutrition,
} from "./pages";
import ResponsiveAppBar from "./components/ResponsiveAppBar";
import DevModeContext from "./contexts/devMode";
Expand Down Expand Up @@ -126,6 +127,7 @@ export default function App() {
<Route path="/settings" element={<SettingsPage />} />
<Route path="/questions" element={<QuestionsPage />} />
<Route path="/insights" element={<InsightsPage />} />
<Route path="/nutrition" element={<Nutrition />} />
<Route path="*" element={<NotFoundPage />} />
<Route path="/nutriscore" element={<NutriscoreValidator />} />
</Routes>
Expand Down
27 changes: 26 additions & 1 deletion src/i18n/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,32 @@
"nutriment_proteins": "Proteins",
"nutriment_fiber": "Fibers",
"nutriment_salt": "Salt",
"nutriment_sodium": "Sodium"
"nutriment_sodium": "Sodium",
"nutriment_zinc" : "Zinc",
"nutriment_vitamin-c" : "Vitamin-c",
"nutriment_vitamin-d" : "Vitamin-d",
"nutriment_vitamin-k" : "Vitamin-k",
"nutriment_vitamin-b6" : "Vitamin-b6",
"nutriment_vitamin-a" : "Vitamin-a",
"nutriment_selenium" : "Selenium",
"nutriment_bicarbonate" : "Bicarbonate",
"nutriment_magnesium" : "Magnesium",
"nutriment_pantothenic-acid" : "Pantothenic-acid",
"nutriment_fluoride" : "Fluoride",
"nutriment_iodine" : "Iodine",
"nutriment_silica" : "Silica",
"nutriment_alcohol" : "Alcohol",
"nutriment_potassium" : "Potassium",
"nutriment_manganese" : "Manganese",
"nutriment_phosphorus" : "Phosphorus",
"nutriment_biotin" : "Biotin",
"nutriment_ph" : "Ph",
"nutriment_molybdenum" : "Molybdenum",
"nutriment_caffeine" : "Caffeine",
"nutriment_chromium" : "Chromium",
"nutriment_iron" : "Iron",
"nutriment_copper" : "Copper",
"nutriment_cholesterol": "Cholesterol"
},
"history": {
"title": "Session History",
Expand Down
27 changes: 26 additions & 1 deletion src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,32 @@
"nutriment_proteins": "Protein content",
"nutriment_fiber": "Fibers",
"nutriment_salt": "Salt",
"nutriment_sodium": "Sodium"
"nutriment_sodium": "Sodium",
"nutriment_zinc" : "Zinc",
"nutriment_vitamin-c" : "Vitamin-c",
"nutriment_vitamin-d" : "Vitamin-d",
"nutriment_vitamin-k" : "Vitamin-k",
"nutriment_vitamin-b6" : "Vitamin-b6",
"nutriment_vitamin-a" : "Vitamin-a",
"nutriment_selenium" : "Selenium",
"nutriment_bicarbonate" : "Bicarbonate",
"nutriment_magnesium" : "Magnesium",
"nutriment_pantothenic-acid" : "Pantothenic-acid",
"nutriment_fluoride" : "Fluoride",
"nutriment_iodine" : "Iodine",
"nutriment_silica" : "Silica",
"nutriment_alcohol" : "Alcohol",
"nutriment_potassium" : "Potassium",
"nutriment_manganese" : "Manganese",
"nutriment_phosphorus" : "Phosphorus",
"nutriment_biotin" : "Biotin",
"nutriment_ph" : "Ph",
"nutriment_molybdenum" : "Molybdenum",
"nutriment_caffeine" : "Caffeine",
"nutriment_chromium" : "Chromium",
"nutriment_iron" : "Iron",
"nutriment_copper" : "Copper",
"nutriment_cholesterol": "Cholesterol"
},
"history": {
"title": "Session History",
Expand Down
1 change: 1 addition & 0 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export { default as LogoUpdatePage } from "./logos/LogoUpdate";

// experimental
export { default as NutriscoreValidator } from "./nutriscoreValidator";
export { default as Nutrition } from "./nutrition"
35 changes: 35 additions & 0 deletions src/pages/nutrition/additionalNutritions.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as React from "react";
import TextField from "@mui/material/TextField";
import Autocomplete from "@mui/material/Autocomplete";
import { useTranslation } from "react-i18next";

export default function AdditionalNutriments({ options, setNutriments }) {
const [inputValue, setInputValue] = React.useState("");
const { t } = useTranslation();

return (
<Autocomplete
value={null}
disablePortal
id="nutrition-input"
options={options}
sx={{ width: 245, marginLeft: 2, marginTop: 2 }}
onChange={(event) => {
const nutr = event.target.innerText;
const nutrName = options.find((item) => item.label === nutr).id;

setNutriments((prev) =>
prev.map((nutr) =>
nutr.label === nutrName ? { ...nutr, display: true } : nutr
)
);
setInputValue("");
}}
inputValue={inputValue}
onInputChange={(event, newInputValue) => {
setInputValue(newInputValue);
}}
renderInput={(params) => <TextField {...params} label="Add nutriment" />}
/>
);
}
57 changes: 57 additions & 0 deletions src/pages/nutrition/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as React from "react";
import NutritionTable from "./table";
import ProductNutriments from "./productCard";
import { Box } from "@mui/material";

import { basicNutriments } from "./nutritionFields";

export default function Nutrition() {
const [nutriments, setNutriments] = React.useState(basicNutriments);

function onchangeHandler(e) {
const { value, name, id } = e.target;
console.log(name);
setNutriments((prevState) =>
prevState.map((nutr) => {
return id === nutr.label ? { ...nutr, [name]: value } : nutr;
})
);
}

function deleteItem(nutr) {
setNutriments((prev) =>
prev.map((nutriment) =>
nutriment === nutr ? { ...nutriment, display: false } : nutriment
)
);
}

return (
<Box
display={"flex"}
flexDirection={{ xs: "column", md: "row" }}
gap={2}
sx={{
width: 1,
height: 1,
alignItems: { xs: "center", md: "flex-start" },
justifyContent: "center",
padding: 4,
border: "5px solid green",
minHeight: "89.4vh",
}}
>
<ProductNutriments
setNutriments={setNutriments}
nutriments={nutriments}
/>
<NutritionTable
nutriments={nutriments.filter((nutr) => nutr.display)}
setNutriments={setNutriments}
additionalNutriments={nutriments.filter((nutr) => !nutr.display)}
onchangeHandler={onchangeHandler}
deleteItem={deleteItem}
/>
</Box>
);
}
Loading