Add useMemo to cameras as well

This commit is contained in:
Nick Mowen 2022-03-12 10:20:53 -07:00
parent 20633975c6
commit 5bc875db1d
2 changed files with 23 additions and 11 deletions

View File

@ -53,8 +53,8 @@ function SortedCameras({ unsortedCameras }) {
const sortedCameras = useMemo(() =>
Object.entries(unsortedCameras)
.filter(([_, conf]) => conf.ui.show)
.sort(([_, aConf], [__, bConf]) => aConf.ui.order === bConf.ui.order ? 0 : (aConf.ui.order > bConf.ui.order ? 1 : -1))
, [unsortedCameras]);
.sort(([_, aConf], [__, bConf]) => aConf.ui.order === bConf.ui.order ? 0 : (aConf.ui.order > bConf.ui.order ? 1 : -1)),
[unsortedCameras]);
return (
<Fragment>
@ -72,8 +72,8 @@ function SortedRecordingCameras({ unsortedCameras }) {
const sortedCameras = useMemo(() =>
Object.entries(unsortedCameras)
.filter(([_, conf]) => conf.ui.show)
.sort(([_, aConf], [__, bConf]) => aConf.ui.order === bConf.ui.order ? 0 : (aConf.ui.order > bConf.ui.order ? 1 : -1))
, [unsortedCameras]);
.sort(([_, aConf], [__, bConf]) => aConf.ui.order === bConf.ui.order ? 0 : (aConf.ui.order > bConf.ui.order ? 1 : -1)),
[unsortedCameras]);
return (
<Fragment>

View File

@ -1,4 +1,4 @@
import { h } from 'preact';
import { h, Fragment } from 'preact';
import ActivityIndicator from '../components/ActivityIndicator';
import Card from '../components/Card';
import CameraImage from '../components/CameraImage';
@ -16,16 +16,28 @@ export default function Cameras() {
<ActivityIndicator />
) : (
<div className="grid grid-cols-1 3xl:grid-cols-3 md:grid-cols-2 gap-4 p-2 px-4">
{Object.entries(config.cameras)
.filter(([_, conf]) => conf.ui.show)
.sort(([_, aConf], [__, bConf]) => aConf.ui.order === bConf.ui.order ? 0 : (aConf.ui.order > bConf.ui.order ? 1 : -1))
.map(([camera, conf]) => (
<Camera key={camera} name={camera} conf={conf} />
))}
<SortedCameras unsortedCameras={config.cameras} />
</div>
);
}
function SortedCameras({ unsortedCameras }) {
const sortedCameras = useMemo(() =>
Object.entries(unsortedCameras)
.filter(([_, conf]) => conf.ui.show)
.sort(([_, aConf], [__, bConf]) => aConf.ui.order === bConf.ui.order ? 0 : (aConf.ui.order > bConf.ui.order ? 1 : -1)),
[unsortedCameras]);
return (
<Fragment>
{sortedCameras.map(([camera, conf]) => (
<Camera key={camera} name={camera} conf={conf} />
))}
</Fragment>
);
}
function Camera({ name }) {
const { payload: detectValue, send: sendDetect } = useDetectState(name);
const { payload: recordValue, send: sendRecordings } = useRecordingsState(name);