Camera groups (#10223)

* Add camera group config

* Add saving of camera group selection

* Implement camera groups in config and live view

* Fix warnings

* Add tooltips to camera group items on desktop

* Add camera groups to the filters for events

* Fix tooltips and group selection

* Cleanup
This commit is contained in:
Nicolas Mowen
2024-03-04 16:18:30 -07:00
committed by GitHub
parent 38e76666e7
commit b4b2162ada
11 changed files with 247 additions and 40 deletions

View File

@@ -1,22 +1,28 @@
import { useCallback } from "react";
import { useCallback, useMemo } from "react";
import { useLocation, useNavigate } from "react-router-dom";
export default function useOverlayState(key: string) {
export default function useOverlayState(
key: string,
): [string | undefined, (value: string, replace?: boolean) => void] {
const location = useLocation();
const navigate = useNavigate();
const currentLocationState = location.state;
const setOverlayStateValue = useCallback(
(value: string) => {
(value: string, replace: boolean = false) => {
const newLocationState = { ...currentLocationState };
newLocationState[key] = value;
navigate(location.pathname, { state: newLocationState });
navigate(location.pathname, { state: newLocationState, replace });
},
// we know that these deps are correct
// eslint-disable-next-line react-hooks/exhaustive-deps
[key, navigate],
);
const overlayStateValue = location.state && location.state[key];
const overlayStateValue = useMemo<string | undefined>(
() => location.state && location.state[key],
[location, key],
);
return [overlayStateValue, setOverlayStateValue];
}