Skip to content

Commit

Permalink
fix: Handle null in imageIdIndex (#74)
Browse files Browse the repository at this point in the history
Co-authored-by: kedar.netelixir <[email protected]>
  • Loading branch information
ckedar and kedar.netelixir authored Mar 24, 2020
1 parent b84c171 commit 08a5b5a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/CornerstoneViewport/CornerstoneViewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,16 @@ class CornerstoneViewport extends Component {
isStackPrefetchEnabled: prevIsStackPrefetchEnabled,
} = prevProps;
const hasStackChanged = !areStringArraysEqual(prevStack, stack);
const hasImageIndexChanged = imageIndex !== prevImageIndex;
const hasImageIndexChanged =
imageIndex != null && imageIndex !== prevImageIndex;
let updatedState = {};

if (hasStackChanged) {
// update stack toolstate
cornerstoneTools.clearToolState(this.element, 'stack');
cornerstoneTools.addToolState(this.element, 'stack', {
imageIds: [...stack],
currentImageIdIndex: imageIndex,
currentImageIdIndex: imageIndex || 0,
});

// New stack; reset counter
Expand All @@ -228,7 +229,7 @@ class CornerstoneViewport extends Component {

try {
// load + display image
const imageId = stack[imageIndex];
const imageId = stack[imageIndex || 0];
cornerstoneTools.stopClip(this.element);
const image = await cornerstone.loadAndCacheImage(imageId);

Expand Down Expand Up @@ -711,6 +712,10 @@ class CornerstoneViewport extends Component {
}
};

onResize = () => {
cornerstone.resize(this.element);
};

render() {
const isLoading = this.state.isLoading;
const displayLoadingIndicator = isLoading || this.state.error;
Expand All @@ -730,9 +735,7 @@ class CornerstoneViewport extends Component {
skipOnMount={true}
refreshMode={'throttle'}
refreshRate={this.props.resizeThrottleMs}
onResize={() => {
cornerstone.resize(this.element);
}}
onResize={this.onResize}
/>
<div
className="viewport-element"
Expand Down

0 comments on commit 08a5b5a

Please sign in to comment.