Skip to content

Commit

Permalink
Fix: Default Camera Presets
Browse files Browse the repository at this point in the history
  • Loading branch information
gigincg committed Dec 12, 2022
1 parent ef4ba6f commit ccf4a6c
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions src/Components/Facility/Consultations/LiveFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -146,7 +159,7 @@ const LiveFeed = (props: any) => {
Notification.Error({ msg: "Something Went Wrong" });
}
getBedPresets(cameraAsset?.id);
getPresets({});
fetchCameraPresets();
setToUpdate(null);
};

Expand All @@ -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();
}
}, []);

Expand All @@ -183,16 +188,16 @@ 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)
: Array.from(Array(10), (_, i) => ({
label: "Monitor " + (i + 1),
value: i + 1,
}));

};
useEffect(() => {
let tId: any;
if (streamStatus !== StreamStatus.Playing) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -550,7 +555,7 @@ const LiveFeed = (props: any) => {
gotoBedPreset(preset);
setCurrentPreset(preset);
getBedPresets(cameraAsset?.id);
getPresets({});
fetchCameraPresets();
}}
>
<span className="justify-start text-xs font-semibold">
Expand Down Expand Up @@ -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();
}}
>
<RefreshIcon /> Refresh
Expand Down

0 comments on commit ccf4a6c

Please sign in to comment.