Skip to content

Commit

Permalink
fix(328): Update to only have a single submit (#347)
Browse files Browse the repository at this point in the history
* fix(328): Update to only have a single submit

* Add default date
  • Loading branch information
knguyenrise8 authored Oct 29, 2024
1 parent 8da47e8 commit 466e028
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/TemplatesIndex/TemplatesIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const TemplatesIndex: FC<TemplateIndexProps> = () => {
'lastUpdated': (d) => {
const date = Date.parse(d)
if (isNaN(date)) {
return "Invalid Date"
return new Date().toLocaleDateString()
}
return new Date(date).toLocaleDateString()

Expand Down
14 changes: 8 additions & 6 deletions frontend/src/pages/ExtractProcess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) {
Expand Down Expand Up @@ -80,7 +80,7 @@ const ExtractProcess = () => {
console.error("Error processing templates:", error);
setIsLoading(false);
}
}
}, [navigate])

useEffect(() => {
const pdfFile = files[0]
Expand Down Expand Up @@ -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 (
<LoadingWrapper isLoading={isLoading}>
Expand Down

0 comments on commit 466e028

Please sign in to comment.