From 466e028aac7adbb4634d48b63a47a3b9c1464df3 Mon Sep 17 00:00:00 2001 From: knguyenrise8 <159168836+knguyenrise8@users.noreply.github.com> Date: Tue, 29 Oct 2024 09:03:31 -0500 Subject: [PATCH] fix(328): Update to only have a single submit (#347) * fix(328): Update to only have a single submit * Add default date --- .../components/TemplatesIndex/TemplatesIndex.tsx | 2 +- frontend/src/pages/ExtractProcess.tsx | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/TemplatesIndex/TemplatesIndex.tsx b/frontend/src/components/TemplatesIndex/TemplatesIndex.tsx index fcb50f65..b6b555ed 100644 --- a/frontend/src/components/TemplatesIndex/TemplatesIndex.tsx +++ b/frontend/src/components/TemplatesIndex/TemplatesIndex.tsx @@ -43,7 +43,7 @@ export const TemplatesIndex: FC = () => { 'lastUpdated': (d) => { const date = Date.parse(d) if (isNaN(date)) { - return "Invalid Date" + return new Date().toLocaleDateString() } return new Date(date).toLocaleDateString() diff --git a/frontend/src/pages/ExtractProcess.tsx b/frontend/src/pages/ExtractProcess.tsx index 40d34655..d1c68c35 100644 --- a/frontend/src/pages/ExtractProcess.tsx +++ b/frontend/src/pages/ExtractProcess.tsx @@ -5,7 +5,7 @@ import { ExtractStepper } from "../components/ExtractStepper"; import { ExtractStep } from "../utils/constants"; import LoadingWrapper from "../components/LoadingWrapper"; import { ImageToText } from "../../api/api" -import { useEffect, useState } from "react"; +import { useCallback, useEffect, useState } from "react"; import { FileType, useFiles } from "../contexts/FilesContext"; import { ImageToTextResponse, Submission } from "../../api/types/types"; import * as pdfjsLib from "pdfjs-dist"; @@ -28,7 +28,7 @@ const ExtractProcess = () => { const [isLoading, setIsLoading] = useState(false); - const handleSubmit = async () => { + const handleSubmit = useCallback(async () => { const templates: FileType[] = JSON.parse(localStorage.getItem("templates") || "[]"); // Check if templates exist if (templates.length === 0) { @@ -80,7 +80,7 @@ const ExtractProcess = () => { console.error("Error processing templates:", error); setIsLoading(false); } - } + }, [navigate]) useEffect(() => { const pdfFile = files[0] @@ -112,11 +112,13 @@ const ExtractProcess = () => { return images; }; - convertPdfToImages(pdfFile).then((imgs) => { + convertPdfToImages(pdfFile) + .then((imgs) => { setImages(imgs); localStorage.setItem("images", JSON.stringify(imgs)); - }); - }, [files]); + }) + .finally(() => handleSubmit()) + }, [files, handleSubmit]); return (