From 91738989268cc12d1f8cc7c1eb4ad2ee6ae2e6ad Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Fri, 24 Nov 2023 10:29:17 +0530 Subject: [PATCH] Revert buggy replacement of useDispatch with useQuery in Live Feed --- .../Facility/Consultations/LiveFeed.tsx | 79 ++++++++++--------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/src/Components/Facility/Consultations/LiveFeed.tsx b/src/Components/Facility/Consultations/LiveFeed.tsx index 4f6c3391c43..cd3f055921e 100644 --- a/src/Components/Facility/Consultations/LiveFeed.tsx +++ b/src/Components/Facility/Consultations/LiveFeed.tsx @@ -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, @@ -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); @@ -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" }); @@ -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(); @@ -624,4 +628,5 @@ const LiveFeed = (props: any) => { ); }; + export default LiveFeed;