From 794fd9b3a0e650031e7231b682986b5614c86f3f Mon Sep 17 00:00:00 2001
From: Rishi Ghan
Date: Wed, 15 Nov 2023 10:46:36 -0600
Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20Added=20null=20check=20?=
=?UTF-8?q?and=20removed=20useless=20deps?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/client/components/Import/Import.tsx | 211 ++++++++++++------------
1 file changed, 103 insertions(+), 108 deletions(-)
diff --git a/src/client/components/Import/Import.tsx b/src/client/components/Import/Import.tsx
index 86cd845..d370e4d 100644
--- a/src/client/components/Import/Import.tsx
+++ b/src/client/components/Import/Import.tsx
@@ -1,9 +1,4 @@
import React, { ReactElement, useCallback, useEffect } from "react";
-import {
- fetchComicBookMetadata,
- getImportJobResultStatistics,
- setQueueControl,
-} from "../../actions/fileops.actions";
import "react-loader-spinner/dist/loader/css/react-spinner-loader.css";
import { format } from "date-fns";
import Loader from "react-loader-spinner";
@@ -21,10 +16,7 @@ interface IProps {
}
/**
- * Component to facilitate comics.
- *
- * @remarks
- * This method is part of the {@link core-library#Statistics | Statistics subsystem}.
+ * Component to facilitate the import of comics to the ThreeTwo library
*
* @param x - The first input number
* @param y - The second input number
@@ -41,14 +33,6 @@ export const Import = (props: IProps): ReactElement => {
})),
);
- // const libraryQueueImportStatus = useSelector(
- // (state: RootState) => state.fileOps.LSQueueImportStatus,
- // );
- //
- // const allImportJobResults = useSelector(
- // (state: RootState) => state.fileOps.importJobStatistics,
- // );
-
const sessionId = localStorage.getItem("sessionId");
const { mutate: initiateImport } = useMutation({
mutationFn: async () =>
@@ -59,6 +43,15 @@ export const Import = (props: IProps): ReactElement => {
}),
});
+ const { data, isError, isLoading } = useQuery({
+ queryKey: ["allImportJobResults"],
+ queryFn: async () =>
+ await axios({
+ method: "GET",
+ url: "http://localhost:3000/api/jobqueue/getJobResultStatistics",
+ }),
+ });
+
// 1a. Act on each comic issue successfully imported/failed, as indicated
// by the LS_COVER_EXTRACTED/LS_COVER_EXTRACTION_FAILED events
socketIOInstance.on("LS_COVER_EXTRACTED", (data) => {
@@ -89,10 +82,6 @@ export const Import = (props: IProps): ReactElement => {
);
};
- useEffect(() => {
- // dispatch(getImportJobResultStatistics());
- }, []);
-
const renderQueueControls = (status: string): ReactElement | null => {
switch (status) {
case "running":
@@ -173,98 +162,104 @@ export const Import = (props: IProps): ReactElement => {
- <>
-
-
-
- | Completed Jobs |
- Failed Jobs |
- Queue Controls |
- Queue Status |
-
-
+ {importJobQueue.status !== "drained" &&
+ !isUndefined(importJobQueue.status) && (
+ <>
+
+
+
+ | Completed Jobs |
+ Failed Jobs |
+ Queue Controls |
+ Queue Status |
+
+
-
-
- |
- {importJobQueue.successfulJobCount > 0 && (
-
-
- {importJobQueue.successfulJobCount}
-
-
- )}
- |
-
- {importJobQueue.failedJobCount > 0 && (
-
-
- {importJobQueue.failedJobCount}
-
-
- )}
- |
+
+
+ |
+ {importJobQueue.successfulJobCount > 0 && (
+
+
+ {importJobQueue.successfulJobCount}
+
+
+ )}
+ |
+
+ {importJobQueue.failedJobCount > 0 && (
+
+
+ {importJobQueue.failedJobCount}
+
+
+ )}
+ |
- {renderQueueControls(importJobQueue.status)} |
-
- {importJobQueue.status !== undefined ? (
-
- {importJobQueue.status}
-
- ) : null}
- |
-
-
-
- Imported{" "}
-
- {importJobQueue.mostRecentImport}
-
- >
+ {renderQueueControls(importJobQueue.status)} |
+
+ {importJobQueue.status !== undefined ? (
+
+ {importJobQueue.status}
+
+ ) : null}
+ |
+
+
+
+ Imported{" "}
+
+ {importJobQueue.mostRecentImport}
+
+ >
+ )}
{/* Past imports */}
-
- Past Imports
- {/*
-
-
- | Time Started |
- Session Id |
- Imported |
- Failed |
-
-
-
-
- {allImportJobResults.map((jobResult, id) => {
- return (
-
- |
- {format(
- new Date(jobResult.earliestTimestamp),
- "EEEE, hh:mma, do LLLL Y",
- )}
- |
-
-
- {jobResult.sessionId}
-
- |
-
-
- {jobResult.completedJobs}
-
- |
-
-
- {jobResult.failedJobs}
-
- |
+ {!isLoading && !isEmpty(data?.data) && (
+ <>
+ Past Imports
+
+
+
+ | Time Started |
+ Session Id |
+ Imported |
+ Failed |
- );
- })}
-
-
*/}
+
+
+
+ {data?.data.map((jobResult, id) => {
+ return (
+
+ |
+ {format(
+ new Date(jobResult.earliestTimestamp),
+ "EEEE, hh:mma, do LLLL Y",
+ )}
+ |
+
+
+ {jobResult.sessionId}
+
+ |
+
+
+ {jobResult.completedJobs}
+
+ |
+
+
+ {jobResult.failedJobs}
+
+ |
+
+ );
+ })}
+
+
+ >
+ )}
);