Skip to content

Commit

Permalink
Revert buggy replacement of useDispatch with useQuery in Live Feed
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Nov 24, 2023
1 parent 6716d2c commit 9173898
Showing 1 changed file with 42 additions and 37 deletions.
79 changes: 42 additions & 37 deletions src/Components/Facility/Consultations/LiveFeed.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { useEffect, useRef, useState } from "react";
import { useEffect, useState, useRef } from "react";
import { useDispatch } from "react-redux";
import routes from "../../../Redux/api";
import request from "../../../Utils/request/request";
import useKeyboardShortcut from "use-keyboard-shortcut";
import {
listAssetBeds,
partialUpdateAssetBed,
deleteAssetBed,
} from "../../../Redux/actions";
import { getCameraPTZ } from "../../../Common/constants";
import {
StreamStatus,
Expand Down Expand Up @@ -109,30 +112,28 @@ const LiveFeed = (props: any) => {
};

const getBedPresets = async (id: any) => {
const { data } = await request(routes.listAssetBeds, {
pathParams: { asset: id },
body: {
const bedAssets = await dispatch(
listAssetBeds({
asset: id,
limit: page.limit,
offset: page.offset,
},
});
setBedPresets(data?.results);
})
);
setBedPresets(bedAssets?.data?.results);
setPage({
...page,
count: data?.count || 0,
count: bedAssets?.data?.count,
});
};

const deletePreset = async (id: any) => {
const { res, data } = await request(routes.deleteAssetBed, {
pathParams: { id },
});
const res = await dispatch(deleteAssetBed(id));
if (res?.status === 204) {
Notification.Success({ msg: "Preset deleted successfully" });
getBedPresets(cameraAsset.id);
} else {
Notification.Error({
msg: "Error while deleting Preset: " + (data?.detail || ""),
msg: "Error while deleting Preset: " + (res?.data?.detail || ""),
});
}
setToDelete(null);
Expand All @@ -143,18 +144,20 @@ const LiveFeed = (props: any) => {
bed_id: bed.id,
preset_name: preset,
};
const { res } = await request(routes.partialUpdateAssetBed, {
pathParams: { id: currentPreset.id },
body: {
asset: currentPreset.asset_object.id,
bed: bed.id,
meta: {
...currentPreset.meta,
...data,
const response = await dispatch(
partialUpdateAssetBed(
{
asset: currentPreset.asset_object.id,
bed: bed.id,
meta: {
...currentPreset.meta,
...data,
},
},
},
});
if (res && res.status === 200) {
currentPreset?.id
)
);
if (response && response.status === 200) {
Notification.Success({ msg: "Preset Updated" });
} else {
Notification.Error({ msg: "Something Went Wrong" });
Expand Down Expand Up @@ -255,19 +258,20 @@ const LiveFeed = (props: any) => {
if (currentPreset?.asset_object?.id && data?.position) {
setLoading(option.loadingLabel);
console.log("Updating Preset");
const { res } = await request(routes.partialUpdateAssetBed, {
pathParams: { id: currentPreset.id },
body: {
asset: currentPreset.asset_object.id,
bed: currentPreset.bed_object.id,
meta: {
...currentPreset.meta,
position: data?.position,
const response = await dispatch(
partialUpdateAssetBed(
{
asset: currentPreset.asset_object.id,
bed: currentPreset.bed_object.id,
meta: {
...currentPreset.meta,
position: data?.position,
},
},
},
});

if (res && res.status === 200) {
currentPreset?.id
)
);
if (response && response.status === 200) {
Notification.Success({ msg: "Preset Updated" });
getBedPresets(cameraAsset?.id);
fetchCameraPresets();
Expand Down Expand Up @@ -624,4 +628,5 @@ const LiveFeed = (props: any) => {
</Page>
);
};

export default LiveFeed;

0 comments on commit 9173898

Please sign in to comment.