make sure slidePosition is only used if it exists

This commit is contained in:
Ramon Souza 2021-02-03 16:38:09 -03:00
parent 49ee9821f8
commit 06bd75dd9e
2 changed files with 40 additions and 48 deletions

View File

@ -168,43 +168,44 @@ class PresentationArea extends PureComponent {
this.onResize();
}
const { width: prevWidth, height: prevHeight } = prevProps.slidePosition;
const { width: currWidth, height: currHeight } = slidePosition;
if(prevProps?.slidePosition && slidePosition){
const { width: prevWidth, height: prevHeight } = prevProps.slidePosition;
const { width: currWidth, height: currHeight } = slidePosition;
if (prevProps.slidePosition.id !== slidePosition.id) {
if ((prevWidth > prevHeight && currHeight > currWidth)
|| (prevHeight > prevWidth && currWidth > currHeight)) {
layoutContextDispatch(
{
type: 'setAutoArrangeLayout',
value: true,
if (prevProps.slidePosition.id !== slidePosition.id) {
if ((prevWidth > prevHeight && currHeight > currWidth)
|| (prevHeight > prevWidth && currWidth > currHeight)) {
layoutContextDispatch(
{
type: 'setAutoArrangeLayout',
value: true,
},
);
}
window.dispatchEvent(new Event('slideChanged'));
}
if (prevWidth !== currWidth || prevHeight !== currHeight) {
layoutContextDispatch({
type: 'setPresentationSlideSize',
value: {
width: currWidth,
height: currHeight,
},
);
}
window.dispatchEvent(new Event('slideChanged'));
}
if (prevWidth !== currWidth || prevHeight !== currHeight) {
layoutContextDispatch({
type: 'setPresentationSlideSize',
value: {
width: currWidth,
height: currHeight,
},
});
if (currWidth > currHeight || currWidth === currHeight) {
layoutContextDispatch({
type: 'setPresentationOrientation',
value: 'landscape',
});
if (currWidth > currHeight || currWidth === currHeight) {
layoutContextDispatch({
type: 'setPresentationOrientation',
value: 'landscape',
});
}
if (currHeight > currWidth) {
layoutContextDispatch({
type: 'setPresentationOrientation',
value: 'portrait',
});
}
}
if (currHeight > currWidth) {
layoutContextDispatch({
type: 'setPresentationOrientation',
value: 'portrait',
});
}
}
const downloadableOn = !prevProps.currentPresentation.downloadable
&& currentPresentation.downloadable;
@ -249,6 +250,7 @@ class PresentationArea extends PureComponent {
}
}
}
}
componentWillUnmount() {
window.removeEventListener('resize', this.onResize, false);

View File

@ -55,21 +55,11 @@ const getCurrentSlide = (podId) => {
});
};
const getSlidePosition = (podId, presentationId, slideId) => {
const positions = SlidePositions.findOne({
podId,
presentationId,
id: slideId,
});
if (!positions) {
return {
width: 1000, height: 1000, x: 0, y: 0, viewBoxWidth: 1000, viewBoxHeight: 1000,
};
}
return positions;
};
const getSlidePosition = (podId, presentationId, slideId) => SlidePositions.findOne({
podId,
presentationId,
id: slideId,
});
const currentSlidHasContent = () => {
const currentSlide = getCurrentSlide('DEFAULT_PRESENTATION_POD');