From ccf4a6cd1b9a96358154c68606dfe394f4bcca24 Mon Sep 17 00:00:00 2001 From: Gigin George Date: Mon, 12 Dec 2022 20:00:48 +0530 Subject: [PATCH] Fix: Default Camera Presets --- .../Facility/Consultations/LiveFeed.tsx | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/Components/Facility/Consultations/LiveFeed.tsx b/src/Components/Facility/Consultations/LiveFeed.tsx index 544ee954c60..2cd62c07df4 100644 --- a/src/Components/Facility/Consultations/LiveFeed.tsx +++ b/src/Components/Facility/Consultations/LiveFeed.tsx @@ -94,6 +94,19 @@ const LiveFeed = (props: any) => { dispatch, }); + const fetchCameraPresets = () => + getPresets({ + onSuccess: (resp) => { + setPresets(resp); + }, + onError: (resp) => { + resp instanceof AxiosError && + Notification.Error({ + msg: "Camera is offline", + }); + }, + }); + const getBedPresets = async (id: any) => { const bedAssets = await dispatch( listAssetBeds({ @@ -146,7 +159,7 @@ const LiveFeed = (props: any) => { Notification.Error({ msg: "Something Went Wrong" }); } getBedPresets(cameraAsset?.id); - getPresets({}); + fetchCameraPresets(); setToUpdate(null); }; @@ -159,15 +172,7 @@ const LiveFeed = (props: any) => { useEffect(() => { if (cameraAsset?.hostname) { - getPresets({ - onSuccess: (resp) => setPresets(resp.data), - onError: (resp) => { - resp instanceof AxiosError && - Notification.Error({ - msg: "Camera is offline", - }); - }, - }); + fetchCameraPresets(); } }, []); @@ -183,8 +188,8 @@ const LiveFeed = (props: any) => { } }, [page.offset, cameraAsset.id, refreshPresetsHash]); - const viewOptions = (page: number) => - presets + const viewOptions = (page: number) => { + return presets ? Object.entries(presets) .map(([key, value]) => ({ label: key, value })) .slice(page, page + 10) @@ -192,7 +197,7 @@ const LiveFeed = (props: any) => { label: "Monitor " + (i + 1), value: i + 1, })); - + }; useEffect(() => { let tId: any; if (streamStatus !== StreamStatus.Playing) { @@ -257,7 +262,7 @@ const LiveFeed = (props: any) => { if (response && response.status === 200) { Notification.Success({ msg: "Preset Updated" }); getBedPresets(cameraAsset?.id); - getPresets({}); + fetchCameraPresets(); } setLoading(undefined); } @@ -550,7 +555,7 @@ const LiveFeed = (props: any) => { gotoBedPreset(preset); setCurrentPreset(preset); getBedPresets(cameraAsset?.id); - getPresets({}); + fetchCameraPresets(); }} > @@ -630,13 +635,7 @@ const LiveFeed = (props: any) => { className="bg-green-100 border border-white rounded-md px-3 py-2 text-black font-semibold hover:text-white hover:bg-green-500 w-full" onClick={() => { getBedPresets(cameraAsset?.id); - getPresets({ - onError: () => { - Notification.Error({ - msg: "Camera is offline", - }); - }, - }); + fetchCameraPresets(); }} > Refresh