diff --git a/package-lock.json b/package-lock.json index 81f51b5d..f4246872 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "@ducanh2912/next-pwa": "^10.2.9", "@ericblade/quagga2": "^1.8.4", - "@frontendnetwork/veganify": "^1.1.64", + "@frontendnetwork/veganify": "^1.2.5", "@types/node": "22.5.4", "@types/react-dom": "18.3.0", "eslint-config-sznm": "^2.0.2", @@ -36,6 +36,21 @@ "eslint-plugin-import": "^2.31.0" } }, + "../veganify-api-wrapper": { + "name": "@frontendnetwork/veganify", + "version": "1.2.5", + "license": "MIT", + "devDependencies": { + "@types/jest": "^29.5.1", + "@types/node": "^20.1.0", + "@typescript-eslint/eslint-plugin": "^5.59.5", + "@typescript-eslint/parser": "^5.59.5", + "eslint": "^8.40.0", + "jest": "^29.5.0", + "ts-jest": "^29.1.0", + "typescript": "^5.0.4" + } + }, "node_modules/@aashutoshrathi/word-wrap": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", @@ -2160,9 +2175,8 @@ } }, "node_modules/@frontendnetwork/veganify": { - "version": "1.1.64", - "resolved": "https://registry.npmjs.org/@frontendnetwork/veganify/-/veganify-1.1.64.tgz", - "integrity": "sha512-ajqKJg6ZFjbQ/4JDRfGaUZwk72C1G4aD4IcDWOir5c0a9QfUV9QmOefmM92ODtjtjz2qnGIcIDA5codqgihPmw==" + "resolved": "../veganify-api-wrapper", + "link": true }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.14", diff --git a/package.json b/package.json index d7de07ba..5520f30f 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "dependencies": { "@ducanh2912/next-pwa": "^10.2.9", "@ericblade/quagga2": "^1.8.4", - "@frontendnetwork/veganify": "^1.1.64", + "@frontendnetwork/veganify": "^1.2.5", "@types/node": "22.5.4", "@types/react-dom": "18.3.0", "eslint-config-sznm": "^2.0.2", diff --git a/src/components/ingredientscheck.tsx b/src/components/ingredientscheck.tsx index af7d0524..4910dc4f 100644 --- a/src/components/ingredientscheck.tsx +++ b/src/components/ingredientscheck.tsx @@ -7,13 +7,18 @@ import ModalWrapper from "@/components/elements/modalwrapper"; const IngredientsCheck = () => { const t = useTranslations("Ingredients"); - const [flagged, setFlagged] = useState([]); - const [vegan, setVegan] = useState(""); + const [surelyVegan, setSurelyVegan] = useState([]); + const [notVegan, setNotVegan] = useState([]); + const [maybeVegan, setMaybeVegan] = useState([]); + const [vegan, setVegan] = useState(null); const [error, setError] = useState(false); const [loading, setLoading] = useState(false); const handleSubmit = (event: FormEvent) => { - setVegan(""); + setVegan(null); + setSurelyVegan([]); + setNotVegan([]); + setMaybeVegan([]); setError(false); event.preventDefault(); const ingredients = event.currentTarget.elements.namedItem( @@ -27,14 +32,11 @@ const IngredientsCheck = () => { ingredients.value, process.env.NEXT_PUBLIC_STAGING === "true" ? true : false ); - if (data.data.vegan === false) { - setVegan(false); - setFlagged(data.data.flagged); - setLoading(false); - } else if (data.data.vegan === true) { - setVegan(true); - setLoading(false); - } + setVegan(data.data.vegan); + setSurelyVegan(data.data.surely_vegan); + setNotVegan(data.data.not_vegan); + setMaybeVegan(data.data.maybe_vegan); + setLoading(false); } catch (error) { setError(true); setLoading(false); @@ -75,7 +77,7 @@ const IngredientsCheck = () => { - {vegan && ( + {vegan !== null && (
@@ -84,9 +86,55 @@ const IngredientsCheck = () => { {t("vegan")}
- +
+ {notVegan.length > 0 && ( + <> + {notVegan.map((item) => ( +
+
+ {item.charAt(0).toUpperCase() + item.slice(1)} +
+
+ +
+
+ ))} + + )} + {maybeVegan.length > 0 && ( + <> + {maybeVegan.map((item) => ( +
+
+ {item.charAt(0).toUpperCase() + item.slice(1)} +
+
+ +
+
+ ))} + + )} + {surelyVegan.length > 0 && ( + <> + {surelyVegan.map((item) => ( +
+
+ {item.charAt(0).toUpperCase() + item.slice(1)} +
+
+ +
+
+ ))} + + )} {t("source")}:{" "} @@ -132,8 +180,8 @@ const IngredientsCheck = () => { GNU FDL .
- © Veganify Contributors and Hamed Montazeri, - licensed under{" "} + © Veganify Contributors and Hamed Montazeri, licensed + under{" "} MIT License @@ -170,111 +218,6 @@ const IngredientsCheck = () => {
)} - {vegan === false && flagged && ( -
-
-
-
-
- {t("vegan")} -
-
- -
-
- {flagged.map((item) => ( -
-
- {item.charAt(0).toUpperCase() + item.slice(1)} -
-
- -
-
- ))} - - {t("source")}:{" "} - - VeganPeace - {" "} - ,{" "} - - PETA - {" "} - &{" "} - - The VEGAN WOLF - - - - Licenses -

{t("licenses")}

-
-

{t("licenses_desc")}

-

- © OpenFoodFacts Contributors, licensed under{" "} - - Open Database License - {" "} - and{" "} - - Database Contents License - - .
- © Open EAN/GTIN Database Contributors, licensed under{" "} - - GNU FDL - - .
- © Veganify Contributors and Hamed Montazeri, - licensed under{" "} - - MIT License - - , sourced from{" "} - - VeganPeace - - ,{" "} - - PETA - {" "} - and{" "} - - The VEGAN WOLF - - .
- © Veganify Contributors, sourced from ©{" "} - - PETA (Beauty without Bunnies) - - . -

-
-
- DeepL', - }), - }} - /> - -
-
-
- )} {error && (