Skip to content

Commit

Permalink
Camera Preset Not Resetting on Re-selection Bug (#9186)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacobjeevan authored Dec 2, 2024
1 parent f76c625 commit 2d9669e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
2 changes: 2 additions & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@
"next_sessions": "Next Sessions",
"no": "No",
"no_attachments_found": "This communication has no attachments.",
"no_bed_asset_linked_allocated": "No bed/asset linked allocated",
"no_bed_types_found": "No Bed Types found",
"no_beds_available": "No beds available",
"no_changes": "No changes",
Expand Down Expand Up @@ -1364,6 +1365,7 @@
"update_facility_middleware_success": "Facility middleware updated successfully",
"update_log": "Update Log",
"update_patient_details": "Update Patient Details",
"update_preset": "Update Preset",
"update_preset_position_to_current": "Update preset's position to camera's current position",
"update_record": "Update Record",
"update_record_for_asset": "Update record for asset",
Expand Down
39 changes: 12 additions & 27 deletions src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => {
const bed = props.consultationData.current_bed?.bed_object;
const feedStateSessionKey = `encounterFeedState[${props.consultationId}]`;
const [preset, setPreset] = useState<CameraPreset>();
const [selectedPreset, setSelectedPreset] = useState<CameraPreset>();
const [showPresetSaveConfirmation, setShowPresetSaveConfirmation] =
useState(false);
const [isUpdatingPreset, setIsUpdatingPreset] = useState(false);
Expand Down Expand Up @@ -78,28 +79,14 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => {
return presets.find((obj) => obj.id === lastState.value);
}
if (lastState.type === "position") {
const assetBedObj = presets.find(
(p) => p.asset_bed.id === lastState.assetBed,
)?.asset_bed;

if (!assetBedObj) {
return;
}

return {
...presets[0],
id: "",
asset_bed: assetBedObj,
position: lastState.value,
} satisfies CameraPreset;
return;
}
}
})() ?? presets[0];

console.log({ preset, presets });

if (preset) {
setPreset(preset);
setSelectedPreset(preset);
}
},
});
Expand All @@ -126,6 +113,7 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => {
await presetsQuery.refetch();

setPreset(updated);
setSelectedPreset(updated);
setHasMoved(false);
setIsUpdatingPreset(false);
setShowPresetSaveConfirmation(false);
Expand Down Expand Up @@ -154,16 +142,16 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => {
}

if (!bed || !asset) {
return <span>No bed/asset linked allocated</span>;
return <span>{t("no_bed_asset_linked_allocated")}</span>;
}

const cannotSaveToPreset = !hasMoved || !preset?.id;

return (
<StillWatching>
<ConfirmDialog
title="Update Preset"
description="Are you sure you want to update this preset to the current location?"
title={t("update_preset")}
description={`Are you sure you want to update ${preset?.name} to the current location?`}
action="Confirm"
show={showPresetSaveConfirmation}
onClose={() => setShowPresetSaveConfirmation(false)}
Expand All @@ -180,11 +168,9 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => {
<CameraFeed
key={key}
asset={asset}
preset={preset?.position}
preset={selectedPreset?.position}
onMove={() => {
if (!preset) {
return;
}
setSelectedPreset(undefined);
setHasMoved(true);
setTimeout(async () => {
const { data } = await operate({ type: "get_status" });
Expand All @@ -193,7 +179,6 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => {
feedStateSessionKey,
JSON.stringify({
type: "position",
assetBed: preset.asset_bed.id,
value: (data as GetStatusResponse).result.position,
} satisfies LastAccessedPosition),
);
Expand Down Expand Up @@ -222,16 +207,17 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => {
<CameraPresetSelect
options={presets}
label={(obj) => obj.name}
value={preset}
value={selectedPreset}
onChange={(value) => {
triggerGoal("Camera Preset Clicked", {
presetName: preset?.name,
presetName: selectedPreset?.name,
consultationId: props.consultationId,
userId: authUser.id,
result: "success",
});
setHasMoved(false);
setPreset(value);
setSelectedPreset(value);
}}
/>
{isUpdatingPreset ? (
Expand Down Expand Up @@ -277,7 +263,6 @@ type LastAccessedPreset = {

type LastAccessedPosition = {
type: "position";
assetBed: string;
value: PTZPayload;
};

Expand Down

0 comments on commit 2d9669e

Please sign in to comment.