From 8ff67bd1b0475450acd9879e60a0353925326745 Mon Sep 17 00:00:00 2001 From: ljreaux <146141261+ljreaux@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:26:25 -0500 Subject: [PATCH] minor updates to pdf functionality --- src-tauri/tauri.conf.json | 2 +- src/components/Home/PDF.tsx | 347 ++++++++++++++++++++---------------- 2 files changed, 199 insertions(+), 150 deletions(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index ea80d6c..7226e9b 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -60,7 +60,7 @@ }, "productName": "MeadTools", "mainBinaryName": "MeadTools", - "version": "1.0.1", + "version": "1.0.2", "identifier": "meadtools", "app": { "windows": [ diff --git a/src/components/Home/PDF.tsx b/src/components/Home/PDF.tsx index e308d10..236c22a 100644 --- a/src/components/Home/PDF.tsx +++ b/src/components/Home/PDF.tsx @@ -15,7 +15,6 @@ import { toBrix } from "../../helpers/unitConverters"; import useAbv from "../../hooks/useAbv.ts"; import { FormData } from "../Nutrients/NutrientCalc"; import calcSb from "../../helpers/calcSb"; -import i18n from "../../localization/i18n.ts"; import { Fragment, useEffect, useState } from "react"; // Create styles @@ -87,7 +86,15 @@ const MyDocument = ({ primaryNotes: string[][]; secondaryNotes: string[][]; }) => { - const { t } = useTranslation(); + const [adding, setAdding] = useState(false); + useEffect(() => { + const adding = JSON.parse( + localStorage.getItem("addingStabilizers") || '{"adding": false}' + )?.adding; + setAdding(adding); + }, [sorbate, sulfite]); + + const { t, i18n } = useTranslation(); const ABVOBJ = OG && FG ? { OG, FG } : { OG: 1, FG: 1 }; const { delle } = useAbv(ABVOBJ); @@ -109,6 +116,19 @@ const MyDocument = ({ const filteredAdditives = additives?.filter((item) => { return item.amount > 0 && item.name.length > 0; }); + + const isMetric = units?.weight === "kg" || units?.volume === "liter"; + function toC(num?: number) { + if (!num) return ""; + return isMetric ? Math.round((num - 32) * (5 / 9)) : num; + } + const lowTemp = toC(selected?.yeastDetails.low_temp); + const highTemp = toC(selected?.yeastDetails.high_temp); + + const tempString = `${t("PDF.tempRange")} ${lowTemp}-${highTemp}°${ + isMetric ? "C" : "F" + }`; + return ( @@ -195,11 +215,7 @@ const MyDocument = ({ : "" } ${selected?.yeastDetails.name}`} - - {`${t("PDF.tempRange")} ${selected?.yeastDetails.low_temp}-${ - selected?.yeastDetails.high_temp - }°F`} - + {tempString} - - {sorbate && sulfite && campden && ( + {adding ? ( + + {sorbate && sulfite && campden && ( + + {t("PDF.stabilizers")} + + )} - {t("PDF.stabilizers")} + {t("PDF.remaining")} - )} - - {t("PDF.remaining")} - - + {adding && ( + + + {sulfite && + campden && + `${Math.round(sulfite * 1000) / 1000}g ${t( + "PDF.kmeta" + )} ${t("accountPage.or")} ${ + Math.round(campden * 10) / 10 + } ${t("list.campden")}`} + + + {sorbate && + `${Math.round(sorbate * 1000) / 1000}g ${t( + "PDF.ksorb" + )}`} + + + )} - {sulfite && - campden && - `${Math.round(sulfite * 1000) / 1000}g ${t( - "PDF.kmeta" - )} ${t("accountPage.or")} ${ - Math.round(campden * 10) / 10 - } ${t("list.campden")}`} + {nuteInfo + ? `${Math.round(nuteInfo?.remainingYan)}PPM` + : "0PPM"} + + ) : ( + <> - {sorbate && - `${Math.round(sorbate * 1000) / 1000}g ${t("PDF.ksorb")}`} + {t("PDF.remaining")} - - - {nuteInfo - ? `${Math.round(nuteInfo?.remainingYan)}PPM` - : "0PPM"} - - + + {nuteInfo + ? `${Math.round(nuteInfo?.remainingYan)}PPM` + : "0PPM"} + + + )} @@ -626,115 +673,117 @@ const MyDocument = ({ })} )} - - { - - - {t("PDF.secondary")} - - - {t("PDF.weight")} {units && units.weight} - - - {t("PDF.volume")} {units && units.volume} - - - } + {secondary.length > 0 && ( + + { + + + {t("PDF.secondary")} + + + {t("PDF.weight")} {units && units.weight} + + + {t("PDF.volume")} {units && units.volume} + + + } - {secondary.map((item, i) => ( - - - {i + 1}. {t(`${lodash.camelCase(item.name)}`)} - - - {item.details[0]} - - - {item.details[1]} - - - ))} - {filteredAdditives && filteredAdditives.length && ( - - - {t("PDF.additives")} - - - {t("PDF.addAmount")} - - - )} - {filteredAdditives && - filteredAdditives.map((item, i) => ( - + {secondary.map((item, i) => ( + - {i + 1}. {item.name} + {i + 1}. {t(`${lodash.camelCase(item.name)}`)} - {`${item.amount}${item.unit}`} + {item.details[0]} + + + {item.details[1]} ))} - + {filteredAdditives && filteredAdditives.length > 0 && ( + + + {t("PDF.additives")} + + + {t("PDF.addAmount")} + + + )} + {filteredAdditives && + filteredAdditives.map((item, i) => ( + + + {i + 1}. {item.name} + + + {`${item.amount} ${item.unit !== "units" ? item.unit : ""}`} + + + ))} + + )} {secondaryNotes.length && secondaryNotes[0][0].length && (