ADD set search param after selected cam

Signed-off-by: Damian Krysta <damian@krysta.dev>
This commit is contained in:
Damian Krysta 2022-01-29 22:36:41 +01:00 committed by Scott Lamb
parent 2d517c28dc
commit 3988c3922d

View File

@ -9,6 +9,7 @@ import { Camera } from "../types";
import { makeStyles } from "@mui/styles"; import { makeStyles } from "@mui/styles";
import { Theme } from "@mui/material/styles"; import { Theme } from "@mui/material/styles";
import {useSearchParams} from "react-router-dom"; import {useSearchParams} from "react-router-dom";
import {isNullOrUndefined} from "util";
export interface Layout { export interface Layout {
className: string; className: string;
@ -205,13 +206,19 @@ const Monoview = (props: MonoviewProps) => {
const { const {
target: { value }, target: { value },
} = event; } = event;
if (value !== null && value !== undefined) {
setSearchParams(new URLSearchParams({cam: value.toString()}));
} else {
setSearchParams(new URLSearchParams({ }))
}
props.onSelect(typeof value === "string" ? parseInt(value) : value); props.onSelect(typeof value === "string" ? parseInt(value) : value);
}; };
const fromQueryOrFirst = searchParams.has('cam') ? Number.parseInt(searchParams.get('cam') as string, 10) : 0; const fromQueryIndexOrNull = searchParams.has('cam') ? Number.parseInt(searchParams.get('cam') as string, 10) : null;
const chooser = ( const chooser = (
<Select <Select
value={props.cameraIndex == null ? fromQueryOrFirst: props.cameraIndex} value={props.cameraIndex == null ? fromQueryIndexOrNull: props.cameraIndex}
onChange={handleChange} onChange={handleChange}
displayEmpty displayEmpty
size="small" size="small"
@ -232,7 +239,7 @@ const Monoview = (props: MonoviewProps) => {
</Select> </Select>
); );
return props.renderCamera( return props.renderCamera(
props.cameraIndex === null ? props.cameras[fromQueryOrFirst] : props.cameras[props.cameraIndex], props.cameraIndex === null ? fromQueryIndexOrNull === null ? null : props.cameras[fromQueryIndexOrNull] : props.cameras[props.cameraIndex],
chooser chooser
); );
}; };