Skip to content

Commit

Permalink
Render all pages up front (elastic#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashid Khan authored Dec 12, 2017
1 parent 946c227 commit 5e11c6d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 7 deletions.
4 changes: 4 additions & 0 deletions public/components/page_stack/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pure } from 'recompose';
import { PageStack as Component } from './page_stack';

export const PageStack = pure(Component);
Empty file.
33 changes: 33 additions & 0 deletions public/components/page_stack/page_stack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import { PropTypes } from 'prop-types';
import './page.less';
import { ElementWrapper } from '../element_wrapper';

export const PageStack = ({ pages, selectedPageId, height, width }) => {
return (
pages.map(page => (
<div
key={page.id}
className="canvas__page"
style={{
top: selectedPageId === page.id ? undefined : '-9999999px',
left: selectedPageId === page.id ? undefined : '-9999999px',
height,
width,
}}>
{
page.elements.map(element => (
<ElementWrapper key={element.id} element={element} />
))
}
</div>
))
);
};

PageStack.propTypes = {
height: PropTypes.number.isRequired,
width: PropTypes.number.isRequired,
pages: PropTypes.array.isRequired,
selectedPageId: PropTypes.string.isRequired,
};
4 changes: 3 additions & 1 deletion public/components/workpad/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { connect } from 'react-redux';
import { get } from 'lodash';
import { undoHistory, redoHistory } from '../../state/actions/history';
import { fetchAllRenderables } from '../../state/actions/elements';
import { getElements, getPageById, getSelectedPage, getWorkpad } from '../../state/selectors/workpad';
import { getElements, getPageById, getSelectedPage, getWorkpad, getPages } from '../../state/selectors/workpad';
import { getFullscreen, getEditing } from '../../state/selectors/app';
import { nextPage, previousPage } from '../../state/actions/pages';
import { Workpad as Component } from './workpad';

const mapStateToProps = (state) => {
return {
pages: getPages(state),
selectedPageId: getSelectedPage(state),
elements: getElements(state),
style: get(getPageById(state, getSelectedPage(state)), 'style'),
workpad: getWorkpad(state),
Expand Down
22 changes: 16 additions & 6 deletions public/components/workpad/workpad.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Shortcuts } from 'react-shortcuts';
import { ElementWrapper } from '../element_wrapper';
import { PageStack } from '../page_stack';
import { Fullscreen } from '../fullscreen';
import './workpad.less';

export const Workpad = (props) => {
const { elements, style, workpad, fetchAllRenderables, undoHistory, redoHistory, nextPage, previousPage, isFullscreen } = props;
export const Workpad = ({
selectedPageId,
pages,
style,
workpad,
fetchAllRenderables,
undoHistory,
redoHistory,
nextPage,
previousPage,
isFullscreen,
}) => {
const { height, width } = workpad;
const itsTheNewStyle = Object.assign({}, style, { height, width });

Expand Down Expand Up @@ -46,9 +56,7 @@ export const Workpad = (props) => {
/>
}

{ elements.map(element => (
<ElementWrapper key={element.id} element={element} />
))}
<PageStack pages={pages} selectedPageId={selectedPageId} height={height} width={width} />
</div>
);
}}
Expand All @@ -58,6 +66,8 @@ export const Workpad = (props) => {
};

Workpad.propTypes = {
pages: PropTypes.array.isRequired,
selectedPageId: PropTypes.string.isRequired,
elements: PropTypes.array.isRequired,
isFullscreen: PropTypes.bool.isRequired,
workpad: PropTypes.object.isRequired,
Expand Down
4 changes: 4 additions & 0 deletions public/components/workpad/workpad.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
}
}

.canvas__page {
position: absolute;
}

// For some bizarre reason, you must repeat the styles in their own blocks or they won’t be applied
// https://www.sitepoint.com/html5-full-screen-api/
// #canvas--fullscreen:-moz-full-screen {
Expand Down

0 comments on commit 5e11c6d

Please sign in to comment.