Add OSD and Payload configuration components with toggle functionality

This commit is contained in:
2025-12-18 13:38:27 +00:00
parent b79da7048e
commit b328d25bc7
8 changed files with 190 additions and 9 deletions

View File

@@ -1,7 +1,7 @@
import { Field, useFormikContext } from "formik";
import { useOSDConfig } from "../hooks/useOSDConfig";
import { useOSDConfig } from "../../hooks/useOSDConfig";
import OSDFieldToggle from "./OSDFieldToggle";
import type { OSDConfigFields } from "../../../types/types";
import type { OSDConfigFields } from "../../../../types/types";
import { toast } from "sonner";
type OSDFieldsProps = {
@@ -12,7 +12,16 @@ const OSDFields = ({ isOSDLoading }: OSDFieldsProps) => {
const { osdMutation } = useOSDConfig();
const { values } = useFormikContext<OSDConfigFields>();
const includeKeys = Object.keys(values as OSDConfigFields).filter((value) => value.includes("include"));
const validOSDKeys: Array<keyof OSDConfigFields> = [
"includeVRM",
"includeMotion",
"includeTimeStamp",
"includeCameraName",
"overlayPosition",
"OSDTimestampFormat",
];
const includeKeys = validOSDKeys.filter((key) => key.includes("include") && typeof values[key] === "boolean");
const handleSubmit = async (values: OSDConfigFields) => {
const result = await osdMutation.mutateAsync(values);

View File

@@ -1,5 +1,6 @@
import Card from "../../../ui/Card";
import CardHeader from "../../../ui/CardHeader";
import Card from "../../../../ui/Card";
import CardHeader from "../../../../ui/CardHeader";
import PayloadOptions from "../PayloadOptions/PayloadOptions";
import OSDFields from "./OSDFields";
import { Tab, TabList, TabPanel, Tabs } from "react-tabs";
import "react-tabs/style/react-tabs.css";
@@ -15,13 +16,13 @@ const OSDOptionsCard = ({ isOSDLoading }: OSDOptionsCardProps) => {
<Tabs>
<TabList>
<Tab>OSD Settings</Tab>
<Tab>payload Settings</Tab>
<Tab>Payload Settings</Tab>
</TabList>
<TabPanel>
<OSDFields isOSDLoading={isOSDLoading} />
</TabPanel>
<TabPanel>
<div>payload settings</div>
<PayloadOptions />
</TabPanel>
</Tabs>
</Card>

View File

@@ -6,7 +6,7 @@ import { usePostBearerConfig } from "../hooks/useBearer";
import { useDispatcherConfig } from "../hooks/useDispatcherConfig";
import { useOptionalConstants } from "../hooks/useOptionalConstants";
import { useCustomFields } from "../hooks/useCustomFields";
import OSDOptionsCard from "./OSDOptionsCard";
import OSDOptionsCard from "./OSD/OSDOptionsCard";
import { useOSDConfig } from "../hooks/useOSDConfig";
const OutputForms = () => {
@@ -89,6 +89,39 @@ const OutputForms = () => {
includeCameraName: includeCameraName ?? false,
overlayPosition: overlayPosition ?? "Top",
OSDTimestampFormat: OSDTimestampFormat ?? "UTC",
// payload ooptions
includeMac: false,
includeSaFID: false,
includeCharHeight: false,
includeConfidence: false,
includeCorrectSpacing: false,
includeDecodeID: false,
includeDirection: false,
includeFrameHeight: false,
includeFrameID: false,
includeFrameTimeRef: false,
includeFrameWidth: false,
includeHorizSlew: false,
inclduePlate: false,
includeNightModeAction: false,
includeOverview: false,
includePlateSecondary: false,
includePlateTrack: false,
includePlateTrackSecondary: false,
includePreferredCountry: false,
includeRawReads: false,
includeRawREADSSecondary: false,
includeRef: false,
includeSeenCount: false,
includeRepeatedPlate: false,
includeSerialCount: false,
includeTraceCount: false,
includeTrack: false,
includeTrackSecondary: false,
includeVertSlew: false,
includeVRMSecondary: false,
includeHotListMatches: false,
};
const handleSubmit = async (values: FormTypes) => {

View File

@@ -0,0 +1,56 @@
import { useFormikContext } from "formik";
import type { PayloadConfigFields } from "../../../../types/types";
import PayloadOptionsToggle from "./PayloadOptionsToggle";
const PayloadOptions = () => {
const { values } = useFormikContext<PayloadConfigFields>();
const validPayloadKeys: Array<keyof PayloadConfigFields> = [
"includeMac",
"includeSaFID",
"includeCharHeight",
"includeConfidence",
"includeCorrectSpacing",
"includeDecodeID",
"includeDirection",
"includeFrameHeight",
"includeFrameID",
"includeFrameTimeRef",
"includeFrameWidth",
"includeHorizSlew",
"inclduePlate",
"includeNightModeAction",
"includeOverview",
"includePlateSecondary",
"includePlateTrack",
];
const includeKeys = validPayloadKeys.filter((key) => key.includes("include") && typeof values[key] === "boolean");
const handleSubmit = async (values: PayloadConfigFields) => {
console.log("Payload Config Submitted:", values);
};
return (
<div className="">
<div className="flex flex-col space-y-4">
<div className="p-4 border border-gray-600 rounded-lg flex flex-col space-y-4">
<div className="flex flex-col space-y-4 h-100 overflow-y-auto p-3">
{includeKeys.map((key, index) => (
<PayloadOptionsToggle key={index} label={key} value={key} />
))}
</div>
<button
type="button"
onClick={() => handleSubmit(values)}
className="w-full md:w-1/4 text-white bg-green-700 hover:bg-green-800 font-small rounded-lg text-sm px-2 py-2.5 hover:cursor-pointer"
>
Save Settings
</button>
</div>
</div>
</div>
);
};
export default PayloadOptions;

View File

@@ -0,0 +1,22 @@
import { Field } from "formik";
type PayloadOptionsToggleProps = {
label: string;
value: string;
};
const PayloadOptionsToggle = ({ label, value }: PayloadOptionsToggleProps) => {
return (
<label className="flex items-center gap-3 cursor-pointer select-none w-full justify-between">
<span className="text-lg">{label}</span>
<Field id={value} type="checkbox" name={value} className="sr-only peer" />
<div
className="relative w-10 h-5 rounded-full bg-gray-300 transition peer-checked:bg-blue-500 after:content-['']
after:absolute after:top-0.5 after:left-0.5 after:w-4 after:h-4 after:rounded-full after:bg-white after:shadow after:transition
after:duration-300 peer-checked:after:translate-x-5"
/>
</label>
);
};
export default PayloadOptionsToggle;

View File

@@ -0,0 +1,16 @@
import { useQuery } from "@tanstack/react-query";
const fetchPayloadConfig = async () => {
const response = await fetch("/api/payload-config");
if (!response.ok) throw new Error("Failed to fetch payload config");
return response.json();
};
export const usePayloadCongfig = () => {
const payloadConfigQuery = useQuery({
queryKey: ["payloadConfig"],
queryFn: fetchPayloadConfig,
});
return { payloadConfigQuery };
};

View File

@@ -88,7 +88,51 @@ export type OSDConfigFields = {
OSDTimestampFormat: "UTC" | "LOCAL";
};
export type FormTypes = BearerTypeFields & OptionalConstants & OptionalLaneIDs & CustomFields & OSDConfigFields;
export type PayloadConfigFields = {
includeMac: boolean;
includeSaFID: boolean;
includeCameraName: boolean;
includeCharHeight: boolean;
includeConfidence: boolean;
includeCorrectSpacing: boolean;
includeDecodeID: boolean;
includeDirection: boolean;
includeFrameHeight: boolean;
includeFrameID: boolean;
includeFrameTimeRef: boolean;
includeFrameWidth: boolean;
includeHorizSlew: boolean;
includeMotion: boolean;
inclduePlate: boolean;
includeNightModeAction: boolean;
includeOverview: boolean;
includePlateSecondary: boolean;
includePlateTrack: boolean;
includePlateTrackSecondary: boolean;
includePreferredCountry: boolean;
includeRawReads: boolean;
includeRawREADSSecondary: boolean;
includeRef: boolean;
includeSeenCount: boolean;
includeRepeatedPlate: boolean;
includeSerialCount: boolean;
includeTimeStamp: boolean;
includeTraceCount: boolean;
includeTrack: boolean;
includeTrackSecondary: boolean;
includeVertSlew: boolean;
includeVRM: boolean;
includeVRMSecondary: boolean;
includeHotListMatches: boolean;
};
export type FormTypes = BearerTypeFields &
OptionalConstants &
OptionalLaneIDs &
CustomFields &
OSDConfigFields &
PayloadConfigFields;
type FieldProperty = {
datatype: string;
value: string;