Skip to content

Commit

Permalink
Presenter mode should show the next animation rather than the next slide
Browse files Browse the repository at this point in the history
  • Loading branch information
vlsi committed Jun 13, 2020
1 parent eaa7ac9 commit d094deb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
27 changes: 21 additions & 6 deletions src/components/deck/presenter-deck.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { DeckContext } from '../../hooks/use-deck';
import { SlideNextElementContext } from '../../hooks/use-slide';
import styled, { css } from 'styled-components';
import { Text } from '../typography';
import { FlexBox, Box } from '../layout';
Expand Down Expand Up @@ -82,6 +83,7 @@ const NotesContainer = styled('div')`

const PresenterDeck = props => {
const {
slideElementMap,
state: {
currentNotes,
currentSlide,
Expand All @@ -99,6 +101,11 @@ const PresenterDeck = props => {
children
} = props;

const countSlideElements = React.useCallback(
slideNumber => slideElementMap[slideNumber],
[slideElementMap]
);

const onStartConnection = React.useCallback(() => {
const urlParams = queryString.stringify({
slide: currentSlide,
Expand All @@ -110,9 +117,15 @@ const PresenterDeck = props => {

const activeSlide =
children.length > currentSlide ? children[currentSlide] : null;
const nextSlide =
children.length > currentSlide + 1 ? children[currentSlide + 1] : null;

// Show next animation in the preview slide if there are animations left on the current slide
const showNextElement =
currentSlideElement + 1 < countSlideElements(currentSlide);
// If there are no animations left on the current slide, then show the next slide in the preview
const nextSlide = showNextElement
? activeSlide
: children.length > currentSlide + 1
? children[currentSlide + 1]
: null;
const castButton = React.useMemo(() => {
if (isReceiver || typeof window.navigator.presentation === 'undefined') {
return null;
Expand Down Expand Up @@ -197,9 +210,11 @@ const PresenterDeck = props => {
Slide {nextSlide.props.slideNum + 1} of {numberOfSlides}
</SlideCountLabel>
</Text>
<SlideWrapper small data-testid="Next Slide">
{nextSlide}
</SlideWrapper>
<SlideNextElementContext.Provider value={{ showNextElement }}>
<SlideWrapper small data-testid="Next Slide">
{nextSlide}
</SlideWrapper>
</SlideNextElementContext.Provider>
</SlideContainer>
)}
</PreviewColumn>
Expand Down
6 changes: 6 additions & 0 deletions src/components/deck/presenter-deck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const children = [
describe('PresenterDeck', () => {
beforeEach(() => {
mockedUseContext.mockReturnValue({
slideElementMap: {
0: 0
},
state: {
currentNotes: '',
currentSlide: 0,
Expand Down Expand Up @@ -61,6 +64,9 @@ describe('PresenterDeck', () => {
terminateConnection: jest.fn()
};
mockedUseContext.mockReturnValue({
slideElementMap: {
0: 0
},
state: {
currentNotes: '',
currentSlide: 2,
Expand Down
19 changes: 17 additions & 2 deletions src/components/slide.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import useSlide, { SlideContext } from '../hooks/use-slide';
import useSlide, {
SlideContext,
SlideNextElementContext
} from '../hooks/use-slide';
import styled, { ThemeContext, css } from 'styled-components';
import { background, color, space } from 'styled-system';
import useAutofillHeight from '../hooks/use-autofill-height';
Expand Down Expand Up @@ -89,6 +92,7 @@ const Slide = props => {
} = props;
const theme = React.useContext(ThemeContext);
const { state } = React.useContext(DeckContext);
const { showNextElement } = React.useContext(SlideNextElementContext) || {};
const [ratio, setRatio] = React.useState(scaleRatio || 1);
const [origin, setOrigin] = React.useState({ x: 0, y: 0 });
const slideRef = React.useRef(null);
Expand Down Expand Up @@ -168,11 +172,22 @@ const Slide = props => {
[state.exportMode, origin, ratio]
);

const value = useSlide(slideNum);
let value = useSlide(slideNum);
const { numberOfSlides } = value.state;

useAutofillHeight({ slideWrapperRef, templateRef, contentRef, slideHeight });

if (showNextElement) {
// Next slide preview in the presenter mode might need to show the next animation
value = {
...value,
state: {
...value.state,
currentSlideElement: value.state.currentSlideElement + 1
}
};
}

return (
<SlideContainer
ref={slideRef}
Expand Down
1 change: 1 addition & 0 deletions src/hooks/use-slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { DEFAULT_SLIDE_ELEMENT_INDEX } from '../utils/constants';

// Initialise SlideContext.
export const SlideContext = React.createContext();
export const SlideNextElementContext = React.createContext();

function useSlide(slideNum) {
// Gets state, dispatch and number of slides off DeckContext.
Expand Down

0 comments on commit d094deb

Please sign in to comment.