Skip to content

Commit a93bc98

Browse files
committed
fix: on next / on prev support for image segmentation
1 parent 3a25979 commit a93bc98

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/components/ImageSegmentation/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const regionTypeToTool = {
2424
const [emptyObj, emptyArr] = [{}, []]
2525

2626
export default ({
27+
sampleIndex: globalSampleIndex,
2728
interface: iface,
2829
taskData = emptyArr,
2930
taskOutput = emptyObj,
@@ -56,7 +57,7 @@ export default ({
5657
const multipleRegions =
5758
iface.multipleRegions || iface.multipleRegions === undefined
5859

59-
const onExit = useEventCallback((output) => {
60+
const onExit = useEventCallback((output, nextAction) => {
6061
const regionMat = (output.images || [])
6162
.map((img) => img.regions)
6263
.map((riaRegions) => (riaRegions || []).map(convertFromRIARegionFmt))
@@ -68,7 +69,13 @@ export default ({
6869
onSaveTaskOutputItem(i, regionMat[i][0])
6970
}
7071
}
71-
if (containerProps.onExit) containerProps.onExit()
72+
if (containerProps.onExit) containerProps.onExit(nextAction)
73+
})
74+
const onNextImage = useEventCallback((output) => {
75+
onExit(output, "go-to-next")
76+
})
77+
const onPrevImage = useEventCallback((output) => {
78+
onExit(output, "go-to-previous")
7279
})
7380

7481
const images = useMemo(
@@ -91,21 +98,16 @@ export default ({
9198
),
9299
[regionTypesAllowed]
93100
)
94-
console.log({
95-
selectedImage: taskData[selectedIndex].imageUrl,
96-
taskDescription: iface.description,
97-
...labelProps,
98-
enabledTools: enabledTools,
99-
images,
100-
onExit,
101-
})
102101

103102
return (
104103
<div style={{ height: "calc(100vh - 70px)" }}>
105104
<Annotator
105+
key={globalSampleIndex}
106106
selectedImage={taskData[selectedIndex].imageUrl}
107107
taskDescription={iface.description}
108108
{...labelProps}
109+
onNextImage={onNextImage}
110+
onPrevImage={onPrevImage}
109111
enabledTools={enabledTools}
110112
images={images}
111113
onExit={onExit}

src/utils/use-prevent-navigation.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function preventNavigation(e) {
1414
export default (shouldPreventNavigation = true) => {
1515
useEffect(() => {
1616
if (!shouldPreventNavigation) return
17+
if (window.location.origin.includes("localhost")) return
1718
window.addEventListener("beforeunload", preventNavigation)
1819
return () => {
1920
window.removeEventListener("beforeunload", preventNavigation)

0 commit comments

Comments
 (0)