From 6963ba3424b8bf915965f90a209c094fa07ea367 Mon Sep 17 00:00:00 2001 From: Javier Osorio M <31483796+josoriom@users.noreply.github.com> Date: Mon, 6 Nov 2023 05:43:50 -0500 Subject: [PATCH] fix: make sure selected roi is rendered on top of other rois (#46) Prevents other rois to be selected when clicking on the selected roi close #37 --- src/components/api/RoiList.tsx | 12 ++++++++++-- src/context/updaters/endAction.ts | 1 - 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/api/RoiList.tsx b/src/components/api/RoiList.tsx index 25b9795..d12e9ad 100644 --- a/src/components/api/RoiList.tsx +++ b/src/components/api/RoiList.tsx @@ -1,9 +1,17 @@ -import { useRois } from '../../hooks'; +import { useRoiState, useRois } from '../../hooks'; +import { assert } from '../../utilities/assert'; import { RoiBox } from './RoiBox'; export function RoiList() { - const rois = useRois(); + const rois = useRois().slice(); + const { selectedRoi } = useRoiState(); + if (selectedRoi) { + const index = rois.findIndex((roi) => roi.id === selectedRoi); + assert(index !== -1, 'Selected ROI not found'); + const roi = rois.splice(index, 1)[0]; + rois.push(roi); + } return ( <> {rois.map((roi) => ( diff --git a/src/context/updaters/endAction.ts b/src/context/updaters/endAction.ts index f32cc30..b6a3e07 100644 --- a/src/context/updaters/endAction.ts +++ b/src/context/updaters/endAction.ts @@ -10,7 +10,6 @@ export function endAction(draft: ReactRoiState) { if (!selectedRoi) return; const roi = rois.find((roi) => roi.id === selectedRoi); const commitedRoi = committedRois.find((roi) => roi.id === selectedRoi); - assert(roi, 'Selected ROI not found'); if (!roi) return;