From 20aa7f285132c35e2503b09bdd7e02c2b774faeb Mon Sep 17 00:00:00 2001 From: Michael Nolivos Date: Sun, 31 Mar 2024 14:45:53 -0400 Subject: [PATCH] chore: ingread copy improvements and yeast alert --- app/routes/ingread/route.tsx | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/app/routes/ingread/route.tsx b/app/routes/ingread/route.tsx index 3bbec46..c397bfd 100644 --- a/app/routes/ingread/route.tsx +++ b/app/routes/ingread/route.tsx @@ -2,7 +2,7 @@ import { ScanLine, Trash2, VideoIcon, VideoOff } from 'lucide-react' import { useRef, useState, useCallback, useEffect } from 'react' import Webcam from 'react-webcam' import { Button } from 'src/components/ui/button' -import { useFetcher, useLoaderData } from '@remix-run/react' +import { useFetcher, useRouteError } from '@remix-run/react' import { ActionFunctionArgs, LoaderFunctionArgs, json } from '@remix-run/node' import { invariantResponse } from 'src/utils/misc' import { openai } from 'src/lib/openai.server' @@ -10,6 +10,7 @@ import { clsx } from 'clsx' import { toast } from 'react-hot-toast' import { load, Schema, Type } from 'js-yaml' import { z } from 'zod' +import { Alert, AlertDescription, AlertTitle } from 'src/components/ui/alert' // OpenAI Vision API expects a 512x512 image at least // and is the cheapest option @@ -106,7 +107,9 @@ const CameraCapture: React.FC = () => { const captureFetcher = useFetcher() - const loaderData = useLoaderData() + const yeastIngredients = captureFetcher.data?.ingredients + ? captureFetcher.data.ingredients.filter((ingredient: string) => /yeast/i.test(ingredient)) + : [] const isScanning = captureFetcher.state !== 'idle' @@ -146,7 +149,7 @@ const CameraCapture: React.FC = () => { }, []) return ( -
+
{!isCaptureEnable && (
{
)} + + {!isScanning && isCaptureEnable && captureFetcher.data && yeastIngredients.length > 0 && ( + + Yeast Ingredients Found + {yeastIngredients.length} ingredients with yeast found. + + )} +
{isScanning && ( <> @@ -228,9 +239,7 @@ const CameraCapture: React.FC = () => {
)} - {!isScanning && !captureFetcher.data && ( -

Quickly check for {loaderData.entrypoint || 'NAC Protocol'} with the snap of a photo.

- )} + {!isScanning && !captureFetcher.data &&

Quickly check ingredient lists for yeast.

} {!isScanning && isCaptureEnable && captureFetcher.data?.ingredients && (

@@ -243,7 +252,7 @@ const CameraCapture: React.FC = () => { - {/yeast|citric acid/i.test(ing) && '😱'} + {/yeast/i.test(ing) && '😱'} {ing} @@ -258,4 +267,15 @@ const CameraCapture: React.FC = () => { ) } +export const ErrorBoundary = () => { + const error = useRouteError() + console.error(error) + return ( +
+

Oops!

+

Sorry, an unexpected error has occurred.

+
+ ) +} + export default CameraCapture