wip: ignore restore on update for first load of initial presentation

This commit is contained in:
Ramón Souza 2023-05-09 10:58:40 -03:00
parent a7d78109b2
commit 854d0a162e

View File

@ -77,6 +77,7 @@ class Presentation extends PureComponent {
isPanning: false, isPanning: false,
tldrawIsMounting: true, tldrawIsMounting: true,
isToolbarVisible: true, isToolbarVisible: true,
hadPresentation: false,
}; };
this.currentPresentationToastId = null; this.currentPresentationToastId = null;
@ -136,9 +137,15 @@ class Presentation extends PureComponent {
window.addEventListener('resize', this.onResize, false); window.addEventListener('resize', this.onResize, false);
const { const {
currentSlide, slidePosition, numPages, layoutContextDispatch, currentSlide, slidePosition, numPages, layoutContextDispatch, currentPresentationId,
} = this.props; } = this.props;
if (currentPresentationId) {
this.setState({
hadPresentation: true
});
}
if (currentSlide) { if (currentSlide) {
layoutContextDispatch({ layoutContextDispatch({
type: ACTIONS.SET_PRESENTATION_NUM_CURRENT_SLIDE, type: ACTIONS.SET_PRESENTATION_NUM_CURRENT_SLIDE,
@ -178,7 +185,7 @@ class Presentation extends PureComponent {
} = this.props; } = this.props;
const { const {
presentationWidth, presentationHeight, zoom, isPanning, fitToWidth, presentationId, presentationWidth, presentationHeight, zoom, isPanning, fitToWidth, presentationId, hadPresentation,
} = this.state; } = this.state;
const { const {
numCameras: prevNumCameras, numCameras: prevNumCameras,
@ -258,22 +265,28 @@ class Presentation extends PureComponent {
}); });
} }
const presentationChanged = presentationId !== currentPresentationId; const presentationChanged = presentationId !== currentPresentationId;
if (presentationChanged) {
this.setState({ // TODO: this information should be received from server
presentationId: currentPresentationId, const isInitialPresentation = currentPresentation.name === 'default.pdf';
});
}
if (!presentationIsOpen && restoreOnUpdate && (currentSlide || presentationChanged)) { if (!presentationIsOpen && restoreOnUpdate && (currentSlide || presentationChanged)) {
const slideChanged = currentSlide.id !== prevProps.currentSlide.id; const slideChanged = currentSlide.id !== prevProps.currentSlide.id;
const positionChanged = slidePosition const positionChanged = slidePosition
.viewBoxHeight !== prevProps.slidePosition.viewBoxHeight .viewBoxHeight !== prevProps.slidePosition.viewBoxHeight
|| slidePosition.viewBoxWidth !== prevProps.slidePosition.viewBoxWidth; || slidePosition.viewBoxWidth !== prevProps.slidePosition.viewBoxWidth;
const pollPublished = publishedPoll && !prevProps.publishedPoll; const pollPublished = publishedPoll && !prevProps.publishedPoll;
if (slideChanged || positionChanged || pollPublished || presentationChanged) { if (slideChanged || positionChanged || pollPublished || (presentationChanged && (hadPresentation || !isInitialPresentation))) {
setPresentationIsOpen(layoutContextDispatch, !presentationIsOpen); setPresentationIsOpen(layoutContextDispatch, !presentationIsOpen);
} }
} }
if (presentationChanged) {
this.setState({
presentationId: currentPresentationId,
hadPresentation: true
});
}
if ((presentationBounds !== prevPresentationBounds) if ((presentationBounds !== prevPresentationBounds)
|| (!presentationWidth && !presentationHeight)) this.onResize(); || (!presentationWidth && !presentationHeight)) this.onResize();
} else if (slidePosition) { } else if (slidePosition) {