Refactored routing components for better organization and maintainability
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { CAMBASE } from "../../../utils/config";
|
import { CAMBASE } from "../../../utils/config";
|
||||||
|
import type { CameraID } from "../../../app/config/cameraConfig";
|
||||||
|
|
||||||
const targetDectionFeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
|
const targetDectionFeed = async (cameraFeedID: CameraID | null) => {
|
||||||
const response = await fetch(`${CAMBASE}/TargetDetectionColour${cameraFeedID}-preview`, {
|
const response = await fetch(`${CAMBASE}/TargetDetectionColour${cameraFeedID}-preview`, {
|
||||||
signal: AbortSignal.timeout(300000),
|
signal: AbortSignal.timeout(300000),
|
||||||
cache: "no-store",
|
cache: "no-store",
|
||||||
@@ -12,7 +13,7 @@ const targetDectionFeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
|
|||||||
return response.blob();
|
return response.blob();
|
||||||
};
|
};
|
||||||
|
|
||||||
const getVideoFeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
|
const getVideoFeed = async (cameraFeedID: CameraID | null) => {
|
||||||
const response = await fetch(`${CAMBASE}/Camera${cameraFeedID}-preview`, {
|
const response = await fetch(`${CAMBASE}/Camera${cameraFeedID}-preview`, {
|
||||||
signal: AbortSignal.timeout(300000),
|
signal: AbortSignal.timeout(300000),
|
||||||
cache: "no-store",
|
cache: "no-store",
|
||||||
@@ -23,7 +24,7 @@ const getVideoFeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
|
|||||||
return response.blob();
|
return response.blob();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useGetVideoFeed = (cameraFeedID: "A" | "B" | "C" | null, mode: string) => {
|
export const useGetVideoFeed = (cameraFeedID: CameraID | null, mode: string) => {
|
||||||
const targetDetectionQuery = useQuery({
|
const targetDetectionQuery = useQuery({
|
||||||
queryKey: ["getfeed", cameraFeedID],
|
queryKey: ["getfeed", cameraFeedID],
|
||||||
queryFn: () => targetDectionFeed(cameraFeedID),
|
queryFn: () => targetDectionFeed(cameraFeedID),
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import type { SystemHealthStatus } from "../../../../types/types";
|
import type { SystemHealthStatus } from "../../../../types/types";
|
||||||
import { capitalize } from "../../../../utils/utils";
|
|
||||||
import SystemHealthModal from "../systemHealth/systemHealthModal/SystemHealthModal";
|
import SystemHealthModal from "../systemHealth/systemHealthModal/SystemHealthModal";
|
||||||
|
import Badge from "../../../../ui/Badge";
|
||||||
|
|
||||||
type CameraStatusGridItemProps = {
|
type CameraStatusGridItemProps = {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -15,6 +16,10 @@ const CameraStatusGridItem = ({ title, statusCategory }: CameraStatusGridItemPro
|
|||||||
return status.tags.every((tag) => allowedTags.includes(tag));
|
return status.tags.every((tag) => allowedTags.includes(tag));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const downItems = statusCategory?.filter((status) => {
|
||||||
|
return status.tags.some((tag) => tag !== "RUNNING" && tag !== "VIDEO-PLAYING");
|
||||||
|
});
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
};
|
};
|
||||||
@@ -24,8 +29,21 @@ const CameraStatusGridItem = ({ title, statusCategory }: CameraStatusGridItemPro
|
|||||||
className="flex flex-col border border-gray-600 p-4 rounded-lg mr-4 hover:bg-[#233241] hover:cursor-pointer m-2 h-70"
|
className="flex flex-col border border-gray-600 p-4 rounded-lg mr-4 hover:bg-[#233241] hover:cursor-pointer m-2 h-70"
|
||||||
onClick={() => setIsOpen(true)}
|
onClick={() => setIsOpen(true)}
|
||||||
>
|
>
|
||||||
<h3 className="text-lg flex flex-row items-center">{capitalize(title)}</h3>
|
<p className="text-sm text-slate-300">
|
||||||
<p className="text-sm text-slate-300">{isAllGood ? "Click to view module status" : "Some systems down"}</p>
|
{isAllGood ? (
|
||||||
|
"Click to view module status"
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<ul>
|
||||||
|
{downItems.map((item) => (
|
||||||
|
<li key={item.id} className="flex justify-between mb-2">
|
||||||
|
<span>{item.id}</span> <Badge text={item.tags[0]} />
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<SystemHealthModal
|
<SystemHealthModal
|
||||||
isSystemHealthModalOpen={isOpen}
|
isSystemHealthModalOpen={isOpen}
|
||||||
|
|||||||
@@ -6,9 +6,5 @@ export const Route = createFileRoute("/cameras")({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
return (
|
return <CameraGrid />;
|
||||||
<div>
|
|
||||||
<CameraGrid />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,5 @@ export const Route = createFileRoute("/output")({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
return (
|
return <OutputForms />;
|
||||||
<div>
|
|
||||||
<OutputForms />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,5 @@ export const Route = createFileRoute("/settings")({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
return (
|
return <Settings />;
|
||||||
<div>
|
|
||||||
<Settings />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user